Which SQL statement retrieves data from a table?
- A. GET
- B. FETCH
- C. SELECT (correct)
- D. READ
Which clause filters rows in a SELECT query?
- A. ORDER BY
- B. WHERE (correct)
- C. FROM
- D. GROUP BY
Which clause sorts the result of a query?
- A. ORDER BY (correct)
- B. GROUP BY
- C. SORT BY
- D. ARRANGE
Which keyword sorts results from highest to lowest?
- A. REVERSE
- B. DESC (correct)
- C. ASC
- D. DOWN
Which SQL statement adds a new row to a table?
- A. UPDATE
- B. INSERT INTO (correct)
- C. CREATE ROW
- D. ADD ROW
Which SQL statement changes existing rows?
- A. CHANGE
- B. MODIFY
- C. UPDATE (correct)
- D. ALTER ROW
Which SQL statement removes rows from a table?
- A. DELETE (correct)
- B. ERASE
- C. REMOVE
- D. DROP ROW
What does SELECT * return?
- A. All tables
- B. Only the first column
- C. Only the primary key
- D. All columns (correct)
Which function counts rows?
- A. SUM()
- B. TOTAL()
- C. NUMBER()
- D. COUNT() (correct)
Which function returns the average of a column?
- A. AVERAGE()
- B. MEAN()
- C. AVG() (correct)
- D. MID()
Which function returns the largest value in a column?
- A. MAX() (correct)
- B. TOP()
- C. BIG()
- D. HIGHEST()
Which keyword removes duplicate rows from a result?
- A. DISTINCT (correct)
- B. UNIQUE
- C. DIFFERENT
- D. SINGLE
Which operator checks for a value within a range?
- A. WITHIN
- B. BETWEEN (correct)
- C. RANGE
- D. INSIDE
Which operator matches a pattern such as names starting with A?
- A. MATCH
- B. LIKE (correct)
- C. SIMILAR
- D. PATTERN
In LIKE patterns, what does % match?
- A. Any sequence of zero or more characters (correct)
- B. Only spaces
- C. Exactly one character
- D. Only digits
How do you check if a column has no value?
- A. = NULL
- B. == NULL
- C. IS EMPTY
- D. IS NULL (correct)
Which keyword limits the number of rows returned in PostgreSQL and MySQL?
- A. TOP 10 only
- B. MAXROWS
- C. FIRST
- D. LIMIT (correct)
Which statement creates a new table?
- A. ADD TABLE
- B. MAKE TABLE
- C. CREATE TABLE (correct)
- D. NEW TABLE
Which statement deletes a whole table, including its structure?
- A. DROP TABLE (correct)
- B. DELETE TABLE
- C. CLEAR TABLE
- D. REMOVE TABLE
What is a row in a table also called?
- A. A key
- B. A record (correct)
- C. A schema
- D. A field
Which clause groups rows that share a value so aggregates can be computed per group?
- A. GROUP BY (correct)
- B. ORDER BY
- C. CLUSTER
- D. PARTITION
Which clause filters groups after aggregation?
- A. FILTER
- B. LIMIT
- C. WHERE
- D. HAVING (correct)
What is the difference between WHERE and HAVING?
- A. HAVING runs first
- B. WHERE filters rows before grouping; HAVING filters groups after (correct)
- C. WHERE works only with aggregates
- D. They are identical
Which join returns all rows from the left table and matching rows from the right?
- A. LEFT JOIN (correct)
- B. CROSS JOIN
- C. INNER JOIN
- D. RIGHT JOIN only
What does an INNER JOIN return?
- A. Only rows with matching values in both tables (correct)
- B. The Cartesian product
- C. All rows from both tables
- D. All rows from the left table
What does a CROSS JOIN produce?
- A. Only unique rows
- B. Rows that do not match
- C. Only matching rows
- D. Every combination of rows from both tables (correct)
What does a FULL OUTER JOIN return?
- A. Only unmatched rows
- B. Only rows from the right table
- C. Only the first match
- D. All rows from both tables, matched where possible (correct)
What is a primary key?
- A. A column or set of columns that uniquely identifies each row (correct)
- B. A key used for encryption
- C. The first column of a table
- D. A column that allows duplicates
What is a foreign key?
- A. A unique index
- B. A column that references the primary key of another table (correct)
- C. A column with only NULL values
- D. A key from another database server
What does the UNIQUE constraint do?
- A. Prevents duplicate values in a column (correct)
- B. Encrypts the column
- C. Makes the column the primary key
- D. Sorts the column
What does the NOT NULL constraint do?
- A. Sets a default of 0
- B. Requires a value in every row for that column (correct)
- C. Makes the column optional
- D. Removes NULL rows
What does the DEFAULT constraint do?
- A. Prevents updates
- B. Supplies a value when none is given on insert (correct)
- C. Sorts new rows first
- D. Sets the primary key
What is the result of COUNT(column) when some values are NULL?
- A. It returns NULL
- B. It counts all rows
- C. It returns an error
- D. It counts only non-NULL values (correct)
Which statement adds a new column to an existing table?
- A. ALTER TABLE ... ADD COLUMN (correct)
- B. UPDATE TABLE ... ADD
- C. MODIFY TABLE ... NEW
- D. INSERT COLUMN
What does UNION do?
- A. Joins two tables by key
- B. Combines results and keeps duplicates
- C. Intersects two results
- D. Combines results of two queries and removes duplicates (correct)
How does UNION ALL differ from UNION?
- A. UNION ALL removes duplicates
- B. UNION ALL sorts results
- C. They are identical
- D. UNION ALL keeps duplicate rows (correct)
What is a subquery?
- A. A query nested inside another query (correct)
- B. A stored procedure
- C. A query on a sub-table
- D. A query with LIMIT
What does IN (1, 2, 3) check?
- A. Whether a list has 3 items
- B. Whether a value is between 1 and 3
- C. Whether the column is indexed
- D. Whether a value matches any value in the list (correct)
What does an index do?
- A. Speeds up lookups at the cost of extra storage and slower writes (correct)
- B. Encrypts a column
- C. Prevents duplicates always
- D. Sorts the table permanently
What does COALESCE(a, b, c) return?
- A. The first non-NULL value (correct)
- B. The last value
- C. NULL if any value is NULL
- D. The sum of the values
What is a view?
- A. A saved query that can be used like a table (correct)
- B. A copy of a table
- C. An index
- D. A backup
Which clause skips a number of rows before returning results?
- A. AFTER
- B. JUMP
- C. OFFSET (correct)
- D. SKIP
What does the CASE expression do?
- A. Creates a table
- B. Returns values based on conditions, like if/else (correct)
- C. Starts a transaction
- D. Changes text case
In SQL, what is an alias?
- A. A temporary name given to a table or column using AS (correct)
- B. An index name
- C. A copy of a table
- D. A user role
Which aggregate function ignores NULL values when adding?
- A. SUM() (correct)
- B. CONCAT()
- C. COUNT(*)
- D. ROW_NUMBER()
What is a transaction?
- A. A single SELECT
- B. A type of index
- C. A group of statements that succeed or fail as one unit (correct)
- D. A backup
Which command saves all changes in the current transaction?
- A. COMMIT (correct)
- B. SAVE
- C. ROLLBACK
- D. END CHANGES
Which command undoes the changes of the current transaction?
- A. ROLLBACK (correct)
- B. REVERT
- C. UNDO
- D. CANCEL
What does ACID stand for?
- A. Access, Control, Index, Database
- B. Atomic, Concurrent, Indexed, Durable
- C. Accuracy, Completeness, Integrity, Data
- D. Atomicity, Consistency, Isolation, Durability (correct)
What does a window function like ROW_NUMBER() OVER (ORDER BY score DESC) do?
- A. Deletes duplicate rows
- B. Numbers rows in order without collapsing them into groups (correct)
- C. Creates a view
- D. Groups rows into one
What is the difference between RANK() and DENSE_RANK()?
- A. They are identical
- B. RANK ignores ties
- C. RANK leaves gaps after ties; DENSE_RANK does not (correct)
- D. DENSE_RANK leaves gaps
What does PARTITION BY do in a window function?
- A. Splits rows into groups that the function runs over separately (correct)
- B. Splits a table across disks
- C. Sorts rows globally
- D. Removes rows
What is a correlated subquery?
- A. A subquery that returns one value only
- B. A subquery that refers to columns of the outer query and runs per row (correct)
- C. A subquery with a JOIN
- D. A subquery in the FROM clause
What is a CTE, written with WITH?
- A. A stored function
- B. A named temporary result set used within a single query (correct)
- C. A trigger
- D. A permanent table
What does a recursive CTE let you do?
- A. Query hierarchical data such as trees by repeatedly joining to itself (correct)
- B. Delete rows recursively
- C. Create tables in a loop
- D. Run queries in parallel
Which isolation level prevents dirty reads but allows non-repeatable reads?
- A. Repeatable Read only
- B. Read Uncommitted
- C. Serializable
- D. Read Committed (correct)
What is a dirty read?
- A. Reading from a backup
- B. Reading data without an index
- C. Reading deleted data
- D. Reading data written by a transaction that has not committed (correct)
What does EXPLAIN show?
- A. Query results
- B. The execution plan the database will use for a query (correct)
- C. The table structure
- D. Errors in the query
What does ON DELETE CASCADE do on a foreign key?
- A. Prevents deleting the parent
- B. Deletes child rows automatically when the parent row is deleted (correct)
- C. Sets the child column to NULL
- D. Deletes the whole table
What is the difference between DELETE and TRUNCATE?
- A. They are identical
- B. TRUNCATE quickly removes all rows without filtering; DELETE can remove selected rows (correct)
- C. DELETE drops the table
- D. TRUNCATE can use WHERE
What is SQL injection?
- A. A way to add rows quickly
- B. An attack that inserts malicious SQL through user input (correct)
- C. A database backup method
- D. An indexing technique
What is the best defence against SQL injection?
- A. Hiding error messages
- B. Longer table names
- C. Using uppercase SQL
- D. Parameterized queries (correct)
What does EXISTS (subquery) return?
- A. True if the subquery returns at least one row (correct)
- B. The first row
- C. True only if every row matches
- D. The number of rows
In SQL, what is NULL = NULL?
- A. Unknown (not true) (correct)
- B. True
- C. An error
- D. False only in MySQL
What does a composite primary key consist of?
- A. A key with text and numbers
- B. A primary key and a foreign key
- C. Two or more columns that together identify a row (correct)
- D. A hashed key