只要第三范式的话,2个表就可以表达了 比如仓库系统,一个kind表(货物种类),一个goods表(货物表)
我用SQLServer来写:
if exists(select * from sysobjects where name='kind')
drop table kind;
create table kind(
kid int identity(1,1) not null,
kname varchar(20) not null
)
if exists(select * from sysobjects where name='goods')
drop table goods;
create table goods(
gid int identity(1,1) not null,
kid int not null,
gname varchar(20) not null
)
--设置两个表的主键
alter table kind add constraint pk_kind primary key(kid)
alter table goods add constraint pk_goods primary key(gid)
--设置外键约束
alter table goods add constraint fk_goods_kind foreign key(kid) references kind(kid)
kind表的kid是goods表的外键
一个kind可以对应多个goods,多个goods对应一个kind
http://wenku.baidu.com/view/46b5867301f69e31433294b0.html