The SQL UPDATE statement is used to modify existing records in a table. The syntax of the UPDATE statement is as follows:
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
Here, table_name is the name of the table that you want to update. column1, column2, etc. are the names of the columns that you want to update. value1, value2, etc. are the new values that you want to assign to the columns. The WHERE clause is used to specify the condition that must be met for the records to be updated. If you omit the WHERE clause, all records in the table will be updated.
Examples:
UPDATE customers
SET age = 31
WHERE id = 101;
In this example, the age of the customer with id 101 is updated to 31.
Update the status of all orders in the orders table to ‘completed’
UPDATE orders
SET status = 'completed';
In this example, the status of all records in the orders table is updated to ‘completed’.
By using the UPDATE statement, you can modify existing records in a table and update the data in your database. It is important to be careful when using the UPDATE statement, as it can affect a large number of records if you don’t specify the WHERE clause correctly.
Learners TV is a website that is designed to educate users and provide instructional material on particular subjects and topics.