[英]There are no primary or candidate keys in the referenced table 'Tabs'
I have 2 tables 我有2张桌子
Table #1: 表格1:
CREATE TABLE Tabs
(
TabId int,
UserId int,
TabName varchar(20),
SettingName varchar(5000),
PRIMARY KEY (TabId, userId),
FOREIGN KEY (UserId) REFERENCES UserProfile(UserId),
)
Table #2: 表#2:
CREATE TABLE TabsSettings
(
TabId int,
UserId int,
TabName varchar(20),
SettingName varchar(5000),
SettingValue varchar(5000),
ModifiedOn datetime,
CreatedOn datetime,
PRIMARY KEY (TabId, userId),
FOREIGN KEY (UserId) REFERENCES Tabs(UserId),
FOREIGN KEY (TabId) REFERENCES Tabs(TabIdId)
)
When I am trying to execute my 2nd query it shows this error 当我尝试执行第二个查询时,它显示此错误
Msg 1776, Level 16, State 0, Line 1
Msg 1776,Level 16,State 0,Line 1
There are no primary or candidate keys in the referenced table 'Tabs' that match the referencing column list in the foreign key 'FK_ TabsSetti _UserI__7EF6D905'.引用表'Tabs'中没有主键或候选键与外键'FK_ TabsSetti _UserI__7EF6D905'中的引用列列表匹配。
Msg 1750, Level 16, State 0, Line 1Msg 1750,Level 16,State 0,Line 1
Could not create constraint.无法创建约束。 See previous errors.
查看以前的错误。
您必须使用单个外键引用这两列:
FOREIGN KEY (TabId,UserId) REFERENCES Tabs(TabId,UserId)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.