constraint
外键表名_id_fk
foreign
key
(外键字段名)
references
主表名(主表id)
create
table
FirNav
(
id int primary key identity ( 1 , 1 ) not null ,
navName varchar ( 10 ) not null ,
);
create table SecNav
(
id int primary key identity ( 1 , 1 ) not null ,
navName varchar ( 10 ) not null ,
firId int ,
constraint SecNav_id_fk foreign key (firId) references FirNav(id)
);
create table ThirdNav
(
id int primary key identity ( 1 , 1 ) not null ,
navName varchar ( 10 ) not null ,
secId int ,
constraint ThirdNav_id_fk foreign key (secId) references SecNav(id)
);
(
id int primary key identity ( 1 , 1 ) not null ,
navName varchar ( 10 ) not null ,
);
create table SecNav
(
id int primary key identity ( 1 , 1 ) not null ,
navName varchar ( 10 ) not null ,
firId int ,
constraint SecNav_id_fk foreign key (firId) references FirNav(id)
);
create table ThirdNav
(
id int primary key identity ( 1 , 1 ) not null ,
navName varchar ( 10 ) not null ,
secId int ,
constraint ThirdNav_id_fk foreign key (secId) references SecNav(id)
);