Tables, Keys & Constraints · Question 14 · Medium

The primary key below is made of two columns. What does the final SELECT return?

CREATE TABLE Enrolment (
  roll INT,
  course VARCHAR(10),
  PRIMARY KEY (roll, course)
);
INSERT INTO Enrolment VALUES (1, 'DBMS');
INSERT INTO Enrolment VALUES (1, 'OS');
INSERT INTO Enrolment VALUES (2, 'DBMS');
SELECT COUNT(*) FROM Enrolment;
  1. 1
  2. 2
  3. 0
  4. 3
Answer and explanation

Answer: D. 3

Explanation: With a composite primary key, the combination (roll, course) must be unique, not each column alone. (1, DBMS), (1, OS) and (2, DBMS) are three different pairs, so all three rows are accepted.

Previous: Table Emp: id | name | salary 1 | Asha | 42000 2 | Bala | 65000 3 | Chirag |… · Next: A table Orders with 50 lakh rows is searched very often by customer_id, so an…

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