Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 使用外键约束创建表时出错(级联)_Sql Server_Tsql - Fatal编程技术网

Sql server 使用外键约束创建表时出错(级联)

Sql server 使用外键约束创建表时出错(级联),sql-server,tsql,Sql Server,Tsql,我一直在尝试应用此代码,但不断收到错误消息 create table employee ( eid int primary key, ename varchar(50), cid int, sid int, constraint fk_hello1 foreign key(cid) references country(cid)on delete cascade on update cascade, constraint fk_hello2 for

我一直在尝试应用此代码,但不断收到错误消息

create table employee
(
  eid int primary key,
  ename varchar(50),
  cid int,
  sid int,
  constraint fk_hello1 foreign key(cid) references country(cid)on delete 
  cascade on update cascade,         
  constraint fk_hello2 foreign key(sid) references state(sid) on delete
  cascade on update cascade,
)

当数据库结构中的关系中有循环引用时,不能在更新级联上使用

仅允许
无操作
(请参见错误
在删除无操作或
更新时无操作

“国家”和“雇员”中的“国家”有不同的含义吗

正确的解决方案:


表[Employee]的多列上必须有一个外键-FK(CID,SID)

从Employee表中删除记录。@BGS Employee表中没有记录,我正在创建表。好吧-根据错误描述,您似乎有多个级联路径-您在国家和州之间或相似性之间有适当的连接
国家
表/您是否可以检查状态表值sid是否为主键..?在这种情况下,我必须通过我的员工表仅引用国家(cid)?或者,我该如何解决这个问题呢?您必须只参考状态表(见上面的模式)。插图很漂亮,而且解释性很强,但是您是否可以将模式转换为代码,以便我能够理解如何完成上面的操作。2个字段的1FK概念不是我所知道的。所以请解释一下。首先表状态必须在列(Cid,Sid)上有主键,然后您必须将外键约束声明为
constraint[FK\u Employees\u States]外键([Cid],[Sid])引用[dbo]。[State]([Cid],[Sid])
感谢您抽出时间回答我的问题,但我还有另一个表,即“country”有字段(cid(PK),cnames),需要连接到“状态”和“员工”表。
ERROR MESSAGE
Msg 1785, Level 16, State 0, Line 1
Introducing FOREIGN KEY constraint 'fk_hello2' on table 'employee' may 
cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or 
ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.

Msg 1750, Level 16, State 0, Line 1
Could not create constraint. See previous errors.