Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 357
Paul Bruno Avatar asked Jul 14 '11 21:07

Paul Bruno


People also ask

Which SQL command is used for insert update and DELETE?

INSERT , UPDATE , and DELETE , as well as SELECT and MERGE, are known as Data Manipulation Language (DML) statements, which let SQL users view and manage data.

What is insert update and DELETE command?

The SQL INSERT, UPDATE, and DELETE commands enable SQL users to manipulate and modify data: The INSERT statement introduces new rows into an existing table. The DELETE statement removes a row or combination of rows from a table. The UPDATE statement enables users to update a row or group of rows in a table.

What is the query for insert in SQL?

INSERT INTO Syntax Specify both the column names and the values to be inserted: INSERT INTO table_name (column1, column2, column3, ...)


2 Answers

When in doubt, call it a "statement."

like image 24
David Marx Avatar answered Oct 09 '22 12:10

David Marx


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]

like image 140
onedaywhen Avatar answered Oct 09 '22 13:10

onedaywhen