Summary of database naming rules

Source: Internet
Author: User
Tags types of tables

Database naming rules

1Purpose

Standardizes naming rules for various objects in the database.

2Database naming principles

2.1Data Files

If the database uses a file system instead of a bare device, the following naming rules are agreed:

1) Data Files start with the table space name and end with. dbf. All data files are named with lowercase English letters and numbers. If the tablespace contains multiple data files, add _ after the tablespace name starting from 2nd data files _.

For example, the system tablespace data files: system. dbf, system_2.dbf

2) control files of oracle databases are represented by control. ctl. For example, control01.ctl and control02.ctl.

3) for oracle database log files, the online log files are represented by redo <Group Name> <file sequence Name>. dbf. The group name and file sequence name are both represented by two digits. For example, the two files in the first group represent redo0101.dbf and redo0102.dbf. Archive logs are represented by arch _ % t _ % s. arc. Both % t and % s are oracle-Defined variables.

2.2Tablespace

2.2.1Database System tablespace

The database system tablespace includes the system tablespace, temporary tablespace, and rollback segment tablespace. Specify the following naming rules:

1) The system tablespace is directly limited by the database and cannot be modified.

2) Temporary tablespace is represented by temp. If there are multiple temporary tablespaces, which start with 2nd temporary tablespaces, are added after temp.

3) The tablespace In the rollback segment is represented by undotbs. If there are more than one tablespace In the rollback segment, the table space starts from the first tablespace In the rollback segment and is added after undotbs.

2.2.2User tablespace of the database

The user tablespace of the database is represented by ts _ <tablespace Name>. Table space names are divided:

1) Data Space: The default tablespace is represented by default. For other tablespaces, they are represented based on the types of tables stored in the tablespaces. For example, the code table is represented by code. The table for storing customer data is represented by customer. Try to use a tablespace to store tables of this type. If a table is very large, you can use a single tablespace.

2) index space: Add ind _ before the name of the corresponding data table space _. For example, the index space of the user's default tablespace is represented by ts_ind_default. The index tablespace of the code table is represented by ts_ind_code.

2.3Table

The naming rules for database tables are as follows:

1) The table name starts with T _. The table name cannot exceed 30 characters. The table name contains all words in the singular format, and the words must be capitalized.

2) Multiple words are connected by underscores. If there are multiple systems in the database, the table name is system name + word or multiple words. The system name is short for the development system, such as VNET.

3) We recommend that you use the complete words in the table. If the table name contains more than 30 characters, the abbreviation of the word is used forward from the last word. (If there is no contract abbreviation, it is represented by the first four letters of the word ).

The following rules are used to name fields in a database table:

1) All database Field Names use lower-case English words, separated. The field length cannot exceed 30 characters.

2) If the field is code, add _ id after the word.

3) If this field represents time, _ time is used as the suffix.

2.4View

Database view naming rules are as follows:

1) The view name starts with V _. The view name cannot exceed 30 characters. View names are expressed in uppercase.

2) When a view is generated from several tables, it uses an underscore (_) to connect the names of several tables. If there are too many tables, you can simplify the table name, but make sure to list all the table names.

2.5Sequence

Database sequence naming rules are as follows:

The sequence name starts with seq _, followed by the field name of the sequence. If several fields use the same sequence, use an underscore (_) to join the names of several fields. If different tables use different sequences for the same field names, add the table features after the field names and connect them with underscores. The sequence Name Length cannot exceed 30 characters. The sequence name is represented by lowercase English words.

2.6Stored Procedure

The naming rules for stored procedures are as follows:

The stored procedure name starts with Pr _. The length of the stored procedure name cannot exceed 30 characters. The stored procedure name is expressed in lowercase.

2.7Function

The function naming rules are as follows:

The function name starts with Fu _. The function name cannot exceed 30 characters. The function name is represented by lowercase English words.

2.8Trigger

The trigger naming rules are as follows:

The trigger name starts with Tr _. The trigger name cannot exceed 30 characters. The trigger name is represented by lowercase English words.

2.9Primary Key

The primary key naming rules are as follows:

The primary key name starts with pk _, followed by the table name where the primary key is located. The primary key name cannot exceed 30 characters. If it is too long, you can abbreviated the table name. The abbreviation rule is the same as the abbreviation rule of the table name. The primary key name is represented by lowercase English words.

2.10Foreign key

The naming rules for foreign keys are as follows:

The foreign key name starts with fk _, followed by the table name of the foreign key and the corresponding primary table name (excluding t _). The sub-table name and parent table name are separated by underscores. The length of the foreign key name cannot exceed 30 characters. If it is too long, you can abbreviated the table name. The abbreviation rule is the same as the abbreviation rule of the table name. The foreign key name is represented by lowercase English words.

2.11Index

The index naming rules are as follows:

1) The index name is represented by lowercase English letters and numbers. The index name cannot exceed 30 characters.

2) The index corresponding to the primary key has the same name as the primary key.

3) Each type of index ends.

4) The unique index starts with uni _, followed by the table name. The general index starts with ind _, followed by the table name.

5) if the index length is too long, you can abbreviation the table name. The abbreviation rule is the same as the abbreviation rule of the table name.

Related Article

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.