Recall & Review
beginner
What does the
ALTER TABLE statement do in SQL?It changes the structure of an existing table, such as adding, deleting, or modifying columns.
Click to reveal answer
beginner
How do you add a new column named
age of type INT to a table called users?Use:
ALTER TABLE users ADD COLUMN age INT;Click to reveal answer
intermediate
How can you rename a column
fullname to full_name in MySQL?Use:
ALTER TABLE table_name CHANGE fullname full_name datatype; where you specify the datatype again.Click to reveal answer
beginner
What is the command to drop (delete) a column named
address from a table customers?Use:
ALTER TABLE customers DROP COLUMN address;Click to reveal answer
intermediate
How do you change the data type of a column
price to DECIMAL(10,2) in MySQL?Use:
ALTER TABLE table_name MODIFY COLUMN price DECIMAL(10,2);Click to reveal answer
Which SQL command adds a new column to an existing table?
✗ Incorrect
The correct syntax to add a column is using ALTER TABLE with ADD COLUMN.
How do you remove a column named 'email' from a table 'contacts'?
✗ Incorrect
The correct syntax to remove a column is ALTER TABLE with DROP COLUMN.
To rename a column in MySQL, which keyword is used?
✗ Incorrect
MySQL uses CHANGE to rename a column and requires the datatype to be specified.
Which command changes the data type of a column?
✗ Incorrect
MODIFY is used to change the data type or definition of a column.
What happens if you run
ALTER TABLE table_name ADD COLUMN new_col VARCHAR(50);?✗ Incorrect
This command adds a new column named new_col with the specified type.
Explain how to add, rename, and delete columns in a MySQL table using ALTER TABLE.
Think about the keywords ADD, CHANGE, and DROP with ALTER TABLE.
You got /3 concepts.
Describe the difference between MODIFY and CHANGE in ALTER TABLE operations.
One is for renaming, the other for changing type.
You got /2 concepts.