Foreign Key naming scheme

前端 未结 10 1815
悲&欢浪女
悲&欢浪女 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:21

    A note from Microsoft concerning SQL Server:

    A FOREIGN KEY constraint does not have to be linked only to a PRIMARY KEY constraint in another table; it can also be defined to reference the columns of a UNIQUE constraint in another table.

    so, I'll use terms describing dependency instead of the conventional primary/foreign relationship terms.

    When referencing the PRIMARY KEY of the independent (parent) table by the similarly named column(s) in the dependent (child) table, I omit the column name(s):

    FK_ChildTable_ParentTable
    

    When referencing other columns, or the column names vary between the two tables, or just to be explicit:

    FK_ChildTable_childColumn_ParentTable_parentColumn
    

提交回复
热议问题