0
0
SQLquery~20 mins

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

Choose your learning style9 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.