Learn how to use SQL UPDATE statement with the tutorial and examples. Find out how to update table records using SQL UPDATE statement.
You have to specify column names and values to update the data of a table. Use the WHERE conditional clause in the SQL UPDATE statement. If you do not use the WHERE condition, the statement will update all the record of the specified column of a table.
If you made any mistake with the data of a table, you can use the UPDATE statement to make the data accurate. You need to set the values for the column in the statement by specifying the values with the columns.
How to Use SQL UPDATE Statement to Update Record
There are two syntaxes you have to use and update the values of a table. You can update single data of a table or multiple data of a table. Update data for one column or you can update a record of a table for multiple columns in one statement.
Syntax1: Update Single Column
1 2 3 |
UPDATE tablename SET column_name = 'value' WHERE condition; |
The above syntax update data for the specified column of a table using the WHERE condition. If you do not specify the WHERE condition in the UPDATE statement, the above syntax update all the rows of the specified column. So, specify the WHERE condition to update the exact row of a table.
Syntax2: Update Values for Multiple Specified Columns
1 2 3 |
UPDATE tablename SET column1 = 'value1', column2 = 'value2',...,columnN = 'valueN' WHERE condition; |
If you want to update multiple values for multiple specified columns, you have to use the above syntax. Specify the column names and respected values inside the update statement. If you do not specify the WHERE condition in the above syntax, all the record of multiple columns gets updated.
Parameter Descriptions
Sr.No | Parameter Name | Description |
---|---|---|
1 | column1, column2, column3,…columnN | Enter the column names or which you want to update the rows of a table. |
2 | tablename | Specify the table name for which you want to use the UPDATE statement and update the record. |
3 | condition | The parameter can use to specify the condition from which you will get only the required data from the table. |
4 | value1, value2, value3,…valueN | Specify the value for the specified column of a table. you can specify a single value to update single column and multiple values for multiple columns. |
1 2 3 |
UPDATE Employee SET Salary = '30000' WHERE Salary>25000; |
1 2 3 |
UPDATE Employee SET Salary = '30000', Designation = 'Senior Project Consultant', Group = 'B' WHERE Salary>25000; |
You must also learn.
Reference