Sqlserver naming rules under. net

Source: Internet
Author: User

 

Standardization has always been a very important interface in the development of the team, and the naming convention is indeed an extremely important part of the specification. We will continue to introduce the encoding specification in the future, control naming rules and other rules on the UI Layer. Here, we will briefly describe the naming rules for sqlserver under. net. Of course, most of them are applicable to other platforms and other types of databases.

Currently, there are two methods to evaluate database naming rules: prefix and non-prefix.

The prefix is always used. For example, the abbreviation of the table module represented by three letters is used as the table prefix before the table name, for example, the user table in the system module: sys_user; before a field name, the table prefix abbreviation represented by three letters is generally used as the field prefix. For more information, see database naming rules. The prefix naming rules mainly consider the clarity between modules and the clearer prefix relationship between tables and Foreign keys. There are also many such standards on the Internet. However, in this way, when a common code generator (not self-written) is used to generate a data access layer class, the prefix cannot be well processed, and the generated class is not standardized. If you use a self-developed code generator to generate code classes, the prefix method is very good. It can distinguish the code of each module and use the table prefix method. However, limited by your own capabilities, you cannot develop such as mysoft. data, nbear, subsonic, and other excellent database access layers. Therefore, this naming method is temporarily abandoned. Another naming method is not to use the table prefix. This kind of naming convention is also available on the Internet, which is very consistent with your own summary. For more information, see the SQL Server naming convention under C. the following describes the naming rules in this mode.

 

I. General rules
1. Various naming rules must be strictly named by Pascal. Considering that not all generation tools can recognize separators to generate classes and fields named by Pascal, the use of connectors is canceled. However, the table name still uses the system module as the prefix, so that the table name can be referenced intelligently.

2. All SQL keywords are capitalized.
3. All Tables and fields should be expressed using the complete word stock phrase as much as possible. If the length exceeds the allowed length, the exception is returned.

4. If all meaningful abbreviations are in uppercase, for example, the primary key uses ID and the stored procedure name is SP _ TABLE name_method.

 

Ii. Database naming

1. It is composed of one or three English words, in Pascal mode, such as departmentmanage.

 

Iii. Table naming
1. each table must have a module prefix to which the table belongs. This prefix is defined in the module design. The module prefix and table name are connected by an underscore (table prefix and underline are used, it is convenient to use IDE Intelligent reference during encoding. For example, system_role indicates the role table of the system module.

2. The table name is displayed in the singular form.

3. If a table needs to be expressed using multiple words, follow the Pascal naming rules for each word, such as system_logconfig.
4. The name of the joined table is named by the name combination of the joined table. For example, system_rolemoduleaction indicates the role module operation table under the system module.
5. each table has four agreed fields (createdon, createdby, modifiedon, and modifiedby). If you use logical deletion, use the isdeleted field, which generally includes whether to enable (isenabled) and sorting field (SNO)

 

Iv. Field naming
1. If the field is bool type, it is represented in the form of "isshow", "isvalid", "haspassed", "hasexamined", "ignorecase. Common bool type keywords include: Is, has, etc.
2. The date field must contain the date keyword, and the time field must contain the time
3. the user-type foreign key field must contain userid, which is managed by the user table. If the varchar type does not comply with this convention

 

V. Other Object names
4. Name the stored procedure: SP _ TABLE name_method, for example, sp_news_add and sp_news_update;

5. View name: vi _ table name, for example, vi_news;

6. All objects such as tables, stored procedures, and views are DBO. Do not use the database username. This will affect changes to database users.

 

In the development process, continue to modify and supplement...

 

 

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.