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
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 |
|
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started