sql更新和刪除

2021-10-01 10:22:35 字數 1256 閱讀 7448

update 語句

update 語句用於修改表中的資料。

語法:update 表名稱 set 列名稱 = 新值 where 列名稱 = 某值

person:

lastname firstname address city

gates bill xuanwumen 10 beijing

wilson champs-elysees

更新某一行中的乙個列

我們為 lastname 是 「wilson」 的人新增 firstname:

update person set firstname = 『fred』 where lastname = 『wilson』

結果:lastname firstname address city

gates bill xuanwumen 10 beijing

wilson fred champs-elysees

更新某一行中的若干列

我們會修改位址(address),並新增城市名稱(city):

update person set address = 『zhongshan 23』, city = 『nanjing』

where lastname = 『wilson』

結果:lastname firstname address city

gates bill xuanwumen 10 beijing

wilson fred zhongshan 23 nanjing

delete 語句

delete 語句用於刪除表中的行。

語法delete from 表名稱 where 列名稱 = 值

person:

lastname firstname address city

gates bill xuanwumen 10 beijing

wilson fred zhongshan 23 nanjing

刪除某行

「fred wilson」 會被刪除:

delete from person where lastname = 『wilson』

結果:lastname firstname address city

gates bill xuanwumen 10 beijing

刪除所有行

可以在不刪除表的情況下刪除所有的行。這意味著表的結構、屬性和索引都是完整的:

delete from table_name

或者:delete * from table_name

SQL的更新和刪除

1 sql更新資料 示例 update table name set some column some value other column other value where unique column unique value 上述示例示更新指定行,若想更新所有的行,那麼去掉where子句即可。...

SQL級聯更新和級聯刪除

alter table 表名 add constraint 約束名 foreign key 欄位名 references 主表名 欄位名 on delete cascade 語法 foreign key column n references referenced table name ref co...

SQL學習(2) 插入,更新和刪除

一 資料插入insert 1.簡單插入 insert into aa values a b null 有幾個值就必須寫幾個值 insert into aa id,name,code values a b null 可以插入特定列的值,使用這個語法要求,這些被忽略的特定列是可以為null,或者有預設值...