微软数据库命名规范
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Database Naming Conventions Version 1.1
数据库命名协议版本1.1
野人翻译2008年3月16日
The main goal of adopting a naming convention for database objects is so that you and others can easily identify the type and purpose of all objects contained in the database.
为数据库对象编写命名协议的目的,就是能够轻松的定义数据库中全部对象。
The information presented here serves as a guide for you to follow when naming your database objects. 这里提到的内容可以作为数据库对象命名的指导。
When reading these rules and guidelines remember that consistent naming can be the most important rule to follow.
当阅读此文涉及的规范和原则时,请牢记始终规范的命名方法是数据库设计的最重要原则。
Keep in mind that following the guidelines as outlined in this document can still produce long and cryptic names, ultimately, your unique situation will dictate the reasonability of your naming convention.
请注意根据此协议的原则做出的数据库对象的命名相对较长并具有相关的意义,具体命名需要依照你个人及开发环境的情况。
The goal of this particular naming convention is to produce practical, legible, concise, unambiguous and consistent names for your database objects.
此命名协议的制定目的,是提供较为形象、易读、简单、明确和原则性一致的数据库命名方法。
While most databases contain more types of objects than those discussed here (User Defined Types, Functions, Queries, etc.), the 7 types of objects mentioned here are common among all major database systems. Think of this as a generic DBMS-neutral guide for naming your objects.
当然,数据库涉及到的对象比这里讨论的更多(例如用户自定义的、函数、查询等),这里提到的7种对象涵盖了大多数数据库系统
的内容。所以请将此协议作为“中性数据库”的命名指导。
The following types of database objects are discussed here:
这里讨论下列数据库对象:
1.Tables表
2.Columns (incl. Primary, Foreign and Composite Keys) 列(包括主键、外键和复合键)
3.Indexes索引
4.Constraints参数
5.Views视图
6.Stored Procedures存储过程
7.Triggers触发器
ALL DATABASE OBJECTS
全部数据库对象命名的统一规则
∙Limit the name to 30 characters (shorter is better) 限制名称在30个字母以内(越短越好)
∙Use only letters or underscores (try to avoid numbers) 仅仅使用字母和下划线(尽量避免数字命名)
∙Try to use underscore characters as little as possible. 尽量减少使用下划线PascalCase notation achieves the same word separation without them. PascalCase标记法可以做到在不使用下划线的情况下分割单词
∙Use a letter as the first character of the name. (don't start names with underscores) 不要以下划线作为名称的字母
∙Avoid abbreviations (can lead to misinterpretation of names) 避免使用所写(可能引起误解)
∙Avoid acronyms (some acronyms have more than one meaning eg. "ASP") 避免使用缩写(因为一些缩写例如ASP,有特定意义和用途)
∙Makes the name readable (they shouldn't sound funny when read aloud) 确保名称可朗读
∙Avoid using spaces in names even if the system allows it. 无论是否系统允许都避免使用空格
1. TABLES表
When naming your database tables, give consideration to other steps in the development process.
当为你的表命名时,请同时考虑到后续开发的各个环节。
Keep in mind you will most likely have to utilize the names you give your tables several times as part of other objects, for example, procedures, triggers or views may all contain references to the table name.
请记住你很有可能在后续开发其他对象,如存储过程、触发器或者视图时多次用到你所命名的表的名称,并作为相关参数使用。
You want to keep the name as simple and short as possible.
所以尽量使用简单短小的单词。
Some systems enforce character limits on object names also.
甚至一些系统强制限制对象名称的单词长度。
For example, in Oracle you are limited to about 30 characters per object.
例如Oracle限制名称长度为30字母以内。
Rule 1a(Plural Names复数原则)- Table names should be plural, for example, "Customers" instead of "Customer".
原则 1(复数原则)- 表的名称应该为复数,例如,"Customers" 而不是 "Customer".
This rule is applicable because tables are logical collections of one or more entities as records - just like collection classes are logical collections of one or more objects.
因为表包含了很多数量的实体记录。
If you were to first draw an abstract data model like a NIAM/ORM model, you might have singular entity names like "Customer" or "User" but, they should be changed to the plural form when building the actual tables.
尽管当你在建立数据库NIAM/ORM模型时,可能使用单数形式表示实例,但是当建立具象事物表时,要使用复数名称。
For table names with multiple words, only the last word should be plural, for example, "UserRoles" and "UserRoleSettings".
当由词组命名时,将最后一个单词变为复数。
[译者按:复数命名法一般情况下不可取,在长度,表述方面不佳,作者本身也承认使用复数命名的情况较少]
Rule 1b (Prefixes前缀) - Used correctly, table prefixes can help you organize your tables into related groups or distinguish them from other unrelated tables.
原则 2(前缀)-正确的使用前缀能够帮助你识别表所处的分组或者和其他的表容易区分。
Used poorly, they can cause you to have to type a lot of unnecessary characters.
使用前缀是避免使用复杂修饰、限制性词汇辅助命名的好方法。
We'll discuss what not to do first.
首先我们讨论被禁止的做法。
Do not give your table names prefixes like "tbl" or "TBL_" as these are just redundant and unnecessary. 不要使用"tbl”或者"TBL",因为这种方法多余且不必须。
It will be obvious which names are the table names in SQL statements because they will always be proceeded by the FROM clause of the SELECT statement.
因为在选择查询语句中表名紧跟在FROM的后面。
Not all prefixes are bad.
不是所有的前缀都不可取。
In some cases, your tables might be sharing a schema/database with other tables that are not related in any way.
在某些情况下,表可能被一些数据库共享引用,但是此表与其它的表没有任何关系。
In this case, it is sometimes a good idea to prefix your table names with some characters that group your tables together.
这时,前缀可以将同类的表分组。
For example, for a healthcare application you might give your tables an "Hc" prefix so that all of the