The difference between dynamic SQL and static SQL

Source: Internet
Author: User
Tags what sql sql using

    First of all, the so-called SQL dynamic and static, refers to when SQL statements are compiled and executed, both are used in SQL embedded programming, which is referred to as embedded refers to the SQL statement embedded in the high-level language, rather than the type of microcontroller embedded programming.
    In a high-level language, if an SQL statement is embedded, and the main structure of the SQL statement is clear, for example, there is a SQL "select * from T1 where c1>5" to execute in a piece of Java code, in the Java compilation phase, You can pass this SQL to the database management system to analyze, the database software can parse this SQL, generate database executable code, such SQL is called Static SQL, that is, in the compilation phase can determine what the database to do.
    And if the embedded SQL is not explicitly given, such as a variable sql:string SQL that defines a string type in Java, then executes the SQL using the Execute method of the PreparedStatement object, The value of the SQL may be equal to one SQL read from the text box or SQL entered from the keyboard, but what is not determined at compile time, only wait until the program is run, in the process of execution can be determined, this SQL is called Dynamic SQL. For example, each database software has the ability to execute the SQL statement interface, the interface received SQL is dynamic SQL, because the database vendors do this interface, do not know what the user will enter the SQL, only after the interface executes, the user's actual input, only to know what SQL is.
    Also note that in SQL if some parameters are not determined, such as "select * from T1 where C1> and c2< ", this statement is static SQL, not dynamic SQL, although the value of the individual parameters is not known, but the entire SQL structure has been determined that the database can be compiled, in the execution phase only need to add the values of individual parameters.

The difference between dynamic SQL and static SQL

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.