Curriculum
Course: SQL
Login

Curriculum

SQL

SQL References

0/80

MySQL Functions

0/139

SQL Server Functions

0/84

SQL Quick Ref

0/1
Text lesson

SET Keyword

SET

The SET command, used with UPDATE, specifies which columns and values should be updated in a table.
The following SQL updates the first customer (CustomerID = 1) with a new ContactName and a new City:

Example

UPDATE Customers
SET ContactName = ‘Alfred Schmidt’, City= ‘Frankfurt’
WHERE CustomerID = 1;

The provided SQL will update the “ContactName” field to “Juan” for all records where the Country is “Mexico”:

Example

UPDATE Customers
SET ContactName=‘Juan’
WHERE Country=‘Mexico’;

Note: Caution should be exercised when updating records in a table. Observe the WHERE clause in the UPDATE statement. It specifies which record(s) should be updated. Omitting the WHERE clause will result in updating all records in the table.