Click here to Skip to main content
15,845,742 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All
I have Two Database DB1 Have TBL1, DB2 Have TBL2
and I need a foreign key in the [TBL1] table (which is in DB1 database) is reference to the other table [TBL2] (which is in the DB2 database).

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.
Bala Selvanayagam 15-Jul-12 7:02am    
You can not have cross-database foreign key but can use triggers instead.

Basically, you needs to check the data validation on insertion using trigger and raise an error, if needed

The error message is pretty explicit:
"Cross-database foreign key references are not supported"

So the answer is in the question: "No".
Share this answer
Mustafa Salman 15-Jul-12 4:31am    
I Know that but I Ask for Another Solution
as OG stated, it's not possible

Alternatives are, have the SP you use to manipulate the row make the assertion

or put a trigger in there - I'd go with the first one
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900