Understanding software Development in advance (29) Layout of database script files

Source: Internet
Author: User
Tags create index header sybase database

"No rules, RADIUS," the code layout of the canonical database script file has the following important meanings:

(1) The code can display a good logical structure, improve the accuracy, continuity, readability and maintainability of the code.

(2) To improve the quality and efficiency of product development, and reduce development costs.

(3) For developers, developing good scripting habits can help improve the level of personal database scripting and thus improve scripting efficiency.

Visible, unified, good script code layout and style is not only the individual subjective aesthetic or formal problems, but also affect the quality of the product, and related to the improvement of their own scripting programming ability.

1. Overview of script Layout order

In the actual software development project, the Unified Specification script layout order may facilitate the reading to the code, facilitates the follow-up maintenance and the test modification. The contents of the script file can be laid out in the following two ways:

Mode one:

File header

Class

The establishment of user and access rights

The creation of data tables

Creation of stored procedures

Creation of database Tasks

End

Mode two:

File header

Class

The creation of data tables

Creation of stored procedures

Creation of database Tasks

The establishment of user and access rights

End

Attention:

(1) A common script file contains the 7 parts of mode one and mode two. To make it easier to differentiate and read, the sections are isolated using the annotation block (the annotation character uses "--").

(2) "The establishment of user and access rights" can be placed in the third part, can also be placed in the sixth part.

(3) Each part of the unified use of the annotation note, the relevant content must be written in the corresponding section, if the relevant content is empty, you must also retain the part of the annotation note.

2. Script Layout Example

Using mode one, the scripting code examples based on Sybase database implementations are as follows:

--Modification Record 1:--Modified Date:--Version number:--Modified by:--Modified content:--***************************************            
    
/--**************************************************--initialization initialization --************************************************** use master go using xxx-- Database go checkpoint go dump tran XXX with no_log-log truncation processing go--**** --User and right creation the establishment of 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 Varc Har not null--first name age int not null--ages Go--More highlights: htt p://www.bianceng.cnhttp://www.bianceng.cn/programming/project/--Create index idx_tb_example1 on Tb_exampl      E (name) go--************************************************************-procedure creation The creation of stored procedures--************************************************************--Information query stored procedure pr_selectinfo--
    
Input parameters: @v_name name, @v_age age--Output parameter: No 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 (30),--Name @v_age INT--Age as begin ...
    
     
End Go    
print ' CREATE PROCEDURE pr_selectinfo OK ' go--************************************************* *-Task Creation Database task Creation--************************************************** ...- --Finalization End--************************************* ......

In the actual software project, the layout of the script file has its strict rules, 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 technical exchange and sharing of the team.

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.