SQL Server Foreign Keys across database boundaries - techniques for enforcement -
i have 2 separate sql server 2005 databases (on same server)
- security database
main application database
the security database has user table needed authenticate. -
- the application database has person table extended user details. there 1-1 mapping between security database user table , application database person table.
i want enforce mapping between user , person table. i'm assuming foreign keys can't mapped across databases wondering enforce integrity of relationship.
cross database foreign keys indeed not supported
msg 1763, level 16, state 0, line 2 cross-database foreign key references not supported.
if want enforce referential integrity on database side have rely on triggers. (which don't recommend)
to make code more maintainable create synonyms tables want check referential integrity on.
create synonym mytable otherdatabase.dbo.mytable;
this make "manual" checks easier, can not create foreign keys on synonym.
Comments
Post a Comment