How to Change the Column Value in SQL
In this article, you will learn how to change the value of the specific column in the Structured Query Language.
The UPDATE command in SQL allows the database users to change the value of the specific column in the table. We can also modify the data of two or more columns using one query.
The syntax for changing the value of a specific column in the table is given below:
The syntax for changing the value of one or more columns in the table is given below:
We have to use the SET keyword in the UPDATE command for modifying the value of the columns. WHERE clause specifies which row you want to change.
If you want to modify the value of the particular column in the table, you have to follow the below five steps one by one in the given order:
Now, we are going to explain each step with an example:
Step 1: Create a Database
In the structured query language, database creation is the first step for storing the structured tables in the database.
Use the following SQL syntax to create a database:
The following CREATE command creates the Vehicles database in the SQL database system:
Step 2: Create a Table and Insert the data
After database creation, you have to use the following syntax to create the table:
Suppose you want to create the Bikes table in the Vehicles database. For this, you have to write the following query in your SQL application:
After the table creation, you have to insert the data of bikes in the Bikes table using the following query:
Step 3: View the Table before updating the values
After table creation and data insertion, you can view the inserted data of the Bikes table by typing the following query in your SQL application:
Step 4: Change the value of a particular column in the table
If you want to change the Color of any bike, you have to type the following query in SQL:
Step 5: View the Table after updating the values
To check the result of the query executed in the 4th step, you have to type the following SELECT command in SQL:
As we can see, the color of Apache Bike has been successfully changed in the Cars table.
Change the value of Multiple Columns in the table
If you want to update the values of multiple columns in the Bikes table, then you have to write the below query in SQL:UPDATE Bikes SET Color = Green, Price = 90000 WHERE Bike_Name = R15;
To check the result of the above query, you have to type the following SELECT command in SQL:
As we can see that the color and price of the R15 bike have been successfully changed.