0
0
MySQLquery~5 mins

ALTER TABLE operations in MySQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ADROP TABLE COLUMN
BALTER TABLE ADD COLUMN
CINSERT INTO TABLE
DCREATE TABLE ADD COLUMN
How do you remove a column named 'email' from a table 'contacts'?
AALTER TABLE contacts DROP COLUMN email;
BDELETE COLUMN email FROM contacts;
CALTER TABLE contacts REMOVE email;
DDROP TABLE contacts.email;
To rename a column in MySQL, which keyword is used?
ACHANGE
BRENAME COLUMN
CMODIFY
DALTER COLUMN
Which command changes the data type of a column?
AALTER TABLE DROP
BALTER TABLE RENAME
CALTER TABLE ADD
DALTER TABLE MODIFY
What happens if you run ALTER TABLE table_name ADD COLUMN new_col VARCHAR(50);?
ARenames the table to new_col
BDeletes the column new_col
CAdds a new column named new_col with type VARCHAR(50)
DChanges the data type of new_col
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.