Bird
Raised Fist0
SQLquery~20 mins

DROP TABLE and ALTER TABLE in SQL - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
SQL Table Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate
2:00remaining
What is the result of dropping a table?

Consider a database with a table named Employees. What happens if you run the following SQL command?

DROP TABLE Employees;

What will be the state of the Employees table after this command?

AThe table <code>Employees</code> is permanently deleted along with all its data.
BThe table <code>Employees</code> is renamed to <code>Employees_backup</code>.
CThe table <code>Employees</code> remains but all data inside it is deleted.
DThe table <code>Employees</code> is locked and cannot be accessed.
Attempts:
2 left
💡 Hint

Think about what DROP means in SQL.

❓ query_result
intermediate
2:00remaining
What does this ALTER TABLE command do?

Given a table Products with columns id and name, what is the effect of this command?

ALTER TABLE Products ADD COLUMN price DECIMAL(10,2);
AAdds a new column named <code>price</code> to the <code>Products</code> table to store decimal numbers.
BDeletes the <code>price</code> column from the <code>Products</code> table.
CChanges the data type of the <code>name</code> column to decimal.
DRenames the <code>Products</code> table to <code>price</code>.
Attempts:
2 left
💡 Hint

Look at the keywords ADD COLUMN in the command.

📝 Syntax
advanced
2:00remaining
Which ALTER TABLE command correctly renames a column?

You want to rename the column old_name to new_name in the table Customers. Which of the following commands is correct in standard SQL?

AALTER TABLE Customers MODIFY COLUMN old_name new_name;
BALTER TABLE Customers RENAME COLUMN old_name TO new_name;
CALTER TABLE Customers CHANGE old_name new_name VARCHAR(255);
DALTER TABLE Customers RENAME old_name new_name;
Attempts:
2 left
💡 Hint

Standard SQL uses a specific syntax for renaming columns.

🔧 Debug
advanced
2:00remaining
Why does this DROP TABLE command fail?

Consider the command:

DROP TABLE Orders;

It fails with an error saying the table does not exist. What is the best way to avoid this error?

ARename the table before dropping it.
BUse <code>DELETE TABLE Orders;</code> instead of DROP.
CUse <code>DROP TABLE IF EXISTS Orders;</code> to drop only if the table exists.
DRestart the database server before running DROP.
Attempts:
2 left
💡 Hint

Check if the table exists before dropping it.

🧠 Conceptual
expert
3:00remaining
What happens when you drop a table with foreign key dependencies?

Table Orders has a foreign key referencing Customers. What happens if you run:

DROP TABLE Customers;

Assuming no special options are used, what is the expected outcome?

AThe <code>Customers</code> table is dropped but the <code>Orders</code> table remains with broken references.
BThe <code>Customers</code> table is dropped and all related <code>Orders</code> rows are deleted automatically.
CBoth tables are dropped automatically.
DThe command fails due to foreign key constraints preventing the drop.
Attempts:
2 left
💡 Hint

Think about referential integrity rules in relational databases.

Practice

(1/5)
1. What does the SQL command DROP TABLE do?
easy
A. Adds a new column to the table.
B. Changes the data type of a column.
C. Deletes the entire table and all its data permanently.
D. Renames the table without deleting data.

Solution

  1. Step 1: Understand the purpose of DROP TABLE

    The DROP TABLE command removes the whole table and all its data from the database permanently.
  2. Step 2: Compare with other commands

    ALTER TABLE changes structure but keeps data; DROP TABLE deletes everything.
  3. Final Answer:

    Deletes the entire table and all its data permanently. -> Option C
  4. Quick Check:

    DROP TABLE = Delete table and data [OK]
Hint: DROP TABLE removes table and data completely [OK]
Common Mistakes:
  • Thinking DROP TABLE only deletes data but keeps structure
  • Confusing DROP TABLE with ALTER TABLE
  • Assuming DROP TABLE can be undone easily
2. Which of the following is the correct syntax to add a new column named age of type INTEGER to a table called users?
easy
A. DROP TABLE users ADD COLUMN age INTEGER;
B. ALTER TABLE users ADD COLUMN age INTEGER;
C. ALTER TABLE users DROP COLUMN age INTEGER;
D. ALTER users ADD age INTEGER;

