2nd part Database SQL language
Layout of database script files
"No rules." Inadequate surrounding area, the code layout of the canonical database script file has the following important meanings:
(1) can show the logical structure of good code. Improve the accuracy, continuity, readability, and maintainability of your code.
(2) It is helpful to improve the quality and efficiency of product development and reduce the development cost.
(3) for developers. Developing a good scripting habit can help improve the level of personal database scripting programming. This improves the efficiency of script programming.
Visible, unified, good script code layout and style is not only a subjective aesthetic or formal problems, and affect the quality of the product, and related to the improvement of their own script programming ability.
1. Overview of script layout order
In the actual software development project, the Uniform Specification script Layout order can facilitate the reading of the code. Facilitates maintenance and test changes.
You can use the following two ways to lay out the contents of a script file:
Way One:
File header
Initialization
Establishment of user and access rights
Creation of data tables
Creation of stored procedures
Creation of database Tasks
End
Way two:
File header
Initialization
Creation of data tables
Creation of stored procedures
Creation of database Tasks
Establishment of user and access rights
End
Attention:
(1) an ordinary script file includes the 7 parts of mode one and mode two. To make it easier to distinguish and read, each part is separated by a gaze block ( the gaze uses "-").
(2) "The establishment of user and access rights" can be placed in the third part, but also in the sixth part.
(3) all parts before the uniform use of labeling instructions. The relevant content must be written in the appropriate section, assuming that the relevant content is empty, you must also retain the part of the labeling instructions.
2. Script Layout Demo sample
Adopt the way one. The script code that is implemented based on the Sybase database is scaled as follows:
--*********************************************************************
-- All rights reserved (C), Zhou Zhaoxiong.
-- database version number: Sybase ASE Enterprise 15.0
-- Content Summary: script file Layout Demo sample
-- Creator: Zhou zhaoxiong
-- completion date: 20140616
-- change record 1:
-- date of change:
-- version number:
-- Change Person:
-- Change content:
--**********************************************************************/
--**************************************************
--Initialization initialization
--**************************************************
Use master
Go
use xxx -- The database to be used
Go
Checkpoint
Go
dump tran xxx with no_log-- log truncation processing
Go
--************************************************************
-- establishment of user and right creation users and permissions
--************************************************************
exec sp_addalias xxx, dbo
Go
--***********************************************************************
-- creation of table creation datasheet
--***********************************************************************
-- sample table tb_example
if exists (select 1 from sysobjects where id = object_id (' tb_example '))
Begin
drop table Tb_example
End
Go
CREATE TABLE Tb_example
(
name varchar (+) NOT NULL,-- name
Age Int. NOT NULL-- ages
)
Go
-- Create an index
Create INDEX Idx_tb_example1 on tb_example (name)
Go
--************************************************************
-- creation of procedure creation stored procedures
--************************************************************
-- information query stored procedure pr_selectinfo
-- Enter the number of references:@v_name name. @v_age Age
-- output parameters: None
if exists (select 1 from sysobjects where id = object_id (' Pr_selectinfo '))
Begin
drop procedure Pr_selectinfo
End
Go
CREATE PROCEDURE Pr_selectinfo
@v_name varchar (in),-- name
@v_age INT-- Age
As
Begin
......
End
Go
print ' CREATE PROCEDURE pr_selectinfo OK '
Go
--**************************************************
--Task creation creation of database tasks
--**************************************************
......
--**************************************************
--Finalization end
--**************************************************
......
In the actual software project. The layout of the script file has its strict rules, and developers need to follow the programming specifications to write script code. This not only facilitates the reading and modification of the code, but also facilitates the exchange and sharing of the team.
(I Weibo: Http://weibo.com/zhouzxi?)
Topnav=1&wvr=5. Number: 245924426. Welcome attention! )
Let you know in advance. Software Development (29): Layout of database script files