100 Days of SQL

sql

Day 08 – SQL UPDATE Statement

The SQL UPDATE statement is used to modify existing records in a table. The basic syntax of an UPDATE statement is:


UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

In this syntax, table_name is the name of the table that you want to update records in, and column1, column2, etc. are the names of the columns that you want to update. The SET keyword is used to specify the new values to be assigned to each column. The WHERE clause is used to specify the condition that must be met in order for the update to occur. If no WHERE clause is specified, all records in the table will be updated.

Here’s an example of an UPDATE statement that updates the salary of an employee in a table named “employees”:


UPDATE employees
SET salary = 60000
WHERE id = 1234;

In this example, the UPDATE statement is used to update the salary of the employee with an ID of 1234 to 60000.

You can also update multiple columns at once with a single UPDATE statement. Here’s an example:


UPDATE employees
SET salary = 60000, job_title = 'Manager'
WHERE id = 1234;

In this example, the UPDATE statement updates both the salary and job_title columns of the employee with an ID of 1234.

The UPDATE statement is a fundamental SQL statement that is used to modify existing records in a table. It is commonly used in conjunction with other SQL statements, such as SELECT and JOIN, to manage and manipulate data in a database. When using the UPDATE statement, it’s important to specify the WHERE clause carefully to ensure that only the intended records are updated.