Tables, Keys & Constraints · Question 9 · Medium
Tables, Keys & Constraints question 9
Table Member:
id | name
1 | Asha
2 | Bala
The table Member below already has two rows when these statements run. What does the SELECT return?
ALTER TABLE Member ADD COLUMN city VARCHAR(20) DEFAULT 'Pune';
SELECT name, city FROM Member ORDER BY id;
- Asha, NULL; Bala, NULL
- No rows, because ALTER TABLE empties the table
- Asha, Pune; Bala, Pune
- Asha, Pune; Bala, NULL
Answer and explanation
Answer: C. Asha, Pune; Bala, Pune
Explanation: ALTER TABLE ... ADD COLUMN keeps the existing rows. When the new column has a DEFAULT, every existing row gets that default value in it; without a DEFAULT they would get NULL.
Previous: In PostgreSQL, MySQL and SQLite, which follow the SQL standard on this point… · Next: Table Dept has rows (1, IT) and (2, HR). Table Emp has rows (10, Kiran, dept…
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
- Which statement can remove only those rows of a table that satisfy a…
- What happens when the INSERT with a price of -50 runs?
- In PostgreSQL, MySQL and SQLite, which follow the SQL standard on this point…
- Table Dept has rows (1, IT) and (2, HR). Table Emp has rows (10, Kiran, dept…
- Table Team has rows (1, Mumbai) and (2, Chennai). Table Player has rows…
- Table Emp: id | name | salary 1 | Asha | 42000 2 | Bala | 65000 3 | Chirag |…
- Table Emp: id | name | salary 1 | Asha | 42000 2 | Bala | 65000 3 | Chirag |…
- The primary key below is made of two columns. What does the final SELECT return?
- 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?
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