2nd part Database SQL language
Blank lines and spaces in a database script
In database scripting, blank lines and spaces play a "icing on the cake". Using them properly can improve the standard and readability of the code, and improve the efficiency of the database programming.
1. Blank Line
A blank line acts as a separate script paragraph, and an appropriate blank line can make the layout of the script clearer. The functions of a blank line are as follows:
(1) create script for separating two data tables
Example:
CREATE TABLE Tb_example1
(
[ table Content Implementation code ]
)
Go
-- Blank Line
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 splitting different logical script blocks of code
Example:
[ script code block 1]
-- Blank Line
[ script code block 2]
2. spaces
spaces Play the role of separating characters, and the appropriate spaces can make the layout of the script cleaner and clearer. Note the following points regarding the use of spaces:
(1) a minimum of one space is required between the multivariate 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) after the Library keyword to leave a blank grid
The if, while and other keywords should be left after a space followed by the left 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 spaces after table name, stored procedure name, trigger name, function name, etc.
The table name, stored procedure name, trigger name, and function name are immediately followed by the opening parenthesis "(" to differentiate it from the keyword.
(4) It is recommended not to use the TAB key, and use a space to indent, indent to 4 spaces
This is to eliminate the differences in the TAB processing of different editors, and to prevent the layout from appearing neatly 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 work efficiency.
(I Weibo: Http://weibo.com/zhouzxi?topnav=1&wvr=5, No.: 245924426, welcome attention!) )