Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Foreign key relation ship between two databases in SQL Server 2008

I have two databases, is it possible to create a foreign key between two tables in different databases in SQL Server 2008?

thanks

like image 655
G.S Bhangal Avatar asked Nov 21 '11 07:11

G.S Bhangal


2 Answers

From Books Online:

A FOREIGN KEY constraint can reference columns in tables in the same database or within the same table.

So, you can not create foreign key constraints between two tables in different databases.

This is one of disadvantages of using multiple databases.

like image 134
Igor Borisenko Avatar answered Sep 19 '22 13:09

Igor Borisenko


If you are using Linq2Sql or the entity framework - You can do it in the designer.

But as Igor say - in the DB itself you cant do it.

like image 21
Yacov Avatar answered Sep 21 '22 13:09

Yacov