Update command in SQL Server
The update command uses the update of existing data in the table (a certain record or list of records), usually updating according to a primary key condition, or a certain condition. If you do not enter the condition, it will update all records in the table.
UPDATE table_name SET column_name1 = expr1, column_name2 = expr2, ... [WHERE condition];
- table_name: the name of the table that you want to update the records for
- column_name: the name of the column you want to update
- value: define a new value for the column to be edited
- WHERE condition: a condition that defines the purpose of filtering the records to be updated.
UPDATE Person.PersonPhone SET PhoneNumber = '731-511-0142' WHERE BusinessEntityID=299 AND ModifiedDate ='2020-10-12'
In the above example, I update the phonenumber for the record in the PersonPhone table, with the condition that BusinessEntityID = 299 and ModifiedDate = '2020-10-12'
If I don't specify the WHERE condition, the entire PhoneNumber column data of the PersonPhone table is updated to '731-511-0142'