SQL UPDATE Syntax
UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value
Note: Notice the WHERE clause in the UPDATE syntax. The WHERE clause specifies which record or records that should be updated. If you omit the WHERE clause, all records will be updated!
SQL UPDATE Example
The "Persons" table:
Now we want to update the person "Joshi, Pradnya" in the "Persons" table.
We use the following SQL statement:
UPDATE Persons
SET Address='Vile Parle', City='Mumbai'
WHERE LastName='Joshi' AND FirstName='Pradnya'
The "Persons" table will now look like this:
SQL UPDATE Warning
Be careful when updating records. If we had omitted the WHERE clause in the example above, like this:
UPDATE Persons
SET Address='Vile Parle', City='Mumbai'
The "Persons" table would have looked like this:
0 comments:
Post a Comment