create table A
(
TypeID int(2) primary key ,
TypeName nvarchar(10),
Description nvarchar(50)
);
create table B
(
DID int primary key,
TypeID int references A(TypeID),-- 用这种写法是不是不能建立主外建关系
Name nvarchar(30)
);上述语句虽然能运行,但在MySql中主外建关系没有建立起来,但在SqlServer中可以建立主外建关系。
难道非要用下面这种形式写吗?create table B
(
DID int primary key,
TypeID int ,
Name nvarchar(30),
foreign key(TypeID) references A(TypeID)
);
而且要注意一定要用在Innodb表引擎上..否则外键无效