Practice Questions — CREATE, ALTER, DROP Tables
← Back to NotesTopic-Specific Questions
Question 1
Easy
Write the ALTER statement to add a column
phone VARCHAR(15) to the employees table.ALTER TABLE ... ADD COLUMN ...
ALTER TABLE employees ADD COLUMN phone VARCHAR(15);Question 2
Easy
Write the ALTER statement to drop the
phone column from employees.DROP COLUMN.
ALTER TABLE employees DROP COLUMN phone;Question 3
Easy
Write the ALTER statement to change the
salary column type to DECIMAL(12, 2).MODIFY COLUMN.
ALTER TABLE employees MODIFY COLUMN salary DECIMAL(12, 2);Question 4
Easy
Write the ALTER statement to rename the column
department to dept in employees (MySQL 8.0+).RENAME COLUMN ... TO ...
ALTER TABLE employees RENAME COLUMN department TO dept;Question 5
Easy
Write the SQL to rename the
employees table to staff.Two ways to do this.
-- Way 1:
ALTER TABLE employees RENAME TO staff;
-- Way 2:
RENAME TABLE employees TO staff;Question 6
Easy
What is the difference between DELETE, TRUNCATE, and DROP in one sentence each?
Rows, table, WHERE clause.
DELETE removes specific rows matching a WHERE clause (transactional). TRUNCATE removes ALL rows quickly and resets AUTO_INCREMENT, but keeps the table. DROP removes the entire table — structure and data — permanently.
Question 7
Easy
Which of DELETE, TRUNCATE, and DROP can be used with a WHERE clause?
Only one.
Only DELETE supports a WHERE clause. TRUNCATE always empties the whole table; DROP removes the whole table.
Question 8
Medium
Write SQL to create a table
employees_archive that is a full copy (with data) of the employees table. You don't need to copy indexes.CREATE TABLE AS SELECT.
CREATE TABLE employees_archive AS
SELECT * FROM employees;Question 9
Medium
Write SQL to clone the
employees schema (structure, indexes, constraints) into a new empty table called employees_template.LIKE.
CREATE TABLE employees_template LIKE employees;Question 10
Medium
Write ALTER to add a named UNIQUE constraint
uq_email on the email column of employees.ADD CONSTRAINT.
ALTER TABLE employees
ADD CONSTRAINT uq_email UNIQUE (email);Question 11
Medium
Write ALTER to add a foreign key named
fk_manager on column manager_id referencing employees(emp_id).ADD CONSTRAINT ... FOREIGN KEY ... REFERENCES ...
ALTER TABLE employees
ADD CONSTRAINT fk_manager
FOREIGN KEY (manager_id) REFERENCES employees(emp_id);Question 12
Medium
Write a single ALTER statement that adds a
bonus DECIMAL(10,2) DEFAULT 0 column AND drops the hire_date column in one shot.Comma-separate multiple actions.
ALTER TABLE employees
ADD COLUMN bonus DECIMAL(10,2) DEFAULT 0,
DROP COLUMN hire_date;Question 13
Medium
After you TRUNCATE a table and insert a new row, what emp_id does it get if the previous max was 10?
TRUNCATE resets AUTO_INCREMENT.
1. TRUNCATE resets the AUTO_INCREMENT counter to its initial value (default 1).
Question 14
Medium
Is DELETE transactional (rollback-able) in MySQL? What about TRUNCATE?
Think DDL vs DML.
DELETE is DML and fully transactional — wrap it in START TRANSACTION ... ROLLBACK to undo. TRUNCATE is DDL with an implicit COMMIT — it cannot be rolled back in most databases including MySQL.
Question 15
Hard
Write a single DDL script that: 1) creates a
school database (if missing), 2) uses it, 3) creates a students table with id (auto PK), name NOT NULL, email UNIQUE NOT NULL, 4) then adds a new dob DATE column, 5) renames email to email_id, 6) drops the table cleanly.CREATE, ALTER several times, DROP.
CREATE DATABASE IF NOT EXISTS school;
USE school;
DROP TABLE IF EXISTS students;
CREATE TABLE students (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
email VARCHAR(100) NOT NULL UNIQUE
);
ALTER TABLE students ADD COLUMN dob DATE;
ALTER TABLE students RENAME COLUMN email TO email_id;
DROP TABLE students;Question 16
Hard
Create a
TEMPORARY table called top_earners containing only employees earning more than 80000. Then count how many there are.CREATE TEMPORARY TABLE ... AS SELECT ...
CREATE TEMPORARY TABLE top_earners AS
SELECT * FROM employees WHERE salary > 80000;
SELECT COUNT(*) AS total_top FROM top_earners;Question 17
Hard
Why might an ALTER TABLE on a 100M-row table be dangerous in production?
Locks and rebuilds.
Many ALTERs require a full table rebuild, which locks the table (or at least blocks writes) for minutes to hours. On a busy production DB, this means your app hangs or errors for the duration. Modern MySQL 8.0 supports online DDL for many cases (ADD INDEX, ADD COLUMN) but not all.
Question 18
Hard
Write a robust "reset" script for a
test_orders table. It should: drop the table if it exists, create it fresh with an AUTO_INCREMENT PK, customer VARCHAR(50) required, amount DECIMAL(10,2) positive, and insert three sample rows.IF EXISTS, IF NOT EXISTS, CHECK.
DROP TABLE IF EXISTS test_orders;
CREATE TABLE test_orders (
order_id INT AUTO_INCREMENT PRIMARY KEY,
customer VARCHAR(50) NOT NULL,
amount DECIMAL(10,2) NOT NULL CHECK (amount > 0),
order_date DATETIME DEFAULT CURRENT_TIMESTAMP
);
INSERT INTO test_orders (customer, amount) VALUES
('Aarav Sharma', 1200.50),
('Priya Iyer', 850.00),
('Rohan Verma', 2499.99);
SELECT * FROM test_orders;Question 19
Hard
You want to remove the PRIMARY KEY from the employees table entirely (rare, but sometimes needed for schema redesign). How?
ALTER TABLE ... DROP PRIMARY KEY.
ALTER TABLE employees DROP PRIMARY KEY;Question 20
Hard
Your colleague runs
TRUNCATE TABLE orders but it fails with a foreign key error. Why, and how do you fix it?orders is referenced by another table.
TRUNCATE cannot run if another table has a FOREIGN KEY referencing orders. Fix options: (1) TRUNCATE the child tables first, (2) temporarily disable FK checks with
SET FOREIGN_KEY_CHECKS = 0;, then TRUNCATE, then re-enable, or (3) use DELETE FROM orders; which respects FK cascading behavior.Mixed & Application Questions
Question 1
Easy
Complete the table: for each of DELETE, TRUNCATE, DROP, say which one (a) keeps the table, (b) resets AUTO_INCREMENT, (c) supports WHERE.
Three statements.
(a) Keeps the table: DELETE and TRUNCATE (DROP removes it). (b) Resets AUTO_INCREMENT: TRUNCATE only. (c) Supports WHERE: DELETE only.
Question 2
Easy
Write SQL to add a column
joining_bonus DECIMAL(8,2) DEFAULT 0 to an existing employees table.ADD COLUMN with DEFAULT.
ALTER TABLE employees
ADD COLUMN joining_bonus DECIMAL(8,2) DEFAULT 0;Question 3
Medium
Find the bug:
CREATE TABLE users (
id INT AUTO_INCREMENT,
email VARCHAR(100) UNIQUE
);AUTO_INCREMENT needs what?
AUTO_INCREMENT column must be a key (usually PRIMARY KEY). As written, MySQL errors: "Incorrect table definition; there can be only one auto column and it must be defined as a key".
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
email VARCHAR(100) UNIQUE
);Question 4
Medium
Write ALTER to change the
dept column so it can no longer be NULL. Assume all current rows already have a value.MODIFY COLUMN ... NOT NULL.
ALTER TABLE employees
MODIFY COLUMN dept VARCHAR(30) NOT NULL;Question 5
Medium
After running these statements, how many rows are in the table?
-- employees has 4 rows (emp_ids 1-4)
DELETE FROM employees WHERE emp_id = 2;
INSERT INTO employees (name, email, dept, salary) VALUES
('Diya', 'diya@corp.in', 'HR', 50000);
TRUNCATE TABLE employees;
INSERT INTO employees (name, email, dept, salary) VALUES
('Meera', 'meera@corp.in', 'IT', 70000);TRUNCATE wipes everything.
1 row (just Meera). The DELETE and the first INSERT are undone by TRUNCATE. Only the final INSERT after TRUNCATE survives.
Question 6
Medium
When would you use CREATE TEMPORARY TABLE instead of a regular CREATE TABLE?
Session-scoped, auto-cleanup.
Use TEMPORARY when (1) you need intermediate staging for a multi-step query or report and don't want the table to linger; (2) different concurrent sessions need their own private version of the same-named table (temporary tables are session-local); (3) you want the table to auto-drop when you disconnect.
Question 7
Hard
Fix the script so it can run multiple times without errors:
CREATE DATABASE shop;
USE shop;
CREATE TABLE products (
id INT PRIMARY KEY,
name VARCHAR(50)
);IF NOT EXISTS and IF EXISTS.
CREATE DATABASE IF NOT EXISTS shop;
USE shop;
DROP TABLE IF EXISTS products;
CREATE TABLE products (
id INT PRIMARY KEY,
name VARCHAR(50)
);Question 8
Hard
Why is TRUNCATE categorized as DDL even though conceptually it only removes data?
Internal implementation.
TRUNCATE works by dropping and recreating the table internally — a structural operation. That is DDL behavior. Side effects: it resets AUTO_INCREMENT, implicitly commits, cannot be rolled back in most databases, and doesn't fire row-level triggers.
Question 9
Hard
Write a script that: 1) creates an
audit_log table, 2) adds a column severity ENUM('low','medium','high') NOT NULL DEFAULT 'low', 3) creates a UNIQUE index on (user_id, event_time).CREATE + ALTER + CREATE INDEX.
CREATE TABLE audit_log (
log_id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
event_time DATETIME NOT NULL,
action VARCHAR(100) NOT NULL
);
ALTER TABLE audit_log
ADD COLUMN severity ENUM('low','medium','high') NOT NULL DEFAULT 'low';
CREATE UNIQUE INDEX uq_user_event
ON audit_log (user_id, event_time);Question 10
Hard
After
DROP TABLE employees;, can you recover the data without a backup?Depends on the storage engine and setup.
Usually no. DROP TABLE is immediate and irreversible in standard MySQL. Recovery requires a backup (mysqldump, binary backup) taken before the drop. Some enterprise tools can read the raw InnoDB tablespace, but success is never guaranteed.
Question 11
Hard
Clone the employees table's structure AND data into a new table
employees_2026_q1.Two steps: LIKE + INSERT SELECT.
CREATE TABLE employees_2026_q1 LIKE employees;
INSERT INTO employees_2026_q1 SELECT * FROM employees;Question 12
Hard
Why does MySQL usually lock a table during ALTER TABLE, and how is this handled in modern versions?
Online DDL.
Historically, ALTER forced a full table copy: MySQL created a shadow copy, applied changes, then swapped. This blocked writes (sometimes reads). MySQL 5.6+ introduced Online DDL: many operations (ADD INDEX, ADD COLUMN, DROP COLUMN on newer versions) now run concurrently with reads and writes. Still, certain ALTERs (changing PK, some MODIFY COLUMN cases) fall back to the blocking copy.
Multiple Choice Questions
MCQ 1
Which command removes the entire table including its structure?
Answer: C
C is correct. DROP TABLE permanently removes the table and its data. DELETE and TRUNCATE keep the table's structure. REMOVE TABLE is not a valid command.
C is correct. DROP TABLE permanently removes the table and its data. DELETE and TRUNCATE keep the table's structure. REMOVE TABLE is not a valid command.
MCQ 2
Which ALTER command adds a new column?
Answer: A
A is correct.
A is correct.
ADD COLUMN is the standard syntax. The word COLUMN is optional in MySQL but considered good practice for portability.MCQ 3
Which command empties a table quickly and resets AUTO_INCREMENT?
Answer: B
B is correct. TRUNCATE empties the table and resets AUTO_INCREMENT to 1. DELETE keeps the counter. DROP removes the table entirely.
B is correct. TRUNCATE empties the table and resets AUTO_INCREMENT to 1. DELETE keeps the counter. DROP removes the table entirely.
MCQ 4
Which command deletes only rows where department = 'HR'?
Answer: C
C is correct. Only DELETE supports a WHERE clause. TRUNCATE always wipes all rows. DROP removes the table. REMOVE FROM is not valid SQL.
C is correct. Only DELETE supports a WHERE clause. TRUNCATE always wipes all rows. DROP removes the table. REMOVE FROM is not valid SQL.
MCQ 5
Which modifier makes CREATE TABLE safely re-runnable?
Answer: B
B is correct.
B is correct.
CREATE TABLE IF NOT EXISTS t (...) is a no-op if the table already exists. OR REPLACE works in MariaDB and some other databases but not standard MySQL.MCQ 6
Which ALTER renames a table from
employees to staff?Answer: C
C is correct. Both ALTER TABLE ... RENAME TO and RENAME TABLE are valid MySQL syntax. RENAME TABLE is atomic and can rename multiple tables in one statement.
C is correct. Both ALTER TABLE ... RENAME TO and RENAME TABLE are valid MySQL syntax. RENAME TABLE is atomic and can rename multiple tables in one statement.
MCQ 7
Which ALTER removes a column called phone?
Answer: B
B is correct.
B is correct.
DROP COLUMN is the standard syntax. REMOVE and DELETE COLUMN are not valid.MCQ 8
After
TRUNCATE TABLE employees;, the next INSERT for a table with AUTO_INCREMENT starting at 1 gets which id?Answer: B
B is correct. TRUNCATE resets AUTO_INCREMENT to the initial value (default 1), so the next insert gets id = 1. This differs from DELETE, which keeps the counter.
B is correct. TRUNCATE resets AUTO_INCREMENT to the initial value (default 1), so the next insert gets id = 1. This differs from DELETE, which keeps the counter.
MCQ 9
Which is TRUE about DROP TABLE?
Answer: C
C is correct. DROP removes the table entirely. It cannot be rolled back (auto-commit), doesn't support WHERE, and doesn't keep the structure.
C is correct. DROP removes the table entirely. It cannot be rolled back (auto-commit), doesn't support WHERE, and doesn't keep the structure.
MCQ 10
Which statement about CREATE TABLE AS SELECT is TRUE?
Answer: B
B is correct. CTAS copies columns and data but NOT indexes, PKs, FKs, or AUTO_INCREMENT. To clone full schema use
B is correct. CTAS copies columns and data but NOT indexes, PKs, FKs, or AUTO_INCREMENT. To clone full schema use
CREATE TABLE new_t LIKE old_t;.MCQ 11
Which command disables FOREIGN KEY enforcement for the current session in MySQL?
Answer: A
A is correct.
A is correct.
SET FOREIGN_KEY_CHECKS = 0; temporarily turns off FK validation. Set it back to 1 to re-enable. Use sparingly; can create orphan rows.MCQ 12
Which ALTER makes the
name column NOT NULL (it was previously nullable)?Answer: B
B is correct. MODIFY COLUMN takes the full new definition of the column. You must repeat the type even if only the nullability changes. Fails if existing rows have NULL — update them first.
B is correct. MODIFY COLUMN takes the full new definition of the column. You must repeat the type even if only the nullability changes. Fails if existing rows have NULL — update them first.
MCQ 13
What does
CREATE TEMPORARY TABLE do?Answer: B
B is correct. TEMPORARY tables are session-local and auto-drop when the connection ends. Two different sessions can have TEMPORARY tables with the same name without conflict.
B is correct. TEMPORARY tables are session-local and auto-drop when the connection ends. Two different sessions can have TEMPORARY tables with the same name without conflict.
MCQ 14
Which is NOT a valid reason to prefer TRUNCATE over DELETE?
Answer: C
C is correct (it is NOT a valid reason). TRUNCATE cannot be rolled back in most databases including MySQL — this is a reason AGAINST TRUNCATE, not for it. A, B, and D are all genuine reasons to pick TRUNCATE.
C is correct (it is NOT a valid reason). TRUNCATE cannot be rolled back in most databases including MySQL — this is a reason AGAINST TRUNCATE, not for it. A, B, and D are all genuine reasons to pick TRUNCATE.
MCQ 15
You run:
CREATE TABLE t2 LIKE t1; followed by INSERT INTO t2 SELECT * FROM t1;. What does t2 have that CTAS would have missed?Answer: B
B is correct.
B is correct.
CREATE TABLE LIKE copies the full schema including PKs, indexes, and AUTO_INCREMENT. CTAS copies only columns and data. That's why LIKE + INSERT is the preferred clone.MCQ 16
Why might
ALTER TABLE employees DROP COLUMN salary; fail?Answer: D
D is correct. All three can cause failure: column doesn't exist, it's part of an index/constraint that must be dropped first, or another table's FK points to it (rare for non-PK columns but possible with composite FKs).
D is correct. All three can cause failure: column doesn't exist, it's part of an index/constraint that must be dropped first, or another table's FK points to it (rare for non-PK columns but possible with composite FKs).
MCQ 17
Which statement about DELETE in MySQL is TRUE?
Answer: C
C is correct. DELETE is DML and fully transactional. Wrap it in START TRANSACTION ... ROLLBACK to undo. A is false (DELETE doesn't implicitly commit). B is false (DELETE fires triggers). D is false (only TRUNCATE resets AUTO_INCREMENT).
C is correct. DELETE is DML and fully transactional. Wrap it in START TRANSACTION ... ROLLBACK to undo. A is false (DELETE doesn't implicitly commit). B is false (DELETE fires triggers). D is false (only TRUNCATE resets AUTO_INCREMENT).
MCQ 18
Which syntax correctly adds a composite UNIQUE constraint on (first_name, last_name)?
Answer: C
C is correct. Both forms work. Option B with an explicit constraint name is preferred because you can later DROP the constraint by name:
C is correct. Both forms work. Option B with an explicit constraint name is preferred because you can later DROP the constraint by name:
ALTER TABLE t DROP INDEX uq_name;.MCQ 19
Which of these single ALTER statements is valid?
Answer: A
A is correct. Multiple changes in one ALTER are comma-separated and faster than running separate ALTERs. The others are invalid syntax.
A is correct. Multiple changes in one ALTER are comma-separated and faster than running separate ALTERs. The others are invalid syntax.
MCQ 20
You need to change
emp_id from INT to BIGINT on a 50M-row table. What should you be aware of?Answer: B
B is correct. Changing a column type typically rebuilds the table, which can lock writes for minutes or hours on big tables. MySQL 8.0 supports online DDL for many operations, but not all type changes. Tools like pt-online-schema-change handle this without downtime.
B is correct. Changing a column type typically rebuilds the table, which can lock writes for minutes or hours on big tables. MySQL 8.0 supports online DDL for many operations, but not all type changes. Tools like pt-online-schema-change handle this without downtime.
Coding Challenges
Challenge 1: Safe Reset Script
EasyWrite a re-runnable script that: drops the
products table if it exists; creates it with id (AUTO_INCREMENT PK), name NOT NULL (up to 80 chars), price DECIMAL(10,2) > 0; inserts three products; ends with a COUNT.Sample Input
(No input)
Sample Output
Creates fresh table, inserts 3 rows, COUNT = 3. Safe to re-run.
Use IF EXISTS on the DROP.
DROP TABLE IF EXISTS products;
CREATE TABLE products (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(80) NOT NULL,
price DECIMAL(10,2) NOT NULL CHECK (price > 0)
);
INSERT INTO products (name, price) VALUES
('Wireless Mouse', 799.00),
('Mechanical Keyboard', 4999.00),
('USB-C Charger', 1299.50);
SELECT COUNT(*) AS total FROM products;
-- Output:
-- +-------+
-- | total |
-- +-------+
-- | 3 |
-- +-------+Challenge 2: ALTER Multiple Things in One Shot
EasyGiven an employees table with columns (emp_id, name, department, salary), write ONE ALTER TABLE that does all three: add a
bonus DECIMAL(8,2) DEFAULT 0 column, rename department to dept, and modify name to VARCHAR(80) NOT NULL.Sample Input
(No input)
Sample Output
A single ALTER statement that applies all three changes.
One statement only.
ALTER TABLE employees
ADD COLUMN bonus DECIMAL(8,2) DEFAULT 0,
RENAME COLUMN department TO dept,
MODIFY COLUMN name VARCHAR(80) NOT NULL;
DESCRIBE employees;
-- Expected structure:
-- emp_id (PK), name VARCHAR(80) NOT NULL, dept VARCHAR(30),
-- salary DECIMAL(10,2), bonus DECIMAL(8,2) DEFAULT 0.Challenge 3: DELETE vs TRUNCATE vs DROP Demo
MediumBuild a small demo: create a products table with 5 rows; use DELETE to remove two rows; use TRUNCATE to wipe the rest; finally, DROP the table. Show the row count after each step using SELECT COUNT(*).
Sample Input
(No input)
Sample Output
5 -> 3 -> 0 -> error (table dropped).
Use all three commands.
DROP TABLE IF EXISTS products;
CREATE TABLE products (
id INT PRIMARY KEY,
name VARCHAR(50),
price DECIMAL(10,2)
);
INSERT INTO products VALUES
(1, 'Pen', 10.00),
(2, 'Notebook', 55.00),
(3, 'Bag', 499.00),
(4, 'Bottle', 199.00),
(5, 'Mug', 149.00);
SELECT COUNT(*) AS step1 FROM products; -- 5
DELETE FROM products WHERE price < 100; -- removes Pen and Notebook
SELECT COUNT(*) AS step2 FROM products; -- 3
TRUNCATE TABLE products;
SELECT COUNT(*) AS step3 FROM products; -- 0
DROP TABLE products;
-- SELECT COUNT(*) FROM products; -- would ERROR: Table doesn't existChallenge 4: Backup Before Risky Change
MediumYour manager asks you to drop the column
legacy_code from customers, but warns "back it up first". Write SQL that: 1) creates a FULL schema+data backup of customers named customers_backup_20260411, 2) drops the legacy_code column from customers.Sample Input
(No input)
Sample Output
backup exists with same rows; original customers has legacy_code removed.
Use the 2-step schema clone method (LIKE + INSERT SELECT).
-- 1) Full backup (schema + data)
DROP TABLE IF EXISTS customers_backup_20260411;
CREATE TABLE customers_backup_20260411 LIKE customers;
INSERT INTO customers_backup_20260411 SELECT * FROM customers;
-- 2) Proceed with risky change on the live table
ALTER TABLE customers DROP COLUMN legacy_code;
-- Verify
SELECT COUNT(*) AS backup_rows FROM customers_backup_20260411;
DESCRIBE customers;
-- If anything goes wrong, we can restore from customers_backup_20260411.Challenge 5: Constraint Rescue
HardAn existing
orders table has no constraints. Add a PRIMARY KEY on order_id, a FOREIGN KEY emp_id referencing employees(emp_id), a CHECK that amount > 0, and a UNIQUE index on (emp_id, order_date). Assume the table exists with order_id, emp_id, amount, order_date columns.Sample Input
(No input)
Sample Output
Four constraints added. DESCRIBE shows PRI/UNI/MUL keys.
Use named constraints for easier rollback.
ALTER TABLE orders
ADD CONSTRAINT pk_orders PRIMARY KEY (order_id),
ADD CONSTRAINT fk_emp FOREIGN KEY (emp_id) REFERENCES employees(emp_id),
ADD CONSTRAINT chk_amount CHECK (amount > 0),
ADD CONSTRAINT uq_emp_date UNIQUE (emp_id, order_date);
DESCRIBE orders;
-- Expected keys: order_id (PRI), emp_id (MUL), (emp_id, order_date) UNIQUE composite
-- If something fails (e.g., existing rows violate the CHECK),
-- you can drop a specific constraint by name:
-- ALTER TABLE orders DROP CHECK chk_amount;
-- ALTER TABLE orders DROP FOREIGN KEY fk_emp;Challenge 6: Zero-Downtime Rename Simulation
HardSimulate a zero-downtime rename of the employees table to staff, using a view as a backward-compatibility shim. Write: 1) a script that renames employees to staff, 2) creates a VIEW called employees that SELECTs from staff (so old code still works), 3) shows that SELECT * FROM employees still returns data.
Sample Input
(No input)
Sample Output
The table is now named staff, but queries against employees still work through the view.
Use RENAME TABLE and CREATE VIEW.
-- Step 1: rename the physical table
RENAME TABLE employees TO staff;
-- Step 2: create a view with the old name for backward compatibility
CREATE OR REPLACE VIEW employees AS
SELECT * FROM staff;
-- Step 3: verify both names still work
SELECT COUNT(*) AS via_new_name FROM staff;
SELECT COUNT(*) AS via_old_name FROM employees;
-- Both counts should match.
--
-- This is the pattern big companies use during rename migrations:
-- rename the table, keep a view with the old name so existing app code keeps working,
-- then gradually update call sites over several releases, and finally drop the view.
--
-- Once all call sites are updated:
-- DROP VIEW employees;Need to Review the Concepts?
Go back to the detailed notes for this chapter.
Read Chapter NotesWant to master SQL and databases with a mentor?
Explore our MySQL Masterclass