Now in this SQL Post we will learn Data Manipulation Language (DML) UPDATE Statement.
UPDATE Statement in SQL – DML Statements
The UPDATE Statement – The UPDATE Statement is used to modify the records of existing table.
If we want to modify the rows data in a table we need to use UPDATE query in SQL.
The SQL UPDATE Statement Syntax :
UPDATE table_name SET col1=val1, col2=val2, col3=val3 WHERE Condition
table_name – is the name of table which has to be updated.
col1, col2 – is the anme of columns which records has to be updated.
val1, val2 – is the values of new records which has be updated in to table.
SQL UPDATE Statement Example :
The SQL Student Table :
ID | Name | City | Mobile | |
---|---|---|---|---|
1 | MEERA | Surat | meera@meeraacademy.com | 1020304050 |
2 | Vaidehi | Mumbai | Vaidehi@yahoo.com | 1122334455 |
Example – Update the email address in table Student whose id=2, the UPDATE query is :
UPDATE Student SET email=”ram@meeraacademy.com” WHERE ID=2;
The Student Table After Updated.
ID | Name | City | Mobile | |
---|---|---|---|---|
1 | MEERA | Surat | meera@meeraacademy.com | 1020304050 |
2 | Vaidehi | Mumbai | ram@meeraacademy.com | 1122334455 |
If we write above UPDATE Statement like below :
UPDATE Student SET City=”Pune”, Mobile=1111111111;
The Student Table After Updated.
ID | Name | City | Mobile | |
---|---|---|---|---|
1 | MEERA | Pune | meera@meeraacademy.com | 1111111111 |
2 | Vaidehi | Pune | ram@meeraacademy.com | 1111111111 |
Note : In UPDATE Statement, If we do not use WHERE Condition, then all records of columns to be updated in a table.