Foreign Reference with another database

  • Hi All,

    I have a table [Vendor] in first database SAMPLEDB. And i have another table [Contract] in another database TESTDB. I need a foreign key in the [Contract] table (which is in TESTDB database) is reference to the other table [Vendor] which is present in the SAMPLEDB.

    When i try to creating them through SQL, i received the following error message :

    Msg 1763, Level 16, State 0, Line 1

    Cross-database foreign key references are not supported. Foreign key 'SAMPLEDB..VENDOR'.

    Is that possible to refer foreign key in external database or not?

    If possible, please give solution for this. If not possible, please suggest some alternate way.

    Thanks in Advance

  • As the error message already said, you cannot create foreign key relationshsips between databases.

    As a workaround you could create create a check constraint.

    [font="Verdana"]Markus Bohse[/font]

  • Thank u for your quick response.

  • A check constraint will work, but you take a performance hit so be careful.

    I seem to remember there being some kind of 3rd party product for doing this so you may want to google it.

  • A check constraint will work. There are also ways to solve this with a trigger.

    You might want to test a few options on both of those concepts and see which works best for you.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

Viewing 5 posts - 1 through 4 (of 4 total)

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