SQL指南-Update 语句 - replace

时间:2024-02-19 20:57:00

SQL指南-Update 语句

Update 语句

Update 语句用于修改表中的数据。

语法

UPDATE table_name
            SET column_name = new_value
            WHERE column_name = some_value

---------------------------------

Person:

LastName FirstName Address City
Nilsen Fred Kirkegt 56 Stavanger
Rasmussen   Storgt 67  

---------------------------------

连续更新一列

我们想给last name为"Rasmussen"的人添加first name

UPDATE Person SET FirstName = \'Nina\'
            WHERE LastName = \'Rasmussen\'

返回结果:

LastName FirstName Address City
Nilsen Fred Kirkegt 56 Stavanger
Rasmussen Nina Storgt 67  

---------------------------------

连续更新多列

我们想改变地址并添加城市名称

UPDATE Person
            SET Address = \'Stien 12\', City = \'Stavanger\'
            WHERE LastName = \'Rasmussen\'

返回结果

LastName FirstName Address City
Nilsen Fred Kirkegt 56 Stavanger
Rasmussen Nina Stien 12 Stavanger