SQL Server 2008 Foreign Key error -



SQL Server 2008 Foreign Key error -

i tried inputting primary , foreign keys after creating table. having issue foreign key, , appreciate help! here code:

create table employee ( ssn_number char(9) not null, first_name varchar(15)not null, mid_name char, last_name varchar(15) not null, birthday date, address varchar(50), gender char, salary money default 8000, supervisor_ssn char(9), department_number int ); alter table employee add together constraint pk_employee primary key (ssn_number); add together constraint ck_employee check (gender in ('m', 'm', 'f', 'f')) add together constraint fk_employee foreign key (supervisor_ssn) references employee (ssn_number) on delete set null;

the error foreign key is:

msg 1785, level 16, state 0, line 1 introducing foreign key constraint 'fk_employee' 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.

removing supervisor should set null values rows supervisor exists

you can't have on delete cascade complained sql server creates cycles.

you need create foreign key out on delete clause

alter table employee add together constraint fk_employee foreign key (supervisor_ssn) references employee (ssn_number) ;

now need think how set supervisor null on deletion. can read triggers this.

the hint utilize insetad of delete trigger on table , set null value deleted supervisor.

you can write trigger reading up.

sql-server sql-server-2008

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -