Alter Table column defined as foreign key

Database
Enthusiast

Alter Table column defined as foreign key

Hello, 

I have two tables. Employee & department.

employee[emp_id, emp_name, Department_id, emp_address]

department[department_id, department_name]

Department_id in employee table has been defined as a foreign key on Department.department_id

and Null values are allowed.

I am trying to alter employee table to alter department_id NOT NULL using below query. 

ALTER TABLE Employee

Add Department_ID NOT NULL INTEGER

I am getting an error that "Foreign key column Department_ID can not be modified."

Can I  not  modify foreign key column in referncing table? If Yes how?

2 REPLIES
Enthusiast

Re: Alter Table column defined as foreign key

Just a thought..

Drop the foreign key reference and then try to alter the table.....

Enthusiast

Re: Alter Table column defined as foreign key

Also,the column type that you are trying to change to NOT NULL if it is indexed then the attributes can not be altered.For non-indexed column defined as NULL can be altered to NOT NULL provided that the column does not contain nulls.