1

Possible Duplicate:
Add Foreign Key relationship between two Databases

What i know is that i can add a foregin key constraint, so that one column in table A can reference to another column in table B using :

CONSTRAINT fk FOREIGN KEY (column) REFERENCES toTable(toColumn)

but here both tables are in the same database. I want to know if i can reference to table in another database. For instance , i have two databases: databaseA and databaseB, when i want to associate them, i prefer adding some table in databaseA reference to another table in databaseB. But i don't know how. Something like :

CONSTRAINT fk FOREIGN KEY (column) REFERENCES [databaseB].[toTable](toColumn)

doesn't work.

Community
  • 1
  • 1
cameron
  • 2,976
  • 3
  • 23
  • 35
  • It is database,not schema. My example may be not accurate,so i have changed them to databaseA and databaseB. – cameron Oct 26 '12 at 02:21
  • Might help, looks horrible though - http://dba010.wordpress.com/2011/01/17/how-to-create-database-link-in-sql-server-2005/ – Phil Oct 26 '12 at 02:25
  • 1
    if your server is `SQL server`, you might want to read this.[Adding Foreign Key Between Two Databases](http://stackoverflow.com/questions/4452132/problem-adding-foreign-key-between-two-databases) – John Woo Oct 26 '12 at 02:31
  • Yes, that is my situation. Thanks for your advice. – cameron Oct 26 '12 at 02:40
  • This is usually a sign that the two databases ought to be merged. Otherwise, taking consistent backups becomes a far larger challenge. – Damien_The_Unbeliever Oct 26 '12 at 07:12

0 Answers0