Question: Employee Attribute Data Type Primary Foreign Constraint SSN Number Charr(9) Check Not Null First Name VarChar(15) Not Null MidName Char Last Name VarChar(15) Not Null

Employee
Attribute Data Type Primary Foreign Constraint
SSN Number Charr(9) Check Not Null
First Name VarChar(15) Not Null
MidName Char
Last Name VarChar(15) Not Null
Birthday Date

Gender Char

Gender CHECK

('M','F','m','f')

Salary Money DEFAULT '80000'
Supervisor SSN Char(9) employee(SSN)
Department Number

Int

Department
Attribute Data Type Primary Foreign Constraint
Department Name VarChar(15) Not Null
Department Number Int Check Not Null
Manager SSN Char(9)

Employee(SSN)

ON DELETE SET NULL

Not Null
Manage Start Date Date

I need to make a foreign key with Manager SSN that relates to Employee SSN, but every time I try to put it in SQL it doesn't allow it due to referential integrity constraints.

My Code in MySQL is as follows:

Alter Table Department_JCS Add Constraint Department_fk Foreign Key (ManagerSSN) References Employee_JCS(EmployeeSSN) On Delete Set Null Go

And the problem I get is:

Msg 1761, Level 16, State 1, Server DESKTOP-54BQ7EN\LOCALDB#743D77CD, Line 1 Cannot create the foreign key "Department_fk" with the SET NULL referential action, because one or more referencing columns are not nullable.

What must I change in order to allow the constraint?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!