此次的任务是建立一个超市收银系统的数据库,从建表到插入测试数据,再到后面根据要求写出相应的查询语句,对于我来说是复习了。
因为主要是写给自己看的,所以就不多说废话了,直接开始吧。
首先是建表并建立相应的约束条件
--创建商品类别表s_Category
create table s_Category(
CId int primary key,
cname varchar(20) not null,
description varchar(50)
);
--创建商品信息表s_ware
create table s_ware(
wid int primary key,
wname varchar(20) not null,
cid int not null,--外键
purchaseprice number(10,2) default '0',
salesprice number(10,2) default '0',
amount int
);
--建立purchaseprice,salesprice,amount只能大于等于0的约束
Alter Table s_ware add Constraint c_pur check(purchaseprice>=0);
Alter Table s_ware add Constraint c_sale check(salesprice>=0);
Alter Table s_ware add Constraint c_am check(amount>=0);
--创建员工表
create table s_employee(
eid int primary key,
ename varchar(10) not null,
epassword varchar(18) not null check (length(epassword)>=6),
remark varchar(50)
);
--创建销售记录表
create table s_salesinfo(
sid int primary key,
wid int not null,--外键
salesdate date not null,
salesamount int not null,
eid int not null--外键
);
--建立salesamount只能大于等于0的约束
Alter Table s_salesinfo add Constraint c_sinfo check(salesamount>=0);
建完表之后再写几条关于表的操作语句,方便后续对表进行操作。
--查询表信息
select * from s_Category;
select * from s_ware;
select * from s_employee;
select * from s_salesinfo;
--删除表
drop table s_Category
drop table s_ware;
drop table s_employee
drop table s_salesinfo;
--清空表内数据
delete from s_Category;
delete from s_ware;
delete from s_employee;
delete from s_salesinfo;
写好操作表的语句之后就可以开始插入测试数据了
--添加测试数据
insert into s_ware(wid,wname,cid,purchaseprice,salesprice,amount) values(10010,'高露洁牙膏',1,4.5,5.8,231);
insert into s_ware(wid,wname,cid,purchaseprice,salesprice,amount