记录自己的Oracle之旅(一)

本文记录了一次使用Oracle构建超市收银系统数据库的过程,包括建表、设置约束、插入测试数据和解决查询问题。在解决查询商品销售量前五的问题时,遇到了技术限制。虽然用SQL Server教材作为参考,但SQL Server、Oracle和MySQL的SQL语法相似,此练习对学习Oracle同样有价值。由于未解决全部问题,作者计划日后继续完善。
摘要由CSDN通过智能技术生成

此次的任务是建立一个超市收银系统的数据库,从建表到插入测试数据,再到后面根据要求写出相应的查询语句,对于我来说是复习了。
因为主要是写给自己看的,所以就不多说废话了,直接开始吧。

首先是建表并建立相应的约束条件

--创建商品类别表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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值