How to Update Data in SQL Server
Usually you only want to update rows that match a certain condition. You do this by specifying a WHERE
clause:
--this will update only one row that matches id=1
update sessions
set start_date='2020-02-20 10:12:15.653',
end_date='2020-02-22 15:40:30.123'
where id = 1;
--this will update multiple rows that match category=1
update sessions
set end_date = null
where category = 1;
To update all rows in a SQL Server table, just use the UPDATE
statement without a WHERE
clause:
update sessions
set end_date = '2020-02-04 16:57:53.653';
You can also update multiple columns at a time:
update sessions
set start_date = '2020-02-02 14:05:15.400',
end_date = '2020-02-04 16:57:53.653';
Previous
How to Insert Data