Foreign Key naming scheme

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

    This is probably over-kill, but it works for me. It helps me a great deal when I am dealing with VLDBs especially. I use the following:

    CONSTRAINT [FK_ChildTableName_ChildColName_ParentTableName_PrimaryKeyColName]
    

    Of course if for some reason you are not referencing a primary key you must be referencing a column contained in a unique constraint, in this case:

    CONSTRAINT [FK_ChildTableName_ChildColumnName_ParentTableName_ColumnInUniqueConstaintName]
    

    Can it be long, yes. Has it helped keep info clear for reports, or gotten me a quick jump on that the potential issue is during a prod-alert 100% would love to know peoples thoughts on this naming convention.

提交回复
热议问题