MySQL 列名标准/约定

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5325520/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 19:07:53  来源:igfitidea点击:

MySQL column name standards / conventions

mysqlnaming-conventions

提问by chubbyk

I'm looking for document (suggestions) with column name standards or conventions for MySQL. Can anybody suggest any?

我正在寻找包含 MySQL 列名标准或约定的文档(建议)。有人可以建议吗?

回答by Brian

There's nothing "standard" in this space I'm aware of, unlike say Sun's old Java conventions. Anything you adopt will be personal/company preference.

我所知道的这个领域没有任何“标准”,这与 Sun 的旧 Java 约定不同。你采用的任何东西都将是个人/公司的偏好。

That said, I do like prefix conventions:

也就是说,我确实喜欢前缀约定:

  • t_ for table
  • v_ for view
  • idx_ for index
  • tx_ for text field
  • dt_ for date field
  • n_ for numeric field
  • id_ for identify field
  • nm_ for something that's specifically a name
  • is_ for booleans, whether 0/1, yes/no or otherwise
  • fk_ as an optional foreign key identifer; you may prefer to stick with id_ though, to keep the field the same as its primary key counterpart, e.g. id_customer -> id_customer, rather than an fk_customer
  • t_ 表
  • v_ 用于查看
  • idx_ 用于索引
  • tx_ 用于文本字段
  • dt_ 用于日期字段
  • n_ 用于数字字段
  • id_ 用于标识字段
  • nm_ 用于特定名称的东西
  • is_ 用于布尔值,无论是 0/1、是/否还是其他
  • fk_ 作为可选的外键标识符;不过,您可能更愿意坚持使用 id_,以保持该字段与其主键副本相同,例如 id_customer -> id_customer,而不是 fk_customer

回答by sreimer

Naming conventions comes into play when using frameworks like Ruby on Rails or Zend that subscribe to convention over configuration. Anything that will scaffold forms for you or "auto discover" your database. Looking at these conventions could also help you decide on a naming strategy even if you are not using a framework.

当使用 Ruby on Rails 或 Zend 等订阅约定优于配置的框架时,命名约定就发挥作用。任何可以为您构建表单或“自动发现”您的数据库的东西。即使您没有使用框架,查看这些约定也可以帮助您决定命名策略。