0
0
SQLquery~5 mins

DROP TABLE and ALTER TABLE in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ADeletes the employees table and all its data
BDeletes only the data inside employees table
CRenames the employees table
DAdds a new column to employees table
Which SQL command adds a new column named age to a table users?
ADROP TABLE users ADD age;
BALTER TABLE users DROP COLUMN age;
CALTER TABLE users ADD age INT;
DCREATE COLUMN age ON users;
How do you rename a table old_name to new_name?
AALTER TABLE old_name RENAME TO new_name;
BDROP TABLE old_name RENAME TO new_name;
CRENAME TABLE old_name TO new_name;
DALTER TABLE old_name CHANGE TO new_name;
What happens if you run DROP TABLE IF EXISTS my_table; and my_table does not exist?
ATable is renamed
BError occurs because table is missing
CTable is created
DNo error, command runs safely
Which command removes a column named address from the customers table?
ADROP TABLE customers.address;
BALTER TABLE customers DROP COLUMN address;
CALTER TABLE customers REMOVE address;
DDELETE COLUMN address FROM customers;
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.