Solution

  1. Step 1: Identify correct ALTER TABLE syntax

    To add a column, use: ALTER TABLE table_name ADD COLUMN column_name data_type;
  2. Step 2: Check each option

    ALTER TABLE users ADD COLUMN age INTEGER; matches correct syntax; others misuse DROP or omit TABLE keyword.
  3. Final Answer:

    ALTER TABLE users ADD COLUMN age INTEGER; -> Option B
  4. Quick Check:

    ALTER TABLE ADD COLUMN = ALTER TABLE users ADD COLUMN age INTEGER; [OK]
Hint: Use ALTER TABLE ... ADD COLUMN to add columns [OK]
Common Mistakes:
  • Using DROP TABLE instead of ALTER TABLE
  • Omitting TABLE keyword after ALTER
  • Using ADD without COLUMN keyword
3. Given the table employees with columns id, name, and salary, what will be the result of this SQL command?
ALTER TABLE employees DROP COLUMN salary;
medium
A. The table employees will be deleted.
B. All data in the employees table will be deleted.
C. A new column named salary will be added.
D. The salary column will be removed from the employees table.

Solution

  1. Step 1: Understand ALTER TABLE DROP COLUMN

    This command removes the specified column from the table structure but keeps the table and other data intact.
  2. Step 2: Analyze options

    Only The salary column will be removed from the employees table. correctly describes removing the salary column; others describe deleting data or table, or adding columns.
  3. Final Answer:

    The salary column will be removed from the employees table. -> Option D
  4. Quick Check:

    ALTER TABLE DROP COLUMN removes column [OK]
Hint: ALTER TABLE DROP COLUMN removes only that column [OK]
Common Mistakes:
  • Thinking DROP COLUMN deletes all data
  • Confusing DROP COLUMN with DROP TABLE
  • Assuming DROP COLUMN adds a column
4. What is wrong with this SQL command?
ALTER TABLE customers DROP age;
medium
A. The command is missing the keyword COLUMN after DROP.
B. DROP cannot be used with ALTER TABLE.
C. The table name is incorrect.
D. The command should be DROP TABLE customers;

Solution

  1. Step 1: Check ALTER TABLE DROP syntax

    To remove a column, the syntax requires DROP COLUMN column_name, not just DROP column_name.
  2. Step 2: Validate other options

    DROP is valid with ALTER TABLE if used correctly; table name is correct; DROP TABLE deletes whole table, not column.
  3. Final Answer:

    The command is missing the keyword COLUMN after DROP. -> Option A
  4. Quick Check:

    ALTER TABLE DROP COLUMN required [OK]
Hint: Use DROP COLUMN, not just DROP, to remove columns [OK]
Common Mistakes:
  • Omitting COLUMN keyword after DROP
  • Confusing DROP TABLE with DROP COLUMN
  • Assuming DROP alone removes columns
5. You want to rename the column fullname to name in the table students. Which SQL command correctly does this in a standard way?
hard
A. ALTER TABLE students RENAME COLUMN fullname TO name;
B. ALTER TABLE students CHANGE fullname name VARCHAR(100);
C. DROP TABLE students RENAME COLUMN fullname TO name;
D. ALTER TABLE students DROP COLUMN fullname ADD COLUMN name VARCHAR(100);

Solution

  1. Step 1: Identify standard rename column syntax

    The standard SQL command to rename a column is ALTER TABLE table_name RENAME COLUMN old_name TO new_name;
  2. Step 2: Evaluate options

    ALTER TABLE students RENAME COLUMN fullname TO name; matches standard syntax; A wrongly uses DROP TABLE; B is MySQL-specific CHANGE syntax; D drops and adds column losing data.
  3. Final Answer:

    ALTER TABLE students RENAME COLUMN fullname TO name; -> Option A
  4. Quick Check:

    Rename column = ALTER TABLE RENAME COLUMN [OK]
Hint: Use ALTER TABLE RENAME COLUMN to rename columns safely [OK]
Common Mistakes:
  • Using DROP TABLE instead of ALTER TABLE
  • Dropping and adding columns loses data
  • Using non-standard syntax without checking compatibility
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard