给主键"id"命名.对比"something_id"在SQL中 [英] Naming primary keys "id" vs "something_id" in SQL

查看:175
本文介绍了给主键"id"命名.对比"something_id"在SQL中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在具有多个表的数据库中命名主键/唯一键的最佳实践是什么.您应该总是只调用每个表的主键id还是可以在每个表中都没有id字段,而只是将它们分别命名为something1_idsomething2_id等?

I'm wondering what the best practice is for naming primary/unique keys in a database with many tables. Should you always just call each table's primary key id or is ok to not have an id field in each table and just name each of them something1_id, something2_id, etc?

推荐答案

无论您做什么,都要选择一个或另一个并遵守该标准.每种方法都有优点和缺点.

Whatever you do, pick one or the other and stick to that standard. There are pros and cons for each.

我更喜欢SomethingID,但是其他人只喜欢ID.在我使用的系统中,有一千多个表,并且PK和FK具有完全相同的名称,这使事情变得更容易.

I prefer SomethingID but other people prefer just ID. In the system I work with there are well over a thousand tables and having the PK and the FK have the exact same names makes things easier.

这篇关于给主键"id"命名.对比"something_id"在SQL中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