SQL 术语:“查询”或“命令”用于插入/更新/删除?

发布于 2024-11-19 21:33:17 字数 173 浏览 5 评论 0原文

调用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

爱人如己 2024-11-26 21:33:17

INSERTUPDATEDELETEMERGE 的通用术语是“更新”(即使它是可能会令人困惑 - 并且不理想 - UPDATE 只是“更新”的子集)。另一个术语是“关系分配”。

SELECTINSERTUPDATEDELETEMERGE(以及任何以分号结尾的其他内容都称为“语句”。

严格来说,“查询”是返回结果集的 SELECT 语句(例如,这会排除 SELECT..INTO..FROM 语句)。然而,使用术语“查询”来指代更新虽然是非正式的,但不幸的是很常见。例如,虽然“更新查询”是一个矛盾修辞法,但当我使用该确切术语(site:stackoverflow.com“更新查询”)对该网站进行 Google 搜索时,我得到了 17,300 次点击!


更新(双关语:)

@David Marx:我不同意你关于引用是适当的说法
插入/删除/合并作为“更新”。那将是极其
令人困惑。只有UPDATE才是更新。

我在最初的回答中同意这种情况可能会令人困惑。我们很幸运在 Stackoverflow 上能够格式化答案和评论,以便可以将关键字 UPDATE 与逻辑更新区分开来;以大写形式编写关键字(按照完整标准 SQL-92 的要求:)也有帮助。

然而,通过阅读一般数据库和计算科学文献,我可以告诉你“更新”确实是正确的集体术语。我在下面提供了对此的引用:

“关系数据库理论简介”(2010),休·达尔文(Hugh Darwen)[可免费下载 pdf - Google 一下):

关系 DBMS 中期望的不同更新运算符是
通常称为 INSERT、DELETE 和 UPDATE,这些是
教程 D 中使用的名称(也在 SQL 中)[p.28]

令人遗憾的是关键字UPDATE已经变得如此广泛
接受作为仅一个特定更新操作员的名称
数据库。请不要向使者开枪! [第168页]

尽管[关系]赋值在理论上就足够了
出于更新目的,使用简写通常更方便
表达目标当前值之间的差异
相关变量和新值。有时候……差别只是
将一个或多个元组添加到现有集合中;有时是
只是改变了一些现有的一些属性值
元组;有时只是删除一些现有的
元组。这三种特殊情况的简写已被提及
从时间起分别为 INSERTUPDATEDELETE
远古的——换句话说,甚至在关系出现之前
数据库,当然,在此之前,
更新是文件,而不是相关变量或 SQL 表 [p.165]

The generic term for a INSERT, UPDATE, DELETE and MERGE is an "update" (even though it is potentially confusing -- and not ideal -- that UPDATE 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 preclude SELECT..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 :)

@David Marx: I disagree with your claim that it's appropriate to refer
to INSERT/DELETE/MERGE as an 'update.' That would be extremely
confusing. Only UPDATE is an update.

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):

The different update operators expected in a relational DBMS are
usually called INSERT, DELETE and UPDATE, and those are the
names used in Tutorial D (also in SQL) [p.28]

It is regrettable that the keyword UPDATE has become so widely
accepted as the name of just one particular operator for updating
databases. Please don't shoot the messenger! [p.168]

although [relational] assignment is theoretically sufficient for
updating purposes, it is usually more convenient to use a shorthand
expressing the difference between the current value of the target
relvar and the new value. Sometimes... that difference is just the
addition of one or more tuples to the existing set; sometimes it is
just changes to some of the attribute values of some of the existing
tuples; and sometimes it is just the removal of some of the existing
tuples. Shorthands for those three particular cases have been referred
to as INSERT, UPDATE and DELETE respectively, since time
immemorial -- in other words, even before the advent of relational
databases, though of course before that advent the targets of the
updates were files, not relvars or SQL tables [p.165]

幽蝶幻影 2024-11-26 21:33:17

如有疑问,请将其称为“声明”。

When in doubt, call it a "statement."

独留℉清风醉 2024-11-26 21:33:17

有时,除了 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文