Recall & Review
beginner
What does the SQL command
DROP TABLE do?The
DROP TABLE command deletes an entire table and all its data permanently from the database.Click to reveal answer
beginner
How do you add a new column to an existing table in SQL?
Use
ALTER TABLE table_name ADD column_name datatype; to add a new column to a table.Click to reveal answer
intermediate
What happens if you try to
DROP TABLE a table that does not exist?You get an error unless you use
DROP TABLE IF EXISTS table_name; which avoids the error if the table is missing.Click to reveal answer
intermediate
How can you rename a table using SQL?
Use
ALTER TABLE old_table_name RENAME TO new_table_name; to rename a table.Click to reveal answer
intermediate
Can you remove a column from a table using
ALTER TABLE? How?Yes, use
ALTER TABLE table_name DROP COLUMN column_name; to remove a column from a table.Click to reveal answer
What does
DROP TABLE employees; do?✗ Incorrect
DROP TABLE removes the entire table and its data permanently.
Which SQL command adds a new column named
age to a table users?✗ Incorrect
ALTER TABLE users ADD age INT; adds a new column called age of type integer.
How do you rename a table
old_name to new_name?✗ Incorrect
The correct syntax to rename a table is ALTER TABLE old_name RENAME TO new_name;.
What happens if you run
DROP TABLE IF EXISTS my_table; and my_table does not exist?✗ Incorrect
IF EXISTS prevents errors if the table does not exist.
Which command removes a column named
address from the customers table?✗ Incorrect
Use ALTER TABLE customers DROP COLUMN address; to remove a column.
Explain what the
DROP TABLE command does and when you might use it.Think about removing a whole spreadsheet from your files.
You got /4 concepts.
Describe how to use
ALTER TABLE to change a table structure, including adding and removing columns.Imagine changing the columns in a spreadsheet without losing the data.
You got /4 concepts.