加上外键约束就可以了:
ALTER TABLE B ADD
CONSTRAINT [FK_A_B] FOREIGN KEY ([flashid])
REFERENCES [A] ([ID])
ALTER TABLE C ADD
CONSTRAINT [FK_B_C] FOREIGN KEY ([scenceid])
REFERENCES [B] ([ID])
GO
ALTER TABLE B ADD
CONSTRAINT [FK_A_B] FOREIGN KEY ([flashid])
REFERENCES [A] ([ID])
ALTER TABLE C ADD
CONSTRAINT [FK_B_C] FOREIGN KEY ([scenceid])
REFERENCES [B] ([ID])
GO
ALTER TABLE B ADD
CONSTRAINT [FK_B_A] FOREIGN KEY
( FlashID ) REFERENCES A ( [ID])
ALTER TABLE C ADD
CONSTRAINT [FK_C_B] FOREIGN KEY
( scenceid) REFERENCES B ( [ID])
go
alter table c add constraint fk_name Foreign key(scenceid) references B(id)
create table B(ID int,scenceid int,flashid int,Primary key(ID))
create table C(ID int,scenceid int,content varchar(200),Primary key(ID))--添加外键关系
ALTER TABLE b ADD CONSTRAINT FK_b_a
FOREIGN KEY(flashid) REFERENCES a(id)
ON UPDATE CASCADE --级联更新
ON DELETE CASCADE --级联删除ALTER TABLE c ADD CONSTRAINT FK_c_b
FOREIGN KEY(scenceid) REFERENCES b(id)
ON UPDATE CASCADE --级联更新
ON DELETE CASCADE --级联删除insert into A
select 1,'瞒天过海'
union all select 2,'借刀杀人'
union all select 3,'指桑骂槐'
union all select 4,'美人计'
union all select 5,'离间计'
union all select 6,'空城计'insert into B
select 1,1,1
union all select 2,2,1
union all select 3,3,1
union all select 4,4,1
union all select 5,1,2
union all select 6,2,2
union all select 7,3,2
union all select 8,4,2
union all select 9,1,3
union all select 10,2,3insert into C
select 1,1,'aaaa'
union all select 2,2,'bbbb'
union all select 3,3,'cccc'
union all select 4,4,'dddd'
union all select 5,5,'eeee'
union all select 6,6,'ffff'
union all select 7,7,'gggg'
union all select 8,8,'hhhh'
union all select 9,9,'iiii'
union all select 10,10,'jjjj'
wzh1215大哥:用关系图来建,怎么建???
create table B(ID int,scenceid int,flashid int,Primary key(ID)
,CONSTRAINT FK_b_a FOREIGN KEY(flashid) REFERENCES a(id)
ON UPDATE CASCADE ON DELETE CASCADE)
create table C(ID int,scenceid int,content varchar(200),Primary key(ID)
,CONSTRAINT FK_c_b FOREIGN KEY(scenceid) REFERENCES b(id)
ON UPDATE CASCADE ON DELETE CASCADE)
你也可以在企业管理器中直观的去添加。。表--〉设计--〉管理关联