Curated · Integrity Constraints

NAT · 1 mark · Problem DBMS-SQL-0365

A table is created asCREATE TABLE T (x INT CHECK (x BETWEEN 1 AND 10), y VARCHAR(5) UNIQUE);The following inserts run one after another on the empty table. An insert that violates a constraint is rejected and the others are kept.I1: INSERT INTO T VALUES (5, 'p');I2: INSERT INTO T VALUES (NULL, 'q');I3: INSERT INTO T VALUES (0, 'r');I4: INSERT INTO T VALUES (7, NULL);I5: INSERT INTO T VALUES (8, NULL);I6: INSERT INTO T VALUES (10, 'p');I7: INSERT INTO T VALUES (NULL, NULL);The number of rows in T at the end is .

Numerical answer (NAT).

Solve it on GATE DA practice →More Relational Model & SQL problems

Show the worked solution\[\boxed{\text{CHECK fails only when its condition is FALSE;}\ \ \text{UNIQUE ignores NULLs}}\]I1 kept. I2 kept: \(\text{NULL BETWEEN 1 AND 10}\) is UNKNOWN, which does not violate a CHECK.I3 rejected: \(0\) is outside \([1, 10]\).I4, I5 kept: NULLs are never equal to each other, so several NULLs in a UNIQUE column are allowed.I6 rejected: \(y = \text{'p'}\) already exists. I7 kept.Rows: I1, I2, I4, I5, I7.Answer: 5

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com