Friday, March 9, 2012

Remote Foreign keys.. What should I do?

Right now i'm building a language centre DB. Is going to hold translations for data in tables in another DB (english DB). The idea is going to be that there is going to be a table in the Language DB for every language and table it is going to translate in the english DB.

So lets consider the following in the English DB:

PROJ_TBL_HELPTOPICS

-> PK_HELP_ID

-> TITLE

-> DESCR

PROJ_TBL_CATEGORIES

-> PK_CAT_ID

-> TITLE

-> DESCR

In the Language DB I want to hold translations for HELPPTOPICS and CATEGORIES, and I want translations for Spanish and Japanese.

PROJ_TBL_HELPTOPICS_ES

-> PK_TRANS_ID

-> FK_HELP_ID

-> TRANS_TITLE

-> TRANS_DESCR

The rest is going to be the layout as above

PROJ_TBL_HELPTOPICS_JA

PROJ_TBL_CATEGORIES_ES

PROJ_TBL_CATEGORIES_JA

The reasons I separated up the language DB from the english DB are:

1. English DB has, and is going to have a lot more tables, and is going to be heavily queried (plus I think dont think the translations are going to be used anywhere near as often and the english). I figured the less tables, where possible, the better.

2. Putting translations in different a different DB, I could take better advantage of colliations specific to a language for example when using Full-Text searching on Japanese text

Anyways, here's my question!?!

I want to link the foreign key column to the table it is translating primary key column (in the English DB). I want to be able to take advantage of Cascade on Delete. So when an item is deleted from EnglishDB.PROJ_HELP_TOPICS it is going to be deleted from LanguageDB.PROJ_HELP_TOPICS_[LANG ISO]. Is this done through Mirroring?

Mirroring is a high-availability feature, it is not the solution you are looking for.

Quote from BOL "FOREIGN KEY constraints can reference only tables within the same database on the same server. Cross-database referential integrity must be implemented through triggers.FOREIGN KEY constraints can reference only tables within the same database on the same server. Cross-database referential integrity must be implemented through triggers."

I'm not sure but if they are different servers or instances you may be able to create a linked server and then create triggers to maintain the integrity.

No comments:

Post a Comment