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

2021-10-05 20:27:57 字數 1134 閱讀 4892

一、資料插入insert

1.簡單插入

insert

into aa values

(「a」,「b」,null

);有幾個值就必須寫幾個值

insert

into aa(id,name,code) values

(「a」,「b」,null

);可以插入特定列的值,使用這個語法要求,這些被忽略的特定列是可以為null,或者有預設值

insert

into aa(id,code) values

(「a」,「b」);

插入多行,這樣會比多次插入效率更高:

insert

into aa(id,code) values

(「a」,「b」),(「a1」,「b1」);

盡量不使用第一種,因為第一種高度依賴與表結構,如果表結構發生改變,sql語句就會出錯

2.插入檢索出的值

insert

into aa(id,name,code)

select id,name,code from bb ;

會將bb表中的所有資料都插入到aa表中

3.複製表

create

table aa as

select

*from bb;

二、更新資料update

更新乙個列:

update aa set a=

1where b=

2;

更新多個列:

update aa set a=

1,c=

3where b=

2;

刪除列值:

update aa set a=

null,c=

null

where b=

2;

三、刪除資料 delete (刪除行)

刪除特定行; delete

from aa where a=

1;刪除所有行: select

from aa;

sql更新和刪除

update 語句 update 語句用於修改表中的資料。語法 update 表名稱 set 列名稱 新值 where 列名稱 某值 person lastname firstname address city gates bill xuanwumen 10 beijing wilson champ...

SQL經典例項(四)插入 更新和刪除

定義表的某些列的預設值 create table d id integer default 0 所有的資料庫都支援使用default關鍵字來顯式地為某一列指定預設值 insert into d values default oracle 8i資料庫及更早的版本不支援default關鍵字,因此沒辦法為...

SQL的更新和刪除

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