简体   繁体   中英

Referential Integrity and Translations

Description

Hi, so I am looking at a legacy database that includes multiple translation tables for existing tables.

So there is a laws table, but then there is also a translation_laws table:

Laws (law_id, inForceDate, type, etc)
Translation_Laws (law_id, lang_code, translation)

There is also a law_type table:

Law_Type (law_type_id, description, isDecreed, etc.)

Translation_Law_Type(law_type_id, lang_code, translation)

So, with the following scheme referential integrity is maintained, but you end up with multiple translations tables.

I would prefer to make one table with the following format:

translations(table_name, id, lang_code, translation)`

This would basically be like bundle, key, lang_code, label . I could also combine bundle+key+lang_code into one varchar key: bundle.key.lang_code .

However, I don't see much of a way to define a relationship in Oracle SQL.

Questions:

  1. Any Ideas how to define a relationship while using Integer IDs??
  2. Would it be so bad to NOT to define a relationship in the database?

    Only solution I can think of would be to try add a String foreign key to every table needing a translation (aaa.bbb.ccc.ddd) that is unique.

Update

Currently I have done away with the official relationships in the DB and made the following type of schema:

  CREATE TABLE TRANSLATIONS(
    DESCRIPTION_ENTITY VARCHAR(30) NOT NULL,
    DESCRIPTION_COLUMN VARCHAR(30) NOT NULL,
    KEY_OR_ID VARCHAR(30) NOT NULL,
    LANG_CODE VARCHAR(2),
    TEXT CLOB,
    -- Legacy are To be able to cross check using columns - but not needed
    LEGACY_TABLE VARCHAR(30) NOT NULL,
    LEGACY_COLUMN VARCHAR(30) NOT NULL);

    ALTER TABLE TRANSLATIONS
      add CONSTRAINT UNIQUE_COMBINATION UNIQUE (DESCRIPTION_ENTITY, DESCRIPTION_COLUMN, KEY_OR_ID, LANG_CODE);

    CREATE INDEX ind_description_entity ON TRANSLATIONS (DESCRIPTION_ENTITY);
    CREATE INDEX ind_description_column ON TRANSLATIONS (DESCRIPTION_COLUMN);
    CREATE INDEX ind_key_or_id ON TRANSLATIONS(KEY_OR_ID);
    CREATE INDEX ind_lang_code ON TRANSLATIONS(LANG_CODE);

    insert into TRANSLATIONS(DESCRIPTION_ENTITY, DESCRIPTION_COLUMN, KEY_OR_ID, LANG_CODE, TEXT, LEGACY_TABLE, LEGACY_COLUMN)
    select 'LAW','TITLE', LAW_CODE, LANG_CODE, LAW_TITLE,
      'LAW_TRANS','TITLE'
    from LAW_TRANS where TITLE is not null;

Personally, I don't think there is anything wrong with not defining a relationship in a DB. At a massive investment bank where I was working before our Oracle specialists NEVER defined the relationships for performance reasons.

The basic question for your setup is, do you need a defined amount of languages or do you have to be flexible with adding languages later? If not, your approach is almost too flexible. Just adding different rows with the translation into the Laws table would be much more performant if you know you only every need 4 different languages.

Alternatively, you could just build a lock-up table:

original-string -> translated-string

And you can ignore the table name completely.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM