SQL: UPDATE Statement

In daily use, a database is a constantly changing store of data. The SQL commands which are used to modify data that is already in the database are the Update and the Delete commands.The Update statement allows you to update a single record or multiple records in a table.

The syntax for the Update statement is as follows:

UPDATE table_name 
SET column_name = expression
WHERE conditions

Example #1

UPDATE AntiqueOwners 
SET Address = '77, Lincoln st.'
WHERE OwnerFirstName= 'Jane' and OwnerLastName = 'Akins'

The Update statement can be used in updating a single field in a table.This statement would update address of Jane Akins in the AntiqueOwners table to 77, Lincoln st..

Note: The Update doesn’t generate a result set. If you want to know which records will be modified, first run a Select query that uses the same criteria. If the results are satisfactory, then run the update query.

Example #2

UPDATE AntiqueOwners 
SET Address = '77, Lincoln st.', City = 'Kirkland', State = 'Washington'
WHERE OwnerFirstName='Jane' And OwnerLastName='Akins'

The Update statement can also be used to update more than one field in a table. The preceding example changes the address, city and state.

admin

admin

Leave a Reply

Your email address will not be published.