I would avoid doing this if I could - can you just keep both tables in one datbase and use an FK?
Parent and Child Tables Are in Different Databases.
Although you cannot use a foreign key in this situation, there are workarounds – you can use either triggers or UDFs wrapped in check constraints. Either way, your data integrity is not completely watertight: if the database with your parent table crashes and you restore it from a backup, you may easily end up with orphans.
Parent-Child Relationship Is Enforced by Triggers.
There are quite a few situations when triggers do not fire, such as:
· A table is dropped.
· A table is truncated.
· Settings for nested and/or recursive triggers prevent a trigger from firing.
Also a trigger may be just incorrect. Either way, you may end up with orphans in your database.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…