Skip to content
VJ Classes

One place to learn science, commerce, arts, computers and life skills

10 questions. Think of your answer first, then open “Show answer”.

  1. Which statement removes only one particular student from the students table?

    1. DELETE FROM students WHERE student_id = 9;
    2. DROP TABLE students;
    3. DELETE FROM students;
    4. 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.

  2. Which data type is best for storing a fee such as 1499.50 exactly?

    1. FLOAT
    2. VARCHAR(10)
    3. DECIMAL(10,2)
    4. 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.

  3. A table has 5 rows and 2 of them have NULL in the city column. What do COUNT(*) and COUNT(city) return?

    1. 5 and 5
    2. 3 and 3
    3. 5 and 2
    4. 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.

  4. Many teachers teach many classes, and every class has many teachers. How should this relationship be stored?

    1. Put a class_id column in the teachers table
    2. Put a teacher_id column in the classes table
    3. Create a third table that holds teacher_id and class_id
    4. 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.

  5. 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?

    1. First normal form
    2. Second normal form, because the key has two columns
    3. Third normal form, because of a transitive dependency
    4. 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.

  6. 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?

    1. 8
    2. 21
    3. 22
    4. 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.

  7. A power cut happens one second after COMMIT. When the server restarts, the committed transfer is still there. Which ACID property is responsible?

    1. Durability
    2. Atomicity
    3. Isolation
    4. 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.

  8. Which statement about a view is true?

    1. A view stores its own copy of the data and must be refreshed by hand
    2. A view can only be created for a single table
    3. A view always runs faster than the same query
    4. 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.

  9. Which statement correctly separates BCNF from third normal form?

    1. 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
    2. BCNF allows partial dependencies, while 3NF does not
    3. BCNF is the same as first normal form with a primary key
    4. 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.

  10. With MySQL in its default autocommit mode, you run an UPDATE and then, without START TRANSACTION, run ROLLBACK. What happens?

    1. The UPDATE is undone
    2. The UPDATE is undone only if it changed one row
    3. The UPDATE stays, because it was already committed automatically
    4. 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