Advance understanding of software development (30) blank lines and spaces in database scripts

Source: Internet
Author: User
Tags empty table name

In database scripts, empty lines and spaces play a "icing on the cake". The proper use of them can improve the standardization and readability of the code, and then improve the programming efficiency of the database.

1. Blank line

Blank lines play a role in separating the script paragraphs, and the appropriate blank lines can make the script layout clearer. Empty rows have the following effects:

(1) Create script to separate two data tables

Example:

CREATE TABLE Tb_example1
    
(
    
        [table content Implementation code]
    
)
    
go
    
--empty row
    
CREATE table Tb_example2
    
(
    
        [Table content Implementation code ]
    
)
    
go

(2) Create script for splitting two stored procedures

Example:

--Pr_example1

[Stored procedure pr_example1 Implementation code]

--Blank line

--Pr_example2

[Stored procedure pr_example2 Implementation code]

(3) for dividing different logical script blocks

Example:

[Script code block 1]

--Blank line

[Script code block 2]

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/project/

2. Space

Spaces play the role of separating characters, and the appropriate spaces can make the layout of the script more neat and clear. Note the following points for using spaces:

(1) At least one space is required between the multivariate operator 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) After the Library keyword to leave blank lattice

You should leave a space after the IF, while, and so on, and then follow the opening parenthesis "(") to highlight the keyword.

Example:

if (@tableindex =1)--Note: There is a space after "if"

Begin

[EXECUTE statement]

End

(3) When creating tables, stored procedures, triggers, functions, etc., do not leave blank after table name, stored procedure name, trigger name, and function name.

The table name, stored procedure name, trigger name, and function name are followed by the opening parenthesis "(") to differentiate from the keyword.

(4) Do not recommend the use of the TAB key, and use the space to indent, indented to 4 spaces

This is to eliminate the differences in the tab handling of different editors, preventing the layout from being neatly printed when the same code is opened with different editors.

In the actual software project, the proper use of blank lines and spaces, can make the code more beautiful. This is good for improving productivity.

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.