A database is a universal and comprehensive data set. It can be shared by various users and has the minimum redundancy and high data and program independence. Currently, major database management systems that are internationally dominated include ORACLE, SQLSERVER, SYBASE, INFORMIX, and INGRES. The commonly used programming language in databases is the SQL language, which can be divided into four
A database is a universal and comprehensive data set. It can be shared by various users and has the minimum redundancy and high data and program independence. Currently, major database management systems that are internationally dominated include ORACLE, SQL SERVER, SYBASE, INFORMIX, and INGRES. The commonly used programming language in databases is the SQL language, which can be divided into four
A database is a universal and comprehensive data set. It can be shared by various users and has the minimum redundancy and high data and program independence. Currently, major database management systems that are internationally dominated include ORACLE, SQL SERVER, SYBASE, INFORMIX, and INGRES.
The commonly used programming language in databases is the SQL language, which can be divided into four parts based on its functions:
(1)Data Definition Language)Defines, revokes, and modifies data modes.
(2)Data Query Language)Used to query data.
(3)Data Manipulation Language)Used to add, delete, and modify data.
(4)Data Control Language)Used to control data access permissions.
Data Definition languages include CREATE, DROP, and ALTER statements. data query languages include SELECT statements. Data Control languages include UPDATE, DELETE, and INSERT statements. Data Control languages include GRANT statements.
In addition to the preceding four SQL languages, the database also involves the concepts of tables, indexes, stored procedures, and transactions. They are also indispensable in actual programming.
1. Overview
Annotations play an important role in programming languages. Beautiful and proper comments not only help developers understand programs, but also improve programming efficiency (and thus improve service efficiency ).
However, it may be because of busy work that many developers do not pay attention to the writing of comments, which also makes it difficult for other developers to understand the program during project handover, I don't even know what the program is going to do. Therefore, writing good comments is a basic requirement for a developer and everyone must pay attention to it.
We recommend that you use English for script comments, which can be international, professional, and normative.
2. Comment on the header of the database script file
Many script files do not have header comments, which are not considered important. However, the author believes that this part of content must be added to facilitate tracking of version information in the future.
In the comments in the file header, you can use the following styles to include copyright, database type, creation date, author, modification record, and other information:
--*************************************** ******************************
-- Copy right (C) 2014, company name.
-- DB Type: XXX
-- Content: XXX
-- Created: YYYY. MM. DD
-- Modify1: The name of the author
-- Date1: YYYY. MM. DD
-- Version1: The original version of the product
-- Modify2: The name of who modified the file
-- Date2: YYYY. MM. DD
-- Version2: The updated version of the product
--*************************************** *******************************
3. Comment on the summary of database script files
After commenting on the header, do not create tables and stored procedures immediately. Instead, you should have a summary. For a table creation script, the summary is the name and purpose of the table included in the file. For a script for creating a stored procedure, summary is the name and purpose of the stored procedure included in the file. This abstract can serve as an index to help developers understand the main content of script files.
The following styles can be used to annotate abstract information:
-- ********** XXX (Version) DataBase Table Creating *********
-- * 1 table1: description1
-- * 2 table2: description2
-- * 3 table3: description3
......
--*************************************** ************
4. Notes at the beginning of a table or stored procedure
You can add notes at the beginning of a table or stored procedure to facilitate locating and viewing. You can use the following styles:
-- XXX (The name of the table or procedure, and what it is used)
The definition of the table or procedure
5. comment after each field in the table
After defining fields in a table, you need to comment on each field to help developers understand its role and avoid speculation and misunderstanding. In this way, it will be easy to use.
Table definitions and field annotations can adopt the following styles:
Create table tb_XXX
(
AAA int not null, -- description1
BBB varchar (256) not null, -- description2
CCC int default (0) null, -- description3
DDD varchar (256) default (''') null, -- description4
......
)
6. Notes for Stored Procedures
Generally, stored procedures include a large number of SQL statements, so annotations are complicated. Even so, there must be comments in some key statements, Otherwise other developers will have a hard time reading them.
You can write and annotate stored procedures in the following format:
Create procedure pr_XXX
@ AAA varchar (30), -- description1
@ BBB int, -- description2
......
As
Begin
Declare
@ CCC int, -- description3
@ DDD varchar (100), -- description4
......
......
-- YYY (name) add YYYYMMDD for ZZZ begin
......
-- YYY (name) add YYYYMMDD for ZZZ end
......
Statement1 -- YYY add YYYYMMDD description5
......
Statement2 -- YYY modify YYYYMMDD description6
......
Statement3 -- YYY delete YYYYMMDD description7
......
......
Statement4 -- description8 (important statement)
......
End
7. Summary
Comments are icing on the cake. inappropriate comments may not only play a proper role, but may lead to misunderstandings. Therefore, we must follow the simple, clear, clear, and easy-to-understand principles when adding a script file annotation.