Tables, Keys & Constraints · Question 2 · Easy

What happens when the last statement runs?

CREATE TABLE Student (
  roll INT PRIMARY KEY,
  name VARCHAR(30)
);
INSERT INTO Student VALUES (1, 'Asha');
INSERT INTO Student VALUES (1, 'Bala');
  1. It succeeds, and the table has two rows with roll 1
  2. It succeeds, and Bala replaces Asha in the row with roll 1
  3. It fails, because roll 1 already exists and a PRIMARY KEY cannot repeat
  4. It succeeds, but roll is stored as NULL for Bala
Answer and explanation

Answer: C. It fails, because roll 1 already exists and a PRIMARY KEY cannot repeat

Explanation: A PRIMARY KEY must be unique. The second INSERT repeats roll 1, so the database rejects it and the table keeps only Asha's row.

Previous: A table Student(roll, name) already holds data. Which statement adds a new… · Next: What does the final SELECT return?

Practise tables, keys & constraints

Try a fresh set of tables, keys & constraints questions with an explanation after every answer, free and without signing up: Tables, Keys & Constraints practice. Or sit a full placement mock test.

More tables, keys & constraints questions

More sql practice

DML & Transactions · SELECT, WHERE & ORDER BY · SQL Joins · Aggregates & GROUP BY · Subqueries & CTEs · Window Functions · NULL Handling · SQL Functions & CASE

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge