📄 维勒斯.txt
字号:
1.
创建商品表
create table merchandise (id int,name varchar2(10),sort varchar2(10),price number(5,2));
创建种类表
create table class (id int primary key,sort varchar2(10));
对种类表设置非空和唯一性
alter table class modify sort not null;
alter table class add unique(sort);
种类表已完善
添加商品表约束:主键,外键,检查
alter table merchandise add constraint pk primary key (id,name);
alter table merchandise add constraint fk foreign key (sort) references class (sort);
alter table merchandise add constraint ck check (price>0);
商品表基本完善
商品表仍不符合第二范式规范,因为种类价格不能由id和name完全确定。如新加入商品,可能出现同一商品几种种类或价格的问题。欲完善之,还应建立价格表和种类清单表。
*******************************************************
2.
SQL> insert into class values (1,'food');
SQL> insert into class values (2,'commodity');
SQL> insert into class values (3,'medicine');
SQL> insert into merchandise values (1,'steak','food',7.00);
SQL> insert into merchandise values (2,'soap','commodity',0.50);
SQL> insert into merchandise values (3,'aspirin','medicine',15.50);
SQL> insert into merchandise values (3,'aaa','medicine',0.10);
SQL> delete from merchandise where price=0.10;
SQL> update merchandise set name='steak' where id=2;
SQL> select * from merchandise;
ID NAME SORT PRICE
--------------------------------------- ---------- ---------- -------
1 steak food 7.00
2 steak commodity 0.50
3 aspirin medicine 15.50
---------------------
出现了增异常和改异常
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -