Foreign Key naming scheme

前端 未结 10 1787
悲&欢浪女
悲&欢浪女 2020-12-12 10:55

I\'m just getting started working with foreign keys for the first time and I\'m wondering if there\'s a standard naming scheme to use for them?

Given these tables:

10条回答
  •  一整个雨季
    2020-12-12 11:38

    Try using upper-cased Version 4 UUID with first octet replaced by FK and '_' (underscore) instead of '-' (dash).

    E.g.

    • FK_4VPO_K4S2_A6M1_RQLEYLT1VQYV
    • FK_1786_45A6_A17C_F158C0FB343E
    • FK_45A5_4CFA_84B0_E18906927B53

    Rationale is the following

    • Strict generation algorithm => uniform names;
    • Key length is less than 30 characters, which is naming length limitation in Oracle (before 12c);
    • If your entity name changes you don't need to rename your FK like in entity-name based approach (if DB supports table rename operator);
    • One would seldom use foreign key constraint's name. E.g. DB tool usually shows what the constraint applies to. No need to be afraid of cryptic look, because you can avoid using it for "decryption".

提交回复
热议问题