1.插入數(shù)據(jù)
1)不指定字段名的插入
insert into 表名 values(值1钞钙,值2鳄橘,..., 值n)
此方法表定義多少字段就需要插入多少數(shù)據(jù)芒炼,且按表字段順序排列對應(yīng)值
2)列出所有字段
insert into 表名 (屬性1瘫怜,屬性2,...本刽,屬性n) values(值1鲸湃,值2赠涮,..., 值n )
不需要對應(yīng)字段位置
3)為指定字段插入數(shù)據(jù)
insert into 表名(屬性1唤锉,屬性2)values (值1世囊,值2)
4)插入多條記錄
insert into 表名[(屬性列表)] values (取值列表1),(取值列表2)...(取值列表n)
屬性列表為空則表示所有字段
實例:
insert into product (id,name,company) values(1001,'name1','htc'),(1002,'name2','sanxing'),(1003,'name3','xiaomi')
5)將查詢結(jié)果插入到表中
insert into 表名1(屬性列表1)select 屬性列表2 from 表名2 where 條件表達式
屬性列表1與屬性列表1字段個數(shù)相同且數(shù)據(jù)類型對應(yīng)相同窿祥。
實例:
insert into product (id,name,address) select id,name,address from medicine;
2.更新數(shù)據(jù)
update 表名 set 屬性名1=取值1株憾,屬性名2=取值2,...晒衩,屬性名n=取值n where 條件表達式嗤瞎;
3.刪除數(shù)據(jù)
delete from 表名 [where 條件表達式]
此表達式可以刪除單條或多條數(shù)據(jù)。
實例:
delete from product where id=1001;