mysql schema命名规范_MySQL schema命名规则

本文详细介绍了MySQL数据库的命名规则,包括全小写、使用下划线、避免空格和保留字、使用有意义的前缀等。建议数据库名以项目名+所有者名作为前缀,表名使用部门缩写,列名遵循特定格式,如主键为'表名_id',外键与关联表主键一致。此外,还提到了MySQL的标识符长度限制、唯一性要求以及大小写敏感性等注意事项。

/*****************by

garcon1986************************************************************/

通用规则:

个数据库里的名字都尽量使用小写。这样能消除由于大小写(

case-sensitivity

)带来

的错误。

Mysql

默认区分大小写。

使

用下划线断开名字,名字中不能

使用空格。

名字中尽量不要

使

用数字。

名字中尽量不要

使用"

.",

样能避免在查询时出错

名字中不能使用保留字。

量使名字简单。

数据库名:

般情况下,使用项目名称作为数据库的名字。

数据库名字前加所有者的名字作为前缀。

表名:

以使用缩略词作为前缀

如:"

hr_”, "mkt_”,非别代表了human

resource, marketing部门。

不要使用通用的前缀

如:"

tbl_”,

"db_”,这样

没有实际意义,反而看起来更麻烦。

表名尽量简短,准确。

于表名的单复数,根据个人习惯决定,没有对错

列名:

键一般

是"

表名

_id”。

键的列名和另一个表的主键名一致

如:

create table manager

(manager_id int(11) primary key );

create table employee(

employee_id int(11) primary key,

manager_id int(11),

FOREIGN KEY (manager_id) REFERENCES

manager(manager_id) ON DELETE CASCADE)

名以

3

个字母的表格缩写为前缀

期列以"

date_”

为前缀

Boolean

型列以"

is_”

为前缀

引用:

MySQL database identifiers that can

be named include databases, tables, and columns. The MySQL documentation

contains extensive information about naming conventions. Here are some

of the naming conventions that you must use:

·

All identifier names must be from 1 to 64

characters long, except for aliases, which can be 255 characters long.

·

Database names must be unique. For each user

within a database, names of database objects must be unique across all

users (for example, if a database contains a department table created by

user A, no other user can create a department table in the same

database).

Note:

MySQL does not support schemas. Consequently, tables are automatically

visible to all users who have appropriate privileges. Column names and

index names must be unique within a table.

·

Database names can use any character that is

allowed in a directory name except for periods and backward and forward

slashes.

·

Table names can use any character that is

allowed in a filename except for periods and forward slashes.

·

Column and alias names allow all characters.

·

A name cannot be a MySQL reserved word

unless the name is enclosed in quotation marks. See the MySQL

documentation for more information about reserved words.

·

Embedded spaces and other special characters

are not permitted unless the name is enclosed in quotation marks.

·

Embedded quotation marks are not permitted.

·

Case sensitivity is set when a server is

installed. By default, the names of database objects are case sensitive

on UNIX and not case sensitive on Windows. For example, the names

CUSTOMER and customer are different on a case-sensitive server.

Note: By default, column and

table names are not quoted. If you are using the SAS Table Server

LIBNAME engine, you can quote the table and column names by using the

LIBNAME or data set options PRESERVE_COL_NAMES= and PRESERVE_TAB_NAMES=.

分享到:

18e900b8666ce6f233d25ec02f95ee59.png

72dd548719f0ace4d5f9bca64e1d7715.png

2010-02-12 23:41

浏览 480

评论

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值