SQL Tutorial
SQL Database
SQL Table
SQL Select
SQL Order By
SQL Insert
SQL Update
SQL Delete
Difference
SQL Injection
SQL String Functions
Miscl
- SQL Formatter
- SQL group by
- SQL add/drop/update column operation
- SQL CAST Function
- SQL Comments
- SQL CONCAT Function
- CTE (Common Table Expression)SQL
- How to use distinct in SQL?
- Joining Three or More Tables in SQL
- What is Web SQL?
- How to create functions in SQL?
- How to run SQL Script?
- How to Delete Duplicate Rows in SQL?
- Nth Highest salary
- 12 Codd's Rules
- SQL EXCEPT
- Types of SQL JOIN
- Change datatype of column in SQL
- SQL Auto Increment
- SQL Like
- Commit and Rollback in SQL
- SQL Concatenate
- SQL get month from the date
- Savepoint in SQL
- SQL ORDER BY DATE
- TIME Datatype in SQL
- SQL BETWEEN
- CRUD Operations in SQL
- SQL INDEX
- Scalar Functions in SQL
- SET Operators in SQL
- Types of SQL Commands
- TCL Commands in SQL
- SQL Subquery
- SQL View
- Constraints in SQL
- Pattern Matching in SQL
- SQL Date Functions
- DDL Commands in SQL
- DML Commands in SQL
- SQL CASE
- SQL Inner Join
- SQL IN Operator
- Check Constraint in SQL
- SQL CLAUSES
- SQL LOGICAL OPERATORS
- Delete Column from Table
- Add Column in the Table
- Delete one row in SQL
- Change the Column Value
- How to Add Foreign Key in SQL
- Add a Primary Key
- Insert One or More rows
- How to Use LIKE in SQL
- Cursor in SQL
- Difference Between DROP and Truncate
- SQL Comparison Operators
- SQL COUNT WHERE
- SQL SELECT MIN
- SQL Stored Procedure
- SQL SELECT AVG
- SQL SELECT MAX
- SQL ADD COLUMN
- How to use Auto-Increment in SQL
- SQL Languages
- SQL Arithmetic Operators
- How to Use GROUP BY in SQL
- How to Use ORDER BY in SQL
- Trigger in SQL
- What is Race Condition
- SQL COUNT DISTINCT
PL/SQL Tutorial
Sql Interview Question
SQl Quiz
Change the Column Value
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:
- Create a Database.
- Create a Table in the database, and Insert the data into the table.
- Show the table before value is updated.
- Change the value of a column in the table.
- Show the table after value is updated.
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:
(
column_Name_1 data type (size of the column_1),
column_Name_2 data type (size of the column_2),
column_Name_3 data type (size of the column_3),
...
column_Name_N data type (size of the column_N)
);
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:
(
Number Int,
Model Int,
Bike_Name Varchar (20),
Color Varchar (20),
Price Int,
Average Int,
) ;
After the table creation, you have to insert the data of bikes in the Bikes table using the following query:
(2, 2020, Pulsar, Black, 190000, 50),
(3, 2019, R15, Blue, 200000, 45),
(4, 2020, Apache, Black, 190000, 45),
(5, 2018, Bullet, Grey, 200000, 50),
(6, 2017, Duke, Yellow, 190000, 35),
(7, 2019, Pulsar, Red, 90000, 45),
(8, 2020, FZ-s, Black, 100000, 40),
(9, 2019, R15, Orange, 200000, 40),
(10, 2020, Bullet, Black, 190000, 35),
(11, 2018, Duke, Red, 128000, 30),
(12, 2020, Harley Davidson, Black, 400000, 25);
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:
Output:
Number | Model | Bike_Name | Color | Price | Average | |||||
---|---|---|---|---|---|---|---|---|---|---|
1 | 2019 | Apache | Black | 180000 | 49 | |||||
2 | 2020 | Pulsar | Black | 190000 | 50 | |||||
3 | 2019 | R15 | Blue | 200000 | 45 | |||||
4 | 2020 | Apache | Black | 190000 | 45 | |||||
5 | 2018 | Bullet | Grey | 200000 | 50 | |||||
6 | 2017 | Duke | Yellow | 190000 | 35 | |||||
7 | 2019 | Pulsar | Red | 90000 | 45 | |||||
8 | 2020 | FZ-s | Black | 100000 | 40 | |||||
9 | 2019 | R15 | Orange | 200000 | 40 | |||||
10 | 2020 | Bullet | Black | 190000 | 35 | |||||
11 | 2018 | Duke | Red | 128000 | 30 | |||||
12 | 2020 | Harley Davidson | Black | 400000 | 25 |
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:
Number | Model | Bike_Name | Color | Price | Average | |||||
---|---|---|---|---|---|---|---|---|---|---|
1 | 2019 | Apache | Black | 180000 | 49 | |||||
2 | 2020 | Pulsar | Black | 190000 | 50 | |||||
3 | 2019 | R15 | Blue | 200000 | 45 | |||||
4 | 2020 | Apache | Black | 190000 | 45 | |||||
5 | 2018 | Bullet | Grey | 200000 | 50 | |||||
6 | 2017 | Duke | Yellow | 190000 | 35 | |||||
7 | 2019 | Pulsar | Red | 90000 | 45 | |||||
8 | 2020 | FZ-s | Black | 100000 | 40 | |||||
9 | 2019 | R15 | Orange | 200000 | 40 | |||||
10 | 2020 | Bullet | Black | 190000 | 35 | |||||
11 | 2018 | Duke | Red | 128000 | 30 | |||||
12 | 2020 | Harley Davidson | Black | 400000 | 25 |
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:
To check the result of the above query, you have to type the following SELECT command in SQL:
Number | Model | Bike_Name | Color | Price | Average | |||||
---|---|---|---|---|---|---|---|---|---|---|
1 | 2019 | Apache | Black | 180000 | 49 | |||||
2 | 2020 | Pulsar | Black | 190000 | 50 | |||||
3 | 2019 | R15 | Blue | 200000 | 45 | |||||
4 | 2020 | Apache | Black | 190000 | 45 | |||||
5 | 2018 | Bullet | Grey | 200000 | 50 | |||||
6 | 2017 | Duke | Yellow | 190000 | 35 | |||||
7 | 2019 | Pulsar | Red | 90000 | 45 | |||||
8 | 2020 | FZ-s | Black | 100000 | 40 | |||||
9 | 2019 | R15 | Orange | 200000 | 40 | |||||
10 | 2020 | Bullet | Black | 190000 | 35 | |||||
11 | 2018 | Duke | Red | 128000 | 30 | |||||
12 | 2020 | Harley Davidson | Black | 400000 | 25 |
As we can see that the color and price of the R15 bike have been successfully changed.