sarahHH
sarahHH

Reputation: 191

support for check constraint for foreign key

I have the following tables in database

Employee(emp_id,emp_name,salary,dept_id)
Department(dept_id,dept_name,location)

dept_id in Employee table is foreign key references on Department(dept_id)

I want to ask if I can make these constraint or not

(when inserting a row in employee table, the dept_id must found in department table, if it is not found >> it's automatically inserted in department table) Can I make this using check constraint, if yes, how? if no, why?

Thanks

Upvotes: 2

Views: 31

Answers (1)

Tab Alleman
Tab Alleman

Reputation: 31785

No, constraints cannot do inserts into other tables. To do what you want, you need to write a Trigger.

Upvotes: 1

Related Questions