sql server - Getting error on create table with foreign key constraint (Cascade) -
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, )
i have been trying apply code getting error msg.........
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 not create constraint. see previous errors.
you can not use on update cascade
when have cycle references in relations in database structure:
only no action
allowed (see error specify on delete no action or on update no action
)
is state country has different meaning state in employee ?
correct solution:
and table [employee] must have 1 foreign key on multiple columns - fk(cid, sid)
Comments
Post a Comment