Difference between a statement and a query in SQL

后端 未结 6 890
暗喜
暗喜 2020-12-14 00:14

I still live in this ambiguity: conceptually what\'s the difference between a statement and a query in SQL? Can anybody give a definition f

相关标签:
6条回答
  • 2020-12-14 00:22

    From Wikipedia - SQL Language Elements

    The SQL language is sub-divided into several language elements, including:

    • Clauses, which are constituent components of statements and queries. (In some cases, these are optional.)[9]
    • Expressions, which can produce either scalar values or tables consisting of columns and rows of data.
    • Predicates, which specify conditions that can be evaluated to SQL three-valued logic (3VL) or Boolean (true/false/unknown) truth values and which are used to limit the effects of statements and queries, or to change program flow.
    • Queries, which retrieve data based on specific criteria.
    • Statements, which may have a persistent effect on schemas and data, or which may control transactions, program flow, connections, sessions, or diagnostics.
      • SQL statements also include the semicolon (";") statement terminator. Though not required on every platform, it is defined as a standard part of the SQL grammar.
    • Insignificant whitespace is generally ignored in SQL statements and queries, making it easier to format SQL code for readability.
    0 讨论(0)
  • 2020-12-14 00:24

    A statement is any SQL command such as SELECT, INSERT, UPDATE, DELETE.

    A query is a synonym for a SELECT statement.

    0 讨论(0)
  • 2020-12-14 00:24

    They're used interchangeably by most, but some often use the word "query" to mean, specifically, SELECT statements, because when you query something or someone, you want information. And SELECT queries return result sets, so that'd fit the description nicely. This also is evident in the fact that SELECT statements are formally called DQL (Data Query Language) statements.

    0 讨论(0)
  • 2020-12-14 00:32

    Queries is used for retrieve data based on specific criteria, but statement may have a persistent effect on schemas and data, or which may control transactions, program flow, connections, sessions, or diagnostics. See also Wikipedia.

    0 讨论(0)
  • 2020-12-14 00:39

    A statement is any text that the database engine recognizes as a valid command. As of SQL-92:

    An SQL-statement is a string of characters that conforms to the format and syntax rules specified in this international standard.

    A query is a statement that returns a recordset (possibly empty).

    How can I call a chunk of SQL code made by more than one statement where statements are separated by a semicolon (;)? Who already replied can edit his answer. Many thanks!

    A series of SQL statements sent to the server at once is called a batch.

    Not all SQL engines required the statements in a batch to be semicolon delimited. SQL Server, for instance, generally does not and breaks the statements based on context. CTE statements starting with WITH are a notable exception.

    0 讨论(0)
  • 2020-12-14 00:42

    A statement is the general term for a piece of complete, correct SQL that you can send to a DBMS. A query is a statement that will return data, thus a query is a special kind of statement.

    A SELECT ... would be a query, a DELETE... just a statement.

    0 讨论(0)
提交回复
热议问题