| Anith Sen 2002-10-05, 9:07 pm |
| I would suggest you use DRI with foriegn key constraints,
provided your table is normalized and logical relationships
are in place. Performance-wise you will get better results with
a Foreign key constraint than with a trigger. With a trigger
you can try something along the lines of
....
IF UPDATE(ReferCol)
BEGIN
IF EXISTS(SELECT * FROM INSERTED WHERE NOT EXISTS(
SELECT * FROM ReferTable
WHERE INSERTED.ReferCol = ReferTable.ReferCol)
ROLLBACK
END
If you are on SQL 2000, you can use INSTEAD OF triggers as well.
Another option in SQL 2K is to create an UDF and use it as a part
of the CHECK constraint (I have not done this, but posted based on
a old post by someone..)
--
- Anith
|