插入语句
a) Insert语句
Insert into <表名> (列名,。。。,列名)values(值1,。。。,值n);
Insert into shohinIns (shohin_id,shohin_mei,shohin_bunrui,banbai_tanka,shiire_tanka,torokubi) values (‘0001’,’T恤’,’衣服’,1000,500,’2009-09-20’);
多行insert
Insert into shohinIns values (‘0002’,’打孔器’,’办公用品’,500,320,’2009-09-11’),
(‘0003’,’运动T恤’,’衣服’,4000,2800,NULL);
b) 列清单的省略
对表进行全列insert时,可以省略表名后的列清单。
Insert into shohin values(‘0005’,’高压锅’,’厨房用具’,6800,5000,’2009-01-15’);
如何不设置列的值,系统会默认设为NULL;
c)从其他表中复制数据
Create table shohincopy
(shohin_id char(4) not NULL,
Shohin_mei varchar(100) not NULL,
Shohin_bunrui varchar(32) not NULL,
Hanbai_tanka integer,
Shiire_tanka integer,
Shiire_tanka date,
Torokubi date,
Primary key (shohin_id)
);
Insert into shohincopy (shohin_id,shohin_mei,shohin_bunrui,hanbai_tnaka,shiire_tanka,torokubi)
Select shohin_id,shohin_mei,shohin_bunrui,hanbai_tanka,shiire_tanka,torokubi from shohin;
d)插入其他表的和值
Insert into shohinbunrui(shohin_bunrui varchar(32) not NULL,
Sum_hanbai_tanka,sum_shiire_tanka) select shohin_bunrui,SUM(hanbai_tanka),SUM(shiire_tanka) from shohin group by shohin_bunrui;
4-2数据删除drop table 和delete语句
Delete + 表名;
Delete from shohin;//格式化
Delete from 表名 where 条件;
Delete from shohin where hanbai_tanka >= 4000;
4-3数据更新(update 语句的使用方法)
Update语法的基本语法
Update 表名 set 列名 = 表达式;
Update shohin set torokubi = ‘2009-10-10’;
----将数据日期全部更新为‘2009-10-10’//包括NULL的数据
---确认更新内容
Select * from shohin order by shohin_id;
--将某种商品的记录单价改为十倍
Update shohin set hanbai_tanka = hanbai_tanka * 10 where shohin_bunrui = ‘厨房用具’;