question

chana avatar image
chana asked

can a primary Key and foreign key relation be created between 2 different databases

can a primary Key and foreign key relation be created between 2 different databsaases
primary-keyforeign-keyrelationshipscross-database
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Cyborg avatar image
Cyborg answered
No! you can't create a foreign key relation between two databases. A foreign key is a relationship or link between two tables which ensures that the data stored in a database is consistent.
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Kev Riley avatar image
Kev Riley answered
No - cross database foreign keys are not supported in SQL Server. MS recommends the use of triggers to implement this functionality. [MSDN][1] : > FOREIGN KEY constraints can reference only tables within the same database on the same server. Cross-database referential integrity must be implemented through triggers. [1]: http://msdn.microsoft.com/en-us/library/ms174979(v=SQL.90).aspx
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.