Sql naming best practice

前端 未结 12 2729
春和景丽
春和景丽 2021-02-14 09:48

I\'m not entirely sure if there\'s a standard in the industry or otherwise, so I\'m asking here.

I\'m naming a Users table, and I\'m not entire

12条回答
  •  情书的邮戳
    2021-02-14 10:17

    It's personal preference. The best advice we can give you is consistency, legibility and ensuring the relationships are correctly named as well.

    Use names that make sense and aren't abbreviated if possible, unless the storage mechanism you are using doesn't work well with them.

    In relationships, I like to use Id on the primary key and [table_name]_Id on the foreign key. eg. Order.Id and OrderItem.OrderId

    Id works well if using a surrogate key as a primary key.

    Also your storage mechanism may or may not be case sensitive, so be sure to that into account.

    Edit: Also, thre is some theory to suggest that table should be name after what a single record in that table should represent. So, table name "User" instead of "Users" - personally the plural makes more sense to me, just keep it consistent.

提交回复
热议问题