Let you know about software development in advance (30): blank lines and spaces in database scripts

Source: Internet
Author: User

Part 1 Database SQL language

Empty rows and spaces in database scripts

 

 

In database scripts, empty rows and spaces play the "icing on the cake" role. Using them appropriately can improve the Code standardization and readability, and thus improve the programming efficiency of the database.

 

1. Empty rows

Empty rows are used to separate script paragraphs. Appropriate empty rows can make the script layout clearer. Empty rows have the following functions:

(1) create scripts used to separate two data tables

Example:

Create table tb_example1

(

[Table content implementation code]

)

Go

-- Empty line

Create table tb_example2

(

[Table content implementation code]

)

Go

 

(2) create scripts used to separate two stored procedures

Example:

-- Pr_example1

[Stored Procedure pr_example1 implementation code]

-- Empty line

-- Pr_example2

[Stored Procedure pr_example2 implementation code]

 

(3)Used to separate different logic script code blocks

Example:

[Script code block 1]

-- Empty line

[Script code block 2]

 

2. Space

Spaces are used to separate characters. Appropriate spaces can make the script layout more clean and clear. Note the following when using spaces:

(1) There must be at least one space between the operators and their operands.

Example:

Select @ v_id = 1 -- Note: There are spaces before and after "="

Select @ v_name = 'hello' -- Note: There are spaces before and after "= ".

Select @ v_num = @ v_num + 1 -- Note: There are spaces before and after "=" and "+"

 

(2) Leave a space after the database keyword

If, while, and other keywords should be followed by a space and followed by the left parenthesis "(" to highlight the keyword.

Example:

If (@ tableindex = 1) -- Note: there is a space after "if ".

Begin

[Statement execution]

End

 

(3) do not leave spaces after the table name, stored procedure name, trigger name, and function name are created.

The table name, stored procedure name, trigger name, and function name are followed by the left parenthesis "(", which is different from the keywords.

 

(4) we recommend that you do not use the TAB key, but use spaces for indentation. The indentation is 4 spaces.

This is to eliminate the differences in the TAB key processing by different editors and prevent the layout from being neat when opening the same code in different editors.

 

In actual software projects, the appropriate use of blank lines and spaces can make the code more beautiful. This is very good for improving work efficiency.

 

 

(My microblogging: http://weibo.com/zhouzxi? Topnav = 1 & wvr = 5, No.: 245924426, welcome !)

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.