SQL Tutorial


SQL CREATE TABLE
SQL DROP TABLE
SQL TRUNCATE TABLE
SQL INSERT INTO
SQL UPDATE
SQL DELETE FROM







Data Warehousing & Business Intelligence
Area Codes Info
State Info
HTML Tutorial























Home
SQL Commands
Table Manipulation
SQL Syntax

SQL UPDATE

Once we have the information in the table, we might find that there is a need to modify the data. To do so, we can use the UPDATE command. The syntax for this is

UPDATE "table_name"
SET "column_1" = [new value]
WHERE {condition}

It is easiest to use an example. Say we currently have a table as below:

Table Store_Information
store_name Sales Date
Los Angeles $1500 Jan-05-1999
San Diego $250 Jan-07-1999
Los Angeles $300 Jan-08-1999
Boston $700 Jan-08-1999

We find that the sales for Los Angeles on 01/08/1999 is actually $500 instead of $300, and we need to update that particular entry. To do so, we use the following SQL:

UPDATE Store_Information
SET Sales = 500
WHERE store_name = "Los Angeles"
AND Date = "Jan-08-1999"

The resulting table would look like

Table Store_Information
store_name Sales Date
Los Angeles $1500 Jan-05-1999
San Diego $250 Jan-07-1999
Los Angeles $500 Jan-08-1999
Boston $700 Jan-08-1999

In this case, there is only one row that satisfies the condition in the WHERE clause. If there are two rows that satisfy the condition, both rows will be modified.

It is also possible to UPDATE multiple columns at the same time. The syntax in this case would look like the following:

UPDATE TABLE "table_name"
SET ("column_1", "column_2") = ([new value 1], [new value 2])
WHERE {condition}


Next Section

Site Map   |   Resources

1