SQL 术语:“查询”或“命令”用于插入/更新/删除?
调用 INSERT/UPDATE/DELETE 语句哪个更合适?命令还是查询?我认为“命令”,因为“查询”意味着您正在提出问题并期望得到答案(以及更多信息,而不仅仅是“是的,此操作已成功执行,并且可选地,这是您的插入 ID”) 。
这是一位中级 Web 应用程序开发人员提出的问题,他也是通信专业的,并且喜欢特殊性。
Which is more proper to call INSERT/UPDATE/DELETE
statements? Command or query? I would think "command," since "query" implies that you are asking a question and expecting to get your question answered (and more information than just "yes, this operation was performed successfully, and, optionally, here's your insert ID").
Just a question from a mid-level web application developer who was also an communications major and is one who enjoys specificity.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
INSERT
、UPDATE
、DELETE
和MERGE
的通用术语是“更新”(即使它是可能会令人困惑 - 并且不理想 -UPDATE
只是“更新”的子集)。另一个术语是“关系分配”。SELECT
、INSERT
、UPDATE
、DELETE
、MERGE
(以及任何以分号结尾的其他内容都称为“语句”。严格来说,“查询”是返回结果集的
SELECT
语句(例如,这会排除SELECT..INTO..FROM
语句)。然而,使用术语“查询”来指代更新虽然是非正式的,但不幸的是很常见。例如,虽然“更新查询”是一个矛盾修辞法,但当我使用该确切术语(site:stackoverflow.com“更新查询”
)对该网站进行 Google 搜索时,我得到了 17,300 次点击!更新(双关语:)
我在最初的回答中同意这种情况可能会令人困惑。我们很幸运在 Stackoverflow 上能够格式化答案和评论,以便可以将关键字
UPDATE
与逻辑更新区分开来;以大写形式编写关键字(按照完整标准 SQL-92 的要求:)也有帮助。然而,通过阅读一般数据库和计算科学文献,我可以告诉你“更新”确实是正确的集体术语。我在下面提供了对此的引用:
“关系数据库理论简介”(2010),休·达尔文(Hugh Darwen)[可免费下载 pdf - Google 一下):
The generic term for a
INSERT
,UPDATE
,DELETE
andMERGE
is an "update" (even though it is potentially confusing -- and not ideal -- thatUPDATE
is merely a subset of "update"). An alternative term is "relational assignment".The generic term for
SELECT
,INSERT
,UPDATE
,DELETE
,MERGE
(and anything else terminated by a semicolon) is known as a "statement".Strictly speaking, a "query" is a
SELECT
statement that returns a resultset (which would for example precludeSELECT..INTO..FROM
statements). However, using the term "query" to refer to an update, while informal, is unfortunately very common. For example, although "update query" is an oxymoron, when I do a Google search for this site using that exact term (site:stackoverflow.com "update query"
) I get 17,300 hits!UPDATE (pun indended :)
I agreed in my original answer that the situation is potentially confusing. We are fortunate on Stackoverflow to be able to format answers and comments so that a keyword
UPDATE
can be differentiated from a logical update; writing keywords in upper case (as required by Full Standard SQL-92 :) also helps.However, from reading the general database and computing science literature, I can tell you that 'update' is indeed the correct collective term. I below provide a citation for this:
"An Introduction to Relational Database Theory" (2010), Hugh Darwen [available as a free pdf download -- Google it):
如有疑问,请将其称为“声明”。
When in doubt, call it a "statement."
有时,除了 select 之外的任何语言都被视为 DML(数据操作语言)。然而,这并不是一个硬性的区别。这与 DML 中经常包含 select 一样。
Sometimes anything other than select is considered to be DML - Data Manipulation Language. However this is not a hard and fast distinction. That is just as often select is included within DML.