Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to make CONSTRAINT CHECK for values in another table?

Status
Not open for further replies.

TheBugSlayer

Programmer
Sep 22, 2002
887
US
Is it possible to set a constraint on a field so that it checks that the value being entered exists in another table?

Something like
... emp_id empid
CONSTRAINT CK_emp_id CHECK (emp_id IN
SELECT emp_id FROM Employees)...

It that is not possible, what is the alternative?

Thanks for your help.

 
You could use an instead of trigger. PUt the thing in an if and run the update only if it doesn;t exist inthe other table
 
Yes that works, I know for sure. I think I took the wrong aproach from start, what I need is to add a foreign key constraint to the field.

Thank you anyway.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top