SQL Microsoft 的数据库命名约定?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3593582/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Database Naming Conventions by Microsoft?
提问by Cheung
I found Naming Guidelinesfrom MSDN, but is it any guideline for MSSQL database from Microsoft?
我从 MSDN找到了命名指南,但它是 Microsoft 的 MSSQL 数据库指南吗?
回答by 8kb
The naming conventions used in SQL Server's AdventureWorksdatabase demonstrate many best practices in terms of style.
SQL Server 的AdventureWorks数据库中使用的命名约定展示了许多风格方面的最佳实践。
To summarize:
总结一下:
- Object names are easily understood
- Table names are not pluralized ("User" table not "Users")
- Abbreviations are few, but allowed (i.e. Qty, Amt, etc.)
- PascalCase used exclusively with the exception of certain column names (i.e. rowguid)
- No underscores
- Certain keywords are allowed (i.e. Name)
- Stored procedures are prefaced with "usp"
- Functions are prefaced with "ufn"
- 对象名称易于理解
- 表名不是复数形式(“用户”表不是“用户”)
- 缩写很少,但允许(即数量、金额等)
- PascalCase 专门用于某些列名(即 rowguid)的例外
- 没有下划线
- 允许使用某些关键字(即名称)
- 存储过程以“usp”开头
- 函数以“ufn”开头
You can find more details here:
您可以在此处找到更多详细信息:
One caveat: database naming conventions can be very controversial and most database developers I've met have a personal stake in their style. I've heard heated arguments over whether a table should be named "OrderHeader" or "OrderHeaders."
一个警告:数据库命名约定可能非常有争议,我遇到的大多数数据库开发人员都对他们的风格有个人兴趣。我听说过关于表应该命名为“OrderHeader”还是“OrderHeaders”的激烈争论。
回答by OMG Ponies
No, there isn't but the practices in the link you provided are good to keep in mind.
不,没有,但您提供的链接中的做法值得牢记。
With respect to naming stored procedures - do notprefix them with "sp_" You can read more about why in this link:
关于命名存储过程 - 不要在它们前面加上“sp_”你可以在这个链接中阅读更多关于为什么的信息:
"Do not prefix stored procedures with sp_, because this prefix is reserved for identifying system-stored procedures."
“不要用 sp_ 作为存储过程的前缀,因为这个前缀是为标识系统存储过程保留的。”
回答by onedaywhen
I don't know what "best practices in terms of style" in the answer by @8kb (at the time of writing) means. Certainly some of the listed items ("Table names are not pluralized", "No underscores", etc) are mere style choices which are obviously subjective. I would have thought the personal preferences of the documentation team lead would be the greatest factor here.
我不知道@8kb(在撰写本文时)的答案中的“风格方面的最佳实践”是什么意思。当然,列出的一些项目(“表名不是复数”、“没有下划线”等)仅仅是明显主观的风格选择。我原以为文档团队负责人的个人偏好将是这里的最大因素。
As regards heuristics in SQL in general (as opposed to proprietary SQL such as T-SQL), there is but one book on the subject: Joe Celko's SQL programming style.Many of the choices for SQL Server's AdventureWorks database conflict with Celko's guidelines.
关于一般 SQL 中的启发式(相对于专有 SQL,如 T-SQL),只有一本关于该主题的书:Joe Celko 的 SQL 编程风格。SQL Server AdventureWorks 数据库的许多选择与 Celko 的指导方针相冲突。
Celko's naming convention is based on on the international standard ISO 11179e.g. specifies that a delimiting character (such as an underscore) should be used to separate elements in a name. Other style choices are similarly backup up by research e.g. using exclusively lower case letters for column names so aid scanning by the human eye. No doubt there are subjective personal preferences in there too but they are based on many years of experiences out in the field.
Celko 的命名约定基于国际标准ISO 11179,例如指定应该使用定界字符(例如下划线)来分隔名称中的元素。其他样式的选择也类似地通过研究备份,例如,列名只使用小写字母,以帮助人眼扫描。毫无疑问,其中也存在主观的个人偏好,但它们是基于多年在该领域的经验。
On the plus side, things have improved in the SQL Server docs in recent years e.g. SQL keywords capitalized, semi-colons to separate statements, etc. Adventure works is a vast improvement on Northwind and pubs. Now why can't the scripting feature in Management Studio spit out code that is a little easier on the eye?!
从好的方面来说,近年来 SQL Server 文档中的情况有所改善,例如 SQL 关键字大写,分号分隔语句等。 Adventureworks 是 Northwind 和 pubs 的巨大改进。现在为什么Management Studio 中的脚本功能不能吐出看起来更容易一点的代码?!
回答by datalifenyc
If you were to build a SQL Server naming conventions guide, I recommend starting with Konstantin's document on GitHub.
如果您要构建 SQL Server 命名约定指南,我建议您从GitHub 上的 Konstantin 文档开始。