天天看點

建立基本表、資料庫、列級/表級限制

3.5建立藥品表,藥品代碼是主碼,批号取值唯一
Create table medicine(
Medicinecode char()primary key,
Medicinename varchar(),
Pycode char(),
Dosagefrom char(),standard char(),
Batchnumber char() unique,
Productiondate date,
Expirationdate date,
Category char(),
Yb char())
;

3.7建立供應商表,主碼為表級限制
Create table provider(
Providercode char() not null,
Providername char() not null,
Pycode char(),
address char(),
Tel char(),
zip char(),
Email char(),
relation char(),
Primary key(providercode) --主碼限制,表級限制
)
;

3.8建立供應表,包含主碼、外碼,均為标記限制
Create table pm(
Medicinecode char() not null,
Providercode char() 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)
);

           

注意:

列級限制:限制條件前有空格隔開的;

表級限制:和定義屬性一樣,獨成一句,以逗号結尾!