SQL Nomenclature: "Query" or "Command" for INSERT/UPDATE/DELETE?
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
andUPDATE
, 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
andDELETE
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."