I have two tables and I want to use the database to enforce a constraint against them.
Table A has a one to many relationship with table B, that is many table B rows belong to exactly one table A row. Table B has a column of the Table A primary key that it belongs to. Anyway, I want to add a column to both table A and table B where the value of it in a table A record must equal the value of it in the corresponding table B records.
I want to tell SQL Server 2000 to disallow updates or additions of table B records unless the values in the sister columns are the same. How can I do this? I tried using a check constraint but it doesn’t like subqueries. Will I have to venture into the world of triggers? Is there another way?
Any help would be appreciated.
Thanks
Isaac
What you’re trying to do sounds like a foreign key relationship – but you already seem to have that (Table B has a column of Table A primary key).
I don’t think you can define such a constraint –
CHECKconstraints cannot span tables, as far as I know. So in the end, you will probably need to use triggers instead on both tables to achieve this.