zoukankan      html  css  js  c++  java
  • 数据库对象命名规范

     

     译自:http://weblogs.asp.net/jamauss/articles/DatabaseNamingConventions.aspx

    通用规则:

    命名长度不超过30个字符

    使用字母和下划线 (避免使用数字)

    尽量少用下划线.

    以字母开头. (不要以下划线开头)

    避免简写 (减少歧义或误解)

    避免缩写 (缩写可能造成多义性 比如 "ASP")

    见名知意

    避免使用空格.

    1. 表 

    规则 1a (Plural Names) – 复数形式。使用 "Customers" ,不用 "Customer". 比如:"UserRoles" "UserRoleSettings".

    规则 1b (Prefixes) – 不要使用前缀 "tbl" or "TBL_" 。有时可用前缀对表进行分组.例如, "HcPayClients" ,不要使用"PayHcClients".

    规则 1c (Notation) -  使用 Pascal Case 命名方式. 这样可以与SQL关键词区分开, "SELECT CustomerId_Pk, CustomerName FROM MyAppGroupTable"

    规则 1d (Special Characters) – 不要使用任何特殊字符.

    规则 1e (Abbreviations) – 尽量不要使用缩写和简写.

    规则 1f (Junction a.k.a Intersection Tables) – 关联表,比如 "Doctors" "Patients" 有多对多的关系,取名为“DoctorsPatients".

    2. 列 - (incl. PRIMARY, FOREIGN, AND COMPOSITE KEYS)

    使用 Pascal Case 命名方式.  

    规则 2a (Identity Primary Key Fields) – 主键列使用 “Id“ 比如   "Customers JOIN Orders ON Customer.Id = Orders.CustomerId“

    规则 2b (Foreign Key Fields) –比如主表有主键为 "Id". 在外键表中取名 "CustomerId".  比如: HomeAddressId, WorkAddressId, MailingAddressId, ShippingAddressId.

    规则 2c (Composite Keys) – 多个列组成主键. 比如 “ModuleId“ “CodeId“ 组成主键.

    规则 2d (Prefixes) –不要使用前缀 "fld_" or "Col_".

    规则 2e (Data Type Specific Naming) – Boolean类型字段应取名为 "IsDeleted", "HasPermission", or "IsValid". 日期时间类型字段应包含 "Date" or "Time" ,数量单位字段,比如 "RuntimeHours" or "ScheduledMinutes".

    3. 索引

    规则 3a (Naming Convention) – 命名格式   {TableName}{ColumnsIndexed}{U/N}{C/N} "U/N" 表示唯一或非唯一索引 and "C/N" 表示族和非族. 比如. "ProductsIdUC".  “OrderDetailsOrderIdCustomerIdNN".

    规则 3b (Prefixes and Suffixes) – 避免使用前缀 "idx" or "IDX_".

    4. 约束

     规则 4a (Naming Convention) – 格式如下:     {constraint type}{table name}_{field name}

          比如:

          1. PkProducts_Id - primary key constraint on the Id field of the Products table

          2. FkOrders_ProductId    - foreign key constraint on the ProductId field in the Orders table

          3. CkCustomers_AccountRepId - check constraint on the AccountRepId field in the Customers table

     规则 4b(Prefixes)  前缀如下

         Primary Key: Pk

         Foreign Key: Fk

         Check: Ck

         Unique: Un

    5. 视图

    规则 5a (Prefixes) – 使用前缀 "Vw" or "View" ,不使用 "V".

    规则 5b (View Types) -. 连接表 "Customers" "StatesAndProvinces"的视图取名为 "VwCustomersStatesAndProvinces"..

    6. 存储过程 

    规则 6a (Prefixes or Suffixes) – 使用CRUD 分组, 使用前缀 "Create", "Get", "Update" or "Delete". 比如 "CreateProductInfo" or "CreateOrder".

    或者,使用表分组,添加 "Create, Get, Update, or Delete" 后缀. 比如, "ProductInfoCreate" or "OrdersCreate".

    其他验证或操作,使用动词和名词结合的方式,比如, "ValidateLogin"

    规则 6b (Grouping Prefixes) – 可以使用前对对SP进行分组,比如 "Prl"—Payroll  "Hr" -- Human Resources.

    规则 6c (Bad Prefixes) – 不要使用前缀 "sp_", "xp_" or "dt_".

    7. 触发器

    规则 7a (Prefixes and Suffixes) – 使用 "Trg" 做前缀或者后缀. 比如: Trg_ProductsIns, ProductsInsTrg, Products_InsTrg, or InsProducts_Trg. 要包含表名, 以及触发器的操作 (Ins, Upd, or Del).

    规则 7b (Multiple Operations) – 如果一个触发器有多个操作 (both INSERT and UPDATE for example) 要包含多个操作比如, "Products_InsUpdTrg" or "TrgProducts_UpdDel"

    download: template_sqlserver_naming_guideline.rar 

  • 相关阅读:
    Linux系统下ZIP文件解压和压缩命令
    解析XML文件
    数组和集合之间的转换
    数据库密码到期修改密码
    Linux系统中启动jar程序
    JSONArray依赖包
    多态性
    接口----interface
    抽象类
    final关键字
  • 原文地址:https://www.cnblogs.com/emanlee/p/1513539.html
Copyright © 2011-2022 走看看