Database naming rules

Source: Internet
Author: User
Tags naming convention one table

A Database:

1. Basic naming rules

Table 1. Base Database object naming

Database objects

Prefix

Tables (table)

Field (Column)

Views (view)

Stored Procedures (Stored procedure)

Trigger (Trigger)

Indexing (Index)

Primary KEY (Primary key)

Foreign key (Foreign key)

Check constraint (check Constraint)

Default constraint (default Constraint)

User-defined data type (user-defined)

User-defined functions (user-defined function)

Tbl_

No

Viw_

Prd_

Trg_

Idx_

Pk_

Fk_

Ck_

Df_

Udt_

Fun_

2. about the naming convention

Variables (variables declared in T-SQL Programming), procedures (stored procedures or triggers, etc.), entities (tables, fields) should be named according to the entity meaning and process action they represent:

Table 2. Good naming and bad naming examples

A good name

Bad naming.

@CurrentDate

@ActivityCount

@EquipmentType

Prcalculatetotalprice

@D

@ActNum

@ET

@prRunCalc

A. Verb form: Verbs put in front, nouns put back. Eg:prd_getproductbyid

B. Do not use computer terminology, as far as possible to use the company business-oriented operation.

C. Using abbreviations

Depending on the requirements of the previous article, the process name based on the business description may become lengthy, such as the following:

Prcounttotalamountofmonthlypayments (calculates the total amount per month paid)

Prgetparentorganizationalunitname (get parent organization name)

Ø If you can find the abbreviation of a word in the dictionary, use this as an abbreviation, for example: Mon (Monday), Dec (December)

Ø You can delete the word vowel (except for the first letter of the word) and repeat the letter for each word to abbreviate a word. For example: current = crnt, Address = Adr, Error = Err, Average = AVG

Ø do not use a conflicting abbreviation (usually a phonetic ambiguity). such as B4 (before), XQT (execute), 4tran (Fortran)

3. Database naming

Named according to the actual meaning of the project

4. Table naming

"Tbl_" + name (name as much as possible with English words, capitalized in the first letter of each word)

5. field naming

Table name (minus prefix) abbreviation + "_" + attribute name (first letter of each word capitalized)

Abbreviation: Wubi Chaizi method to take the letter

One word: Take the first four letters

Two words: Take the first two letters of each word

Three words: Take the first two words and the last two letters of the third word.

Four or more than four: take the first letter of the first three words and the first letter of the last word.

6. naming the primary key

The primary key is for a table, not for a field, because the primary key is unique, and a table can have only one primary key.

A. General primary key naming: The name of the primary key is Pk_tablename.

B. Composite primary key: "Pk_" + "field name"

e.g.: Constraint pk_studentcourse Primary key (stud_id, cour_id)

Primary key Pk_studentcourse, contains two fields stud_id and cour_id

7. foreign key naming

The name of the foreign key is the name of the table named Fk_ foreign key, which is referenced by the foreign key. Because the foreign key is the table from which the table is located, the above can be written as fk_ from the table name _ the primary table name.

8.Check constraint naming

"Ck_" + "Table name" "_" + "Field name"

e.g.: Ck_tbl_company_comp_zip

9.Default constraint naming

"Df_" + "Table name" "_" + "Field name"

e.g.: Df_tbl_news_news_hit

name of Trigger

"Trg_" + "table name" + "suffix"

A. Prefix-"Trg_", which describes the type of database object.

B. Basic section, which describes the tables added by the trigger.

C. Suffixes (_i, _u, _d), showing modification statements (Insert, update, and delete)

One . stored procedure naming

Naming rules: see Names and know the meaning.

"Prd_" + "description"

Description: Dynamic object structure (verb + noun)

e.g.:p Rd_getproductbyid

Naming the parameters in a stored procedure

The first word is lowercase, with the same field name as the corresponding one.

Two. Program Design

Microsoft 3.0 documentation is the main

1. Project name

"Company Name" + "project actual meaning name"

E.g.:qikingyellowpage

2. page Naming

Rule: Capitalize the first letter of each word because it is a class.

A. Parent page--using nouns to describe

B. Sub-page _ List--"list" + "Parent page"

C. Sub-page _ details--"Show" + "Parent page"

3 Page Pass Value

"Id_" + "page name"

4. error page naming

Error.aspx

5. User Login

Userlogin.aspx

6. folder naming

Capitalize the first letter of the word

Singular or plural, depending on actual needs.

Note: Some of these refer to Zhang Ziyang's database object naming reference Second Edition http://www.cnblogs.com/JimmyZhang/archive/2007/08/30/875504.html

According to the habits of individuals added, modified some.

One's life should be spent like this: when he looks back on the past, not because of wasting time and remorse, nor because of mediocrity and shame.1 Overview

The purpose of writing this database naming convention is to provide a more image, easy-to-read, straightforward, principled and consistent database naming method. This makes it easy for project-related people to understand the meaning of all objects in the database, so that they can communicate with each other.

Here is a description of the following 7 common types of database objects:

1. Tables (table)

2. Field (Fields)

3. View (views)

4. Stored Procedures (Stored procedures)

5. Index (Indexes)

6. Association (Relationships)

7. Trigger (Trigger)

This section describes the general rules for database naming conventions.

1.1 Character Set fit

1. 26 Lowercase letters (A-z)

2. 26 Capital letters (A-z)

3. 10 numeric characters (0-9)

4. Underline (_)

1.2 database Objects

The name of the object consists of a prefix and an actual name, with an underscore between the prefix and the actual name.

Note: do not place spaces between the characters of the object name, not more than 30 characters in length.

[Object name ]= [prefix ] _ [actual name ]

prefix abbreviation rules: use lowercase letters, for different database objects, the following table specification is named.

Object

Prefix

Table

Tb

View

Vi

Index

Idx

Association

Rl

Stored Procedures

Sp

Function

Fn

Trigger

Tr

actual name: try to describe the content of the entity, consisting of a word or a combination of words. write in Camel rule, that is, the first letter is lowercase and the first letter of each word is capitalized.

Note: do not start with numbers and underscores, and do not separate the words with underscores. Also avoid using reserved keywords and Chinese pinyin, for example:ui_pk_userid,ui_firstname, Ui_lastname, and tb_userinfo

1.3 SQL Statement writing rules

All reserved keywords in an SQL statement are written in uppercase letters.

This section describes in detail the naming conventions for database objects that may be involved in an ITSM system.

1.1 Table Naming conventions

[Table name ]=tb_[actual name ]

For a table, the following rules are:

1. Use the prefix TB;

2. Use as few complex numbers as possible in the table name;

3. Do not use underscores in the actual name section;

4. The actual name part avoids the abbreviation as far as possible, can clearly indicate its meaning except, for example:tb_userinfo;

In addition, for tables that get data synchronously from other databases, in addition to the naming conventions above, underline the [actual name ] and add the [database name of the data source ].

such as:Tb_assetinfo_croom, indicates that the asset information table originates from the croom database.

1.2 Field naming conventions

[Field name ]=[table name shorthand ]_[field actual name] [field data type abbreviation ]

The abbreviated part of the table name, consisting of the lowercase initials of each word in the actual name part of the table name.

1. If the field is the primary key:[Field actual name ]=pk+_+[actual name ];

2. If the field is a foreign key:[Field actual name ]=fk+_+[actual name ];

3. If the field is a key combination:[field actual name ]=ck+_+[actual name ];

such as:Ui_pk_userid, ui_lastname.

In addition, for fields where the data originates from other databases, underline the last field naming specification above, and then add the [database name of the data source ].

For example:ai_assetname_croom, indicates that the asset name field originates from the croom database.

Note: If you appear in more than one table with similar or identical fields, the fields must have the same field properties. such as:text type, with the same maximum length setting.

[View name ]=vi_[actual name ]

1. Use vi as the prefix;

2. The actual name as far as possible to reflect the function of the view, and underline the list of all related table names;

3. Other naming requirements are consistent with the naming requirements of the table;

1.1 Stored Procedure naming conventions

[Stored procedure name ]=sp_[actual name ]

1. Use sp as prefix;

2. The actual name should reflect the operation of this stored procedure (Update,Delete, Insert into,etc.);

3. For a stored procedure, the actual name consists of an operation and a table name;

such as:Sp_updateuserinfo.

1.2 Index naming conventions

[Index name ]=idx[0-9]_[table name abbreviated ]_[actual name ]

1. Use idx as a prefix;

2. [0-9] A plurality of indexes used to differentiate tables;

3. [actual name ] refers to the relevant field or index meaning;

such as:idx0_ui_firstname.

1.3 Association Naming conventions

[Close joint ]=rl_[Main Table name abbreviated ]_[from the table name abbreviated ]

Association relationships refer to foreign key relationships between database tables.

such as:rl_logininfo_userinfo

1.4 trigger naming specification

[Trigger name ]=tr_[actual name ]

1. Use tr as a prefix;

2. The actual name of the action to describe the trigger (Insert,update, etc.);

3. For a trigger, the actual name is composed of the operation and the corresponding table name;

1.5 function Naming conventions

[function name ]=fn_[actual name ]

1. Use fn as the prefix;

2. The actual name describes the function of the specific behavior (get,set, etc.), to see the name interpretation;

Database naming rules

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.