Statements, Commands & Queries
SQL Community View
When talking about SQL language instructions communicating the requested behavior to a DBMS (such as Postgres) three terms are often used:
-
a statement,
-
a command, and
-
a query.
Unfortunately, the terms are not clearly defined nor delimited by the SQL community (vide Difference between a statement and a query in SQL).
Some deem a statement (a command) to be any SQL instruction to a DBMS that can potentially 1) persist manipulated data and/or 2) retrieve unmanipulated data, and a query an SQL instruction that can only retrieve unmanipulated data. In this view the query term is a semantic subset of the statement (the command) term.
Other deem a statement (a command) to be an SQL instruction to a DBMS that can potentially persists manipulated data, and a query an SQL instruction to a DBMS that only retrieves unmanipulated data. In this view the statement (the command) term is semantically disjointed from the query term.
In both views the term statement and command is equalized.
Object-Oriented Programming Command Query Separation
The term "Command Query Separation" was coined by Bertrand Meyer in the book "Object-Oriented Software Construction". The term does not refer to SQL commands or queries but to object methods and is presented here for reference purposes only.
In the Command Query Separation view a command method changes the state of a system but does not return a value, and a query method does not change the state of the system but does return a value.