-- ************************************ -- 得意先マスタ -- ------------------------------------ -- 制約 各項目の not null -- 得意先コード 数字 2桁(0埋め) -- ************************************ create table customer_master ( customer_code char(2) not null, customer_name varchar(30) not null, constraint pk_customer_master primary key(customer_code), check (customer_code like '[0-9][0-9]') ) -- ************************************ -- 商品マスタ -- ------------------------------------ -- 制約 各項目の not null -- 商品コード 数字 2桁(0埋め) -- ************************************ create table article_master ( article_code char(2) not null, article_name varchar(30) not null, price smallmoney not null, cost smallmoney not null, constraint pk_article_master primary key(article_code), check (article_code like '[0-9][0-9]'), check (price >= cost) ) -- ************************************ -- 受注 -- ------------------------------------ -- 制約 各項目の not null -- 得意先コードの参照制約、 -- および 外部キー制約 -- ************************************ create table receive_order ( order_no int not null, customer_code char(2) not null, order_date char(10) not null, constraint pk_receive_order primary key(order_no), foreign key (customer_code) references customer_master(customer_code) ) -- ************************************ -- 受注明細 -- ------------------------------------ -- 制約 各項目の not null -- 商品コードの参照制約 -- および 外部キー制約 -- ************************************ create table order_item ( order_no int not null, seqno int not null, article_code char(2) not null, qty int not null, price smallmoney not null, constraint pk_order_item primary key(order_no,seqno), foreign key (order_no) references receive_order(order_no), foreign key (article_code) references article_master(article_code) )