Let you know ahead of time Software development (26): Database scripting Gaze

Source: Internet
Author: User
Tags table definition

2nd part Database SQL language

The gaze of database scripts

1. Overview

Gaze plays a very important role in programming language writing. Graceful, well-timed gaze not only helps developers understand the program, but also improves programming efficiency ( and thus improves efficiency ).

However, it may be because the work is more busy, many developers do not pay attention to the writing of gaze, which also led to the handover of the project, other developers understand the program difficult. Don't even know what the program is going to do. Therefore, the writing of good gaze is a basic requirement for a developer, and we must pay attention to it.

For the gaze of the script. We suggest that we all adopt English, so that we can embody internationalization, professionalism and standardization.

2. database script file gaze at the head

Very many script files do not have a head gaze, and it is not important for everyone to think about it. However, the author felt that this part of the content must be added, so that later tracking version number information to provide convenience.

In the gaze of the head of the file, include information such as copyright, database type, creation date, author, change record, etc., which can be used in the following style:

--*********************************************************************

-Copy Right (C), company name.

--DB Type:xxx

--Content:xxx

--created:yyyy. Mm. Dd

--modify1:the name of the author

--date1:yyyy. Mm. Dd

--Version1:the original version of the product

--modify2:the name of the WHO modified the file

--date2:yyyy. Mm. Dd

--Version2:the updated version of the product

--**********************************************************************

3. the gaze of the database script file summary information

After staring at the head. Do not start creating tables and stored procedures immediately, but you should have a summary. The assumption is that a table script is created, and the summary is the name and purpose of the table contained in the file. The assumption is the script that creates the stored procedure, and the summary is the name and purpose of the stored procedure contained in the file.

This summary can serve as an index to help developers understand the main contents of a script file.

The gaze of the summary information can be used in the following style:

--********* XXX (Version) DataBase Table creating*********

--* 1 Table1:description1

--* 2 Table2:description2

--* 3 Table3:description3

. . . . . .

--***************************************************

4. Gaze at the beginning of a table or stored procedure

By adding gaze at the beginning of a table or stored procedure, it can be conveniently positioned and easily accessible. The following styles can be used:

--XXX (the name of the table or procedure, and what it's used for)

The definition of the table or procedure

5. gaze after each field of the table

After you have defined the fields of a table, you need to stare at each field. To make it easier for developers to understand their role. Avoid pushing and wrong understanding.

This makes it easier to use.

The table definition and field gaze can be used in the following style:

CREATE TABLE Tb_xxx

(

AAA int NOT NULL,--Description1

BBB varchar () NOT NULL,--Description2

CCC int default (0) NULL,--Description3

DDD varchar ("") Default ("") null,--Description4

. . . . . .

)

6. Gaze of the stored procedure

Generally speaking. The stored procedure contains more SQL statements, so the gaze is more complex. Even so, there must be a gaze in the place of some key statements. Otherwise developers will be more laborious to read.

The writing of stored procedures and the gaze can be made using the following style ( in the case of the Sybase database Syntax ):

CREATE PROCEDURE Pr_xxx

@AAA varchar (+),--Description1

@BBB int,--Description2

. . . . . .

As

Begin

Declare

@CCC int,--Description3

@DDD varchar (+),--Description4

. . . . . .

. . . . . .

--YYY (name) add YYYYMMDD for ZZZ begin

    . . . . . .

--YYY (name) add YYYYMMDD for ZZZ end

. . . . . .

Statement1--YYY add YYYYMMDD description5

. . . . . .

Statement2--YYY Modify YYYYMMDD Description6

. . . . . .

Statement3--YYY Delete YYYYMMDD description7

. . . . . .

. . . . . .

Statement4--Description8 (important statement)

. . . . . .

End

7. some of the rules and recommendations concerning gaze

(1) Use the "--" to Stare ( do not use "/* * * /Stare").
(2) The script file must be stared at the head.

(3) before a script with a certain function ( such as creating data tables, stored procedures, tasks, inserting default records, etc. ). Should have a gaze description.

(4) there should be a gaze after creating each field in the data table. Description of the meaning of the field, some also need to explain the range of values and so on.

(5) Create stored procedures and functions in each of the input and output parameters should be staring, explain the meaning of the parameters, some also need to explain the range of values.

(6) write the gaze on the branch statement ( including the conditional branch ), the loop statement, and so on.

(7) ensure the consistency of the code and gaze. Change the code at the same time to change the corresponding gaze, no longer practical gaze to delete.

(8) The gaze should be similar to the code described in the description. The gaze on the code should be placed in the adjacent position above or to the right ( gazing at the fields and stored procedure parameters in the data table ) . Not to be placed below. If placed above, it should be separated from the code above with a blank line.

(9) The gaze is indented in the same way as the described description code.

The Chinese version of the gaze unifies the use of Chinese descriptive narrative, the overseas version of the gaze unified use of English descriptive narrative.

The code becomes self-gazing by correctly naming functions or processes, variables, etc., and by properly organizing code structures.

try to avoid using abbreviations in your gaze, especially if you don't use abbreviations frequently.

8. Summary

The role of gaze is icing on the cake, and inappropriate gaze not only does not work as it should, but it can make people misunderstand. So. When we join the script file gaze, we must follow the simple, clear, clear, easy-to-understand principles.

(This series of articles updated two weekly, please look forward to!) I Weibo: Http://weibo.com/zhouzxi?topnav=1&wvr=5, No.: 245924426, welcome attention! )

Let you know ahead of time Software development (26): Database scripting Gaze

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.