-
Which statement removes only one particular student from the students table?
- DELETE FROM students WHERE student_id = 9;
- DROP TABLE students;
- DELETE FROM students;
- UPDATE students SET name = NULL;
Show answer
Answer: A · DELETE FROM students WHERE student_id = 9;
DELETE with a WHERE clause removes just the matching row. Without WHERE it empties the table, and DROP TABLE removes the table itself.
-
Which data type is best for storing a fee such as 1499.50 exactly?
- FLOAT
- VARCHAR(10)
- DECIMAL(10,2)
- DATE
Show answer
Answer: C · DECIMAL(10,2)
DECIMAL stores exact numbers with a fixed number of decimal places, which money needs. FLOAT is approximate, and text cannot be added or averaged properly.
-
A table has 5 rows and 2 of them have NULL in the city column. What do COUNT(*) and COUNT(city) return?
- 5 and 5
- 3 and 3
- 5 and 2
- 5 and 3
Show answer
Answer: D · 5 and 3
COUNT(*) counts all rows, so it returns 5. COUNT(city) counts only the rows where city is not NULL, which is 3.
-
Many teachers teach many classes, and every class has many teachers. How should this relationship be stored?
- Put a class_id column in the teachers table
- Put a teacher_id column in the classes table
- Create a third table that holds teacher_id and class_id
- Store a list of class names in one teachers column
Show answer
Answer: C · Create a third table that holds teacher_id and class_id
A many-to-many relationship needs a junction table with a foreign key to each side. A single foreign key can only express one-to-many, and a list in a cell breaks first normal form.
-
An employees table has emp_id as the key and the columns name, dept_id and dept_name. The dept_name is fixed by dept_id. Which normal form does this break?
- First normal form
- Second normal form, because the key has two columns
- Third normal form, because of a transitive dependency
- None, because dept_name is a plain column
Show answer
Answer: C · Third normal form, because of a transitive dependency
The key is a single column, so there is no partial dependency. But emp_id determines dept_id and dept_id determines dept_name, a transitive dependency that third normal form forbids.
-
The students table has 8 rows and the marks table has 21 rows. One student has no marks. How many rows does students INNER JOIN marks ON the student ids give?
- 8
- 21
- 22
- 168
Show answer
Answer: B · 21
Each of the 21 marks rows matches exactly one student, and the student without marks has no match. A LEFT JOIN would give 22, and a join with no condition would give 8 times 21, which is 168.
-
A power cut happens one second after COMMIT. When the server restarts, the committed transfer is still there. Which ACID property is responsible?
- Durability
- Atomicity
- Isolation
- Consistency
Show answer
Answer: A · Durability
Durability promises that committed changes survive crashes, because the database writes them to a log on disk before it confirms the commit.
-
Which statement about a view is true?
- A view stores its own copy of the data and must be refreshed by hand
- A view can only be created for a single table
- A view always runs faster than the same query
- A view stores a query, and the data comes from the underlying tables each time
Show answer
Answer: D · A view stores a query, and the data comes from the underlying tables each time
A view is a saved SELECT. It holds no rows of its own, so reading it always reflects the current data in the base tables.
-
Which statement correctly separates BCNF from third normal form?
- BCNF requires the left side of every dependency to be a candidate key, while 3NF also allows a dependency whose right side is part of a key
- BCNF allows partial dependencies, while 3NF does not
- BCNF is the same as first normal form with a primary key
- BCNF removes the need for foreign keys
Show answer
Answer: A · BCNF requires the left side of every dependency to be a candidate key, while 3NF also allows a dependency whose right side is part of a key
BCNF is the stricter rule: every determinant must be a candidate key. Third normal form has an extra allowance for right-hand sides that belong to some candidate key, so a few tables pass 3NF but fail BCNF.
-
With MySQL in its default autocommit mode, you run an UPDATE and then, without START TRANSACTION, run ROLLBACK. What happens?
- The UPDATE is undone
- The UPDATE is undone only if it changed one row
- The UPDATE stays, because it was already committed automatically
- MySQL reports an error and closes the connection
Show answer
Answer: C · The UPDATE stays, because it was already committed automatically
In autocommit mode every statement is committed as soon as it finishes. ROLLBACK can only undo work inside a transaction opened with START TRANSACTION or by turning autocommit off.
Want to test yourself? Take the same questions as a timed practice test and see your score. Start the practice test