C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
SQL Update StatementThe SQL UPDATE statement is used to modify the data that is already in the database. The condition in the WHERE clause decides that which row is to be updated. Syntax UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition; Sample TableEMPLOYEE
Updating single recordUpdate the column EMP_NAME and set the value to 'Emma' in the row where SALARY is 500000. Syntax UPDATE table_name SET column_name = value WHERE condition; Query UPDATE EMPLOYEE SET EMP_NAME = 'Emma' WHERE SALARY = 500000; Output: After executing this query, the EMPLOYEE table will look like:
Updating multiple recordsIf you want to update multiple columns, you should separate each field assigned with a comma. In the EMPLOYEE table, update the column EMP_NAME to 'Kevin' and CITY to 'Boston' where EMP_ID is 5. Syntax UPDATE table_name SET column_name = value1, column_name2 = value2 WHERE condition; Query UPDATE EMPLOYEE SET EMP_NAME = 'Kevin', City = 'Boston' WHERE EMP_ID = 5; Output
Without use of WHERE clauseIf you want to update all row from a table, then you don't need to use the WHERE clause. In the EMPLOYEE table, update the column EMP_NAME as 'Harry'. Syntax UPDATE table_name SET column_name = value1; Query UPDATE EMPLOYEE SET EMP_NAME = 'Harry'; Output
Next TopicDBMS SQL Delete
|