SQL中语句和查询的区别[英] Difference between a statement and a query in SQL

本文是小编为大家收集整理的关于SQL中语句和查询的区别的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我仍然生活在这种歧义中:从概念上讲,语句和a 查询在SQL中有什么区别?有人可以为每个人提供一个定义吗? It would be useful, for example when choosing variables names inside programs in a way that will be clear for everybody. 谢谢!

另外:如何称呼由多个语句制成的SQL代码的一块,而该语句被半词(;)分开?已经回答的人可以编辑他的答案.非常感谢!

推荐答案

a 语句是数据库引擎识别为有效命令的任何文本.从SQL-92开始:

sql-statement是符合格式和语法规则的字符串.

a 查询是返回记录集(可能为空)的语句.

如何调用由多个语句用半隆(;)分离的多个语句制作的SQL代码的一部分?已经回答的人可以编辑他的答案.非常感谢!

一次发送到服务器的一系列SQL语句称为 batch .

并非所有SQL引擎都要求批次中的陈述必须是半分离的.例如,SQL Server通常不会并根据上下文打破语句. CTE以WITH开头的语句是一个显着的例外.

其他推荐答案

a 语句是任何SQL命令,例如SELECT,INSERT,UPDATE,DELETE.

a 查询是选择语句的同义词.

其他推荐答案

来自 wikipedia- sql语言元素

SQL语言分为几个语言元素,包括:

  • 条款,是语句和查询的组成部分. (在某些情况下,这些是可选的.)[9]
  • 表达式,可以产生标量值或由数据行组成的表格.
  • 谓词,它指定可以评估为SQL三值逻辑(3vl)或布尔值(true/forade/fewarde)真实值的条件,并用于限制语句和语句效果查询或更改程序流.
  • 查询 ,根据特定标准检索数据.
  • 语句 ,可能会对模式和数据产生持久影响,或者可以控制交易,程序流,连接,会话或诊断.
    • SQL语句还包括Semicolon(";")语句终结者.尽管在每个平台上都不需要,但它被定义为SQL语法的标准部分.
  • 微不足道的空格通常在SQL语句和查询中被忽略,使得更容易格式化SQL代码以确保可读性.

本文地址:https://www.itbaoku.cn/post/597636.html

问题描述

I still live in this ambiguity: conceptually what's the difference between a statement and a query in SQL? Can anybody give a definition for each of them? It would be useful, for example when choosing variables names inside programs in a way that will be clear for everybody. Thanks!

ADDITIONALLY: 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 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.

其他推荐答案

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

A query is a synonym for a SELECT statement.

其他推荐答案

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.