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.