3.5创建药品表,药品代码是主码,批号取值唯一 Create table medicine( Medicinecode char(10)primary key, Medicinename varchar(50), Pycode char(10), Dosagefrom char(10), standard char(15), Batchnumber char(20) unique, Productiondate date, Expirationdate date, Category char(10), Yb char(10)) ; 3.7创建供应商表,主码为表级约束 Create table provider( Providercode char(4) not null, Providername char(60) not null, Pycode char(10), address char(50), Tel char(15), zip char(6), Email char(30), relation char(8), Primary key(providercode) --主码约束,表级约束 ) ; 3.8建立供应表,包含主码、外码,均为标记约束 Create table pm( Medicinecode char(10) not null, Providercode char(4) not null, Pmdate date not null, Price number, qyt int, Primary key(medicinecode,providercode,pmdate), Foreign key(medicinecode) references medicine(medicinecode), Foreign key(providercode)references provider(providercode) ) ;
注意:
列级约束:约束条件前有空格隔开的;
表级约束:和定义属性一样,独成一句,以逗号结尾!
本文出自 “桑海田 博客专栏” 博客,请务必保留此出处http://10602803.blog.51cto.com/10592803/1683064
原文地址:http://10602803.blog.51cto.com/10592803/1683064