Tables, Keys & Constraints · Question 18 · Hard
The status column has a DEFAULT, but this INSERT passes NULL for it explicitly. What does the final SELECT return?
CREATE TABLE Orders (
id INT PRIMARY KEY,
item VARCHAR(20),
status VARCHAR(10) DEFAULT 'NEW'
);
INSERT INTO Orders (id, item, status) VALUES (2, 'Saree', NULL);
SELECT status FROM Orders WHERE id = 2;
- NEW
- Saree
- NULL
- Nothing: the INSERT fails, because NULL conflicts with the DEFAULT
Answer and explanation
Answer: C. NULL
Explanation: A DEFAULT is used only when the column is left out of the INSERT (or the keyword DEFAULT is written). An explicit NULL is a supplied value, and since the column is not declared NOT NULL, NULL is stored.
Previous: Emp.dept_id is declared as FOREIGN KEY REFERENCES Dept(id) with no ON DELETE… · Next: The four INSERT statements run one after another. Which of them is the first…
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
- A table Orders with 50 lakh rows is searched very often by customer_id, so an…
- The second INSERT passes NULL as the price. What does the final SELECT return?
- Emp.dept_id is declared as FOREIGN KEY REFERENCES Dept(id) with no ON DELETE…
- The four INSERT statements run one after another. Which of them is the first…
- In standard SQL, which column(s) of the parent table may a FOREIGN KEY…
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