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 !)