SQL SERVER 2000 CONSTRAINT INVOLVING COLUMN ON DIFFERENT TABLE

john rob

Total Post:108

Points:756
Posted by  john rob
 894  View(s)
Ratings:
Rate this:
Hi Expert!

I would like a constraint on a SQL Server 2000 table column that is sort of a combination of a foreign key and a check constraint. The value of my column must exist

in the other table, but I am only concerned with values in the other table where one of its columns equal a specified value. The simplified tables are:

import_table:
part_number  varchar(30)
quantity     int

inventory_master:
part_number  varchar(30)
type         char(1)
So I want to ensure the part_number exists in inventory_master, but only if the type is 'C'. Is this possible? Thanks.

Thanks in advance!
  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: SQL Server 2000 constraint involving column on different table

    Hi John!


    You could use an INSTEAD OF INSERT trigger to emulate that behaviour.

    Check value existence when an insert is about to occur.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!