EN
MS SQL Server - UPDATE statement
0 points
In this article, we would like to show you how to use UPDATE
statement in MS SQL Server.
Quick solution:
xxxxxxxxxx
1
UPDATE [table_name]
2
SET [column1] = value1, [column2] = value2, ...
3
WHERE condition;
Note:
Be careful when updating records. If you omit the
WHERE
clause, all records will be updated!
To show how the UPDATE
statement works, we will use the following table:

Note:
At the end of this article you can find database preparation SQL queries.
In this example, we will update information about moderator Chris.
Query:
xxxxxxxxxx
1
UPDATE [users]
2
SET [name] = 'Christopher' , [role] = 'admin'
3
WHERE [id] = 2;
Output:

create_tables.sql
file:
xxxxxxxxxx
1
CREATE TABLE [users] (
2
[id] INT IDENTITY(1,1),
3
[name] VARCHAR(100) NOT NULL,
4
[role] VARCHAR(15) NOT NULL,
5
PRIMARY KEY ([id])
6
);
insert_data.sql
file:
xxxxxxxxxx
1
INSERT INTO [users]
2
([name], [role])
3
VALUES
4
('John', 'admin'),
5
('Chris', 'moderator'),
6
('Kate', 'user'),
7
('Denis', 'moderator');