How to implement cross database foreign key constraint

  • If i have a table on database A and one of the keys is called PErsonID and if for some reason I have a table on database B which also uses PersonID as well. How can I ensure referrential integrity bearing in mind that both tables are across different databases.

    Any ideas ?

  • A trigger.

    Foreign key constraints cannot reference objects in other databases so to do cross-DB referential integrity you need triggers.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Thanks for the reply, is that the best way to do it, how about functions that are part of a check constraint, returns a bit. is that better ?

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply