数据库的创建外键的时候出现了问题,半天没解决啊,求大神帮解决
createtablePlayer(Pnamevarchar(50),Psexchar(1)CHECK(PsexIN('男','女'))DEFAULT'男',Plvtin...
create table Player
(Pname varchar(50),
Psex char(1) CHECK(Psex IN('男','女')) DEFAULT '男',
Plv tinyint CHECK(Plv>=1 AND Plv<=85),
Php smallint,
Pmp smallint,
Prace char(10) CHECK(Prace IN('人类','德莱尼','侏儒','矮人','狼人','地精','血精灵','兽人','亡灵','牛头人')),
Pcamps char(10) CHECK(Pcamps IN('部落','联盟')),
Pcareer char(10) CHECK(Pcareer IN('盗贼','法师','德鲁伊','圣骑士','术士','死亡骑士','战士','猎人','萨满','牧师')),
Pmoney smallint,
PRIMARY KEY(Pname)
)
create table Major
(Ma_name varchar(20),
Ma_count tinyint CHECK(Ma_count>=0 AND Ma_count<=550),
Ma_function varchar(100),
PRIMARY KEY(Ma_name,Ma_function)
)
create table P_M
(Pname varchar(50),
p_Mname varchar(20),
P_Mfunction varchar(100),
PRIMARY KEY(Pname,P_Mname,P_Mfunction),
FOREIGN KEY(Pname) REFERENCES Player(Pname),
FOREIGN KEY(P_Mname) REFERENCES Major(Ma_name),
FOREIGN KEY(P_Mfunction) REFERENCES Major(Ma_function),
)
我想创建三个外键结果
咋就出现了这种错误
Msg 1776, Level 16, State 0, Line 1
There are no primary or candidate keys in the referenced table 'Major' that match the referencing column list in the foreign key 'FK__P_M__P_Mname__3E52440B'.
Msg 1750, Level 16, State 0, Line 1
Could not create constraint. See previous errors. 展开
(Pname varchar(50),
Psex char(1) CHECK(Psex IN('男','女')) DEFAULT '男',
Plv tinyint CHECK(Plv>=1 AND Plv<=85),
Php smallint,
Pmp smallint,
Prace char(10) CHECK(Prace IN('人类','德莱尼','侏儒','矮人','狼人','地精','血精灵','兽人','亡灵','牛头人')),
Pcamps char(10) CHECK(Pcamps IN('部落','联盟')),
Pcareer char(10) CHECK(Pcareer IN('盗贼','法师','德鲁伊','圣骑士','术士','死亡骑士','战士','猎人','萨满','牧师')),
Pmoney smallint,
PRIMARY KEY(Pname)
)
create table Major
(Ma_name varchar(20),
Ma_count tinyint CHECK(Ma_count>=0 AND Ma_count<=550),
Ma_function varchar(100),
PRIMARY KEY(Ma_name,Ma_function)
)
create table P_M
(Pname varchar(50),
p_Mname varchar(20),
P_Mfunction varchar(100),
PRIMARY KEY(Pname,P_Mname,P_Mfunction),
FOREIGN KEY(Pname) REFERENCES Player(Pname),
FOREIGN KEY(P_Mname) REFERENCES Major(Ma_name),
FOREIGN KEY(P_Mfunction) REFERENCES Major(Ma_function),
)
我想创建三个外键结果
咋就出现了这种错误
Msg 1776, Level 16, State 0, Line 1
There are no primary or candidate keys in the referenced table 'Major' that match the referencing column list in the foreign key 'FK__P_M__P_Mname__3E52440B'.
Msg 1750, Level 16, State 0, Line 1
Could not create constraint. See previous errors. 展开
展开全部
看看你的数据库的配置文件中 搜索引擎的类型。就像mysql一样引用外键生效 用enign=innodb一样
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
修改如下
create table P_M
(Pname varchar(50),
p_Mname varchar(20),
P_Mfunction varchar(100),
PRIMARY KEY(Pname,P_Mname,P_Mfunction),
FOREIGN KEY(Pname) REFERENCES Player(Pname),
FOREIGN KEY(P_Mname,P_Mfunction ) REFERENCES Major(Ma_name,Ma_function)
)
create table P_M
(Pname varchar(50),
p_Mname varchar(20),
P_Mfunction varchar(100),
PRIMARY KEY(Pname,P_Mname,P_Mfunction),
FOREIGN KEY(Pname) REFERENCES Player(Pname),
FOREIGN KEY(P_Mname,P_Mfunction ) REFERENCES Major(Ma_name,Ma_function)
)
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询