开发者

SQL Nomenclature: "Query" or "Command" for INSERT/UPDATE/DELETE?

开发者 https://www.devze.com 2023-03-20 15:56 出处:网络
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 ans

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 开发者_JAVA技巧question from a mid-level web application developer who was also an communications major and is one who enjoys specificity.


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]


When in doubt, call it a "statement."


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消