Home > Archive > microsoft.public.sqlserver.server > October 2002 > Partitioning data and referential integrity





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Partitioning data and referential integrity
Mark DeWaard

2002-10-05, 9:07 pm

What is the best way to enforce referential integrity?

Can we use Declarative Referential Integrity or do we need to set it up
using triggers?



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





Sponsored Links





Free Braindumps | MCSE braindumps software forum

Copyright 2003 - 2008 examnotes.net