Which SQL statement reads the data of a table without changing it?
Answer : SELECT
SELECT reads the requested rows. INSERT adds, UPDATE modifies and DELETE removes rows.
Revise SQL & Databases: here is a selection of questions of every level, with the answer and an explanation. To test yourself without seeing the answers, play the quizzes.
Play the SQL & Databases quizzesAnswer : SELECT
SELECT reads the requested rows. INSERT adds, UPDATE modifies and DELETE removes rows.
Answer : DISTINCT
DISTINCT keeps only one occurrence of each identical row in the result.
Answer : WHERE
WHERE filters the rows according to a condition, for example WHERE age >= 18.
Answer : ORDER BY
ORDER BY name ASC sorts in ascending order, DESC in descending order.
Answer : INSERT
INSERT INTO adds a row; UPDATE modifies existing rows, CREATE creates a table and ALTER changes its structure.
Answer : A tuple, also called a record
A row is a tuple, also called a record; a column corresponds to an attribute.
Answer : Uniquely identify each row
The primary key cannot be NULL or repeated, which makes it possible to identify each row without ambiguity.
Answer : 1970
Edgar F. Codd published the founding article of the relational model in 1970, on which SQL is based.
Answer : INNER JOIN
INNER JOIN keeps only the matches; LEFT JOIN keeps all the rows of the left table, with NULL where there is no match.
Answer : SELECT ville, COUNT(*) FROM clients GROUP BY ville
GROUP BY ville groups the rows by city, and COUNT(*) counts the rows of each group.
Answer : HAVING
WHERE filters the rows before grouping; HAVING filters the groups, for example HAVING COUNT(*) > 5.
Answer : AVG
AVG calculates the average of the non-NULL values of a numeric column.
Answer : WHERE email IS NULL
A comparison with = or <> to NULL is never true: we use IS NULL or IS NOT NULL.
Answer : It provides the list of the client_id values present in the commandes table
The subquery returns a list of values; the outer query keeps the customers whose id appears in this list.
Answer : Reference the primary key of another table
A foreign key references a key, usually the primary key of another table; the DBMS can refuse a value that is absent from that table.
Answer : UNION
UNION merges the results while removing duplicates; UNION ALL keeps them all, without this removal step.
Answer : Atomicity
Atomicity: a transaction is executed entirely or not at all. ACID also covers consistency, isolation and durability.
Answer : READ COMMITTED
READ COMMITTED only reads committed data, but a row can change between two reads within the same transaction.
Answer : Being in 1NF and avoiding partial dependencies on a composite key
2NF assumes 1NF, then that no non-key attribute depends on only part of a composite key.
Answer : A B+ tree
InnoDB organizes its indexes as B+ trees, whose leaf nodes are linked together for range scans.
Answer : Shows the planned execution without running the query
EXPLAIN shows the planned execution (indexes, join order) without running the query; EXPLAIN ANALYZE, on the other hand, runs it.
Answer : A name given to a SELECT query, re-run on every read
An ordinary view stores nothing: it is re-executed on every read. A materialized view, on the other hand, keeps its results.
Answer : SQL code executed automatically on an INSERT, UPDATE or DELETE on a table
A trigger runs automatically when an event occurs on a table; a stored procedure, on the other hand, is called explicitly with CALL.
Answer : A distributed system cannot guarantee consistency, availability and partition tolerance all at once
When the network splits between nodes, a distributed system must choose between consistency and availability.
Play the SQL & Databases quizzes