SQL generator-Generate SQL statements with comments

Source: Internet
Author: User
Tags generator

First, I'll explain the use of the environment, the data I use is Oracle, and I develop SQL statements using PL/SQL dev. In PL/SQL Dev, the short is a good implementation, but to write long SQL is very troublesome, first write good SQL, and then an add comment, add comment this step efficiency is really very low. A long time ago, when I ran into long SQL, I had already produced a SQL gadget that would automatically generate annotations, but unfortunately it has never been done.

Recently I have developed a new module that needs to write some simple SQL, such as inserting, querying, and updating statements. With the drive to develop the module recently, I'll write a SQL generator. The function of the SQL generator is to automatically generate SQL statements that are inserted, queried, and updated, and the statement fields must contain comments. All you know about SQL is that it requires one copy and paste or typing, so it's inefficient and error prone. My SQL generator can avoid this problem.

The implementation process of the SQL generator.

(1) Data access:

The view that comes with the Oracle data contains the field and field comments for the table, we need to correlate the views user_tab_columns and User_col_comments, just select the field name, data type, precision, and comment four fields to be able, table name as the condition parameter. The detailed SQL is as follows:

<span style= "White-space:pre" ></span>select tc.column_name as column_name, Tc.data_type as                                       data_type ,                                       tc.data_length as Data_length,                                       cc.comments as comments from                                  User_tab_columns TC, user_col_comments cc                                 where tc.table_name = Cc.table_name and                                   tc.column_name = Cc.column_name and                                   tc.table_name = ' {0} '
(2) Business realization:

SQL generator features, database connection settings, you need to enter the database user name, password and data source, query table field, display to DataGridView; You can select fields to generate SQL. The conditional functionality is also required for query statement SELECT and UPDATE statement update. The current condition can or is not perfect, query statements, we can generate the main part, conditional statement handwriting. As shown in the following:


(3) Generating SQL statements

I did not display the generated SQL statements in the interface, but by writing txt files. This feature needs to be aware of the SQL syntax, INSERT, update to distinguish between character, number or date type. TXT is generated through the Logo log class to achieve.

(4)

Click to open link


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

SQL generator-Generate SQL statements with comments

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.