Oracle comment: Significance of comment on

Source: Internet
Author: User

 

Comments are now accepted and recognized by everyone. Third-party plug-ins are provided in all programming ides to support the extraction of comments.
Quickly understand the structure functions. However, in writing database scripts, I also summarized some things and learned from them.
The following describes how to create an oracle table.
Create Table ctable_name
(
Field1 varchar2 (20), -- Comment content 1
Field2 number, -- Comment content 2
Field3 char (2), -- Comment content 3
Field4 date/* Comment content 4 */
)
I have been building tables like this all the time before, and I feel that it is both quick and understandable. In fact, I also like this method when the database structure is not complex, but it is a headache to maintain it when the database structure is very complex, an SQL statement that is hundreds of KB is worth your attention. With n Such SQL files, you can implement fast programming for complex database structures that you don't know about, in order to understand the workload of structure search and annotation.
In particular, the company has been working on projects for five years, and many SQL scripts are missing. Therefore, the data structure can only be used by old colleagues, however, for companies with frequent staff turnover, when Old Cheng colleagues changed a few batches, they were not there. No one could ask, so the maintenance staff or subsequent developers fell into endless pain points, A lot of problems occur here. The investment cost in the later stage is also huge. If the naming rules of database structures are better, you can use them literally. In addition, the transfer of knowledge is caused by a lack of factors. For example, an employee usually takes one month to hand over before leaving the company, but most of them use
If you hand over the work in a week or so, you will naturally consciously ignore some small or hidden problems and only focus on the main advantages, if a colleague who has a good understanding of the structure is handed over, it is not a problem to take over based on the corresponding experience. However, if the employee is handed over to a new employee, it will be very difficult to pick up the new employee, the company where a colleague is going to enter also urges him to leave his job quickly. The missing part should be compensated by new colleagues, of course, if he is a person in charge, when he finds that although the project can be run or the program can run, there are some things, generally, he doesn't know the details and needs to call his colleagues to find out the details, so there won't be any problems, but what I'm talking about is, generally, people will not get those things when they see that the project can be done (the program can run). In this way, the loop goes down, and finally the program is maintained or the bad guys developed in the future will suffer, I have experienced this kind of pain, so I have a deep understanding. It is estimated that other companies will also have this kind of phenomenon.
 
To sum up the possible situations:
1. There are a lot of SQL script content, the format is not standard, reading is not convenient, joint search is not very efficient.
2. There are a lot of SQL scripts, and each has a problem of 1, which is still inefficient.
3. Lost details in database work handover.
4. Problems 3 occur and the database object naming is not standard. The maintenance personnel will be ambiguous about the meaning of the database object in the future, and the associated problems will approach infinity,
Mental torture approaches infinity, resulting in the probability that you don't want to continue and quit.
After summing up, we will certainly propose a solution that I think is better. We will use the comment keyword to solve this problem. Let's take a look at the following methods.
Create Table ctable_name
(
 
Field1 varchar2 (20), -- Comment content 1
Field2 number, -- Comment content 2
Field3 char (2), -- Comment content 3
Field4 date/* Comment content 4 */
)
-- Select * From ctable_name;
Comment on table ctable_name is 'table comment content';/* Add Comment to table */
Select * From user_tab_comments where table_name = 'ctable _ name';/* query comments of a table */
 
Comment on column ctable_name.field1 is 'comment content to the field1 column ';/* Comment content to the column, how many columns should be written */
Select * From user_col_comments where table_name = 'ctable _ name' and column_name = 'field1';/* query comments of a column in a table */
 
The above solution solves all the problems I mentioned above. The essence is to use the data dictionary function in Oracle. Although it may take more work to write scripts, however, he can achieve much greater results than that.
 
The editor here is really bad and won't be passed in. You can execute the above statements in the database at that time. Let's talk about his advantages.
1. You can use SQL statements to quickly query tables, as long as you know the table name and field name, locate the comment, which is very convenient and fast.
2. The comment content is stored in the dictionary table. As long as the table structure is still there, the SQL script can locate the query even if it does not exist.
3. You do not need to guess what the field means, because the comments with no two meanings have been given in the simplified table, and they will be clarified later.
4. You can write your own gadgets to accelerate the learning process of data structures and facilitate new employees.
5. I strongly recommend that you do this. Colleagues can add comments to the table structure of the original database.
 
I wrote a little in a hurry and did not make it clear in many places. You are welcome to come and learn from each other. I have already done this in my subsequent projects, and it is indeed a lot of benefit. I finally used Zhao Benshan's words to end "who knows who to use ".

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.