Database naming rules

Source: Internet
Author: User
Tags naming convention

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 constrained naming

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

e.g.: Ck_tbl_company_comp_zip

9.Default constrained naming

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

e.g.: Df_tbl_news_news_hit

10. Trigger naming

"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)

11. Stored Procedure naming

Naming rules: see Names and know the meaning.

"Prd_" + "description"

Description: Dynamic object structure (verb + noun)

e.g.:p Rd_getproductbyid

12. Naming parameters in stored procedures

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

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.