Coginiti menu Coginiti menu

SQL Update

Update Data in SQL

The update query in SQL modifies existing data in a table. This command allows you to change one or more columns for one or many rows in a table.

The basic syntax is as follows:

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

IMPORTANT: If you omit the WHERE clause, the UPDATE statement will modify all the rows in the table.

For example, suppose you have a table named bookshop with columns title, price, and author, and you want to increase the prices to 10% higher for all Jane Austen books.

The update query in SQL to increase the price from 14 to 15.4 would be:

UPDATE bookshop SET
price = price * 1.1
WHERE author = 'Jane Austen';

Note that the UPDATE statement can significantly impact your data. So, always double-check your WHERE clause to ensure you only modify the intended rows. Back up your data before making any changes, especially in production environments.

An Easier Way to Update Data Into a Table

If you are in Coginiti, you can right-click the table or column you want to update and select UPDATE statement to automatically generate the code with the proper schema. Then, replace the blanks with your needed updates.