What is the purpose of the `ALTER TABLE` statement in MySQL?
A
To select data from a table B
To delete the entire table C
To modify the structure of an existing table D
To insert new records
Analysis & Theory
`ALTER TABLE` is used to change the structure of an existing table.
Which command adds a new column named `age` of type `INT` to the `students` table?
A
ADD COLUMN age INT TO students; B
ALTER TABLE students ADD age INT; C
MODIFY TABLE students ADD age INT; D
INSERT COLUMN age INTO students;
Analysis & Theory
`ALTER TABLE students ADD age INT;` is the correct syntax for adding a column.
How do you rename a table in MySQL?
A
ALTER TABLE old_name CHANGE TO new_name; B
RENAME old_name TO new_name; C
ALTER TABLE old_name RENAME TO new_name; D
CHANGE TABLE old_name TO new_name;
Analysis & Theory
`ALTER TABLE old_name RENAME TO new_name;` is used to rename a table.
Which clause is used to delete a column from a table?
A
DROP COLUMN B
REMOVE COLUMN C
DELETE COLUMN D
ERASE COLUMN
Analysis & Theory
Use `ALTER TABLE table_name DROP COLUMN column_name;` to remove a column.
What does `ALTER TABLE employees MODIFY salary DECIMAL(10,2);` do?
A
Adds a new column called salary B
Removes the salary column C
Changes the data type of `salary` to `DECIMAL(10,2)` D
Updates salary values
Analysis & Theory
`MODIFY` is used to change a column’s data type or attributes.
Which of the following adds a NOT NULL constraint to an existing column?
A
ALTER TABLE t SET NOT NULL age; B
ALTER TABLE t ALTER age NOT NULL; C
ALTER TABLE t MODIFY age INT NOT NULL; D
ALTER age INT NOT NULL IN t;
Analysis & Theory
Use `MODIFY` to redefine the column with the desired constraint.
How do you rename a column in MySQL?
A
ALTER TABLE t RENAME COLUMN old_name TO new_name; B
ALTER TABLE t CHANGE old_name new_name datatype; C
RENAME COLUMN old_name TO new_name; D
MODIFY COLUMN old_name TO new_name;
Analysis & Theory
MySQL uses `CHANGE old_name new_name datatype` to rename a column.
Which keyword is used to change the order of columns in a table?
A
MOVE B
POSITION C
AFTER D
SHIFT
Analysis & Theory
`AFTER column_name` can be used in `MODIFY` or `ADD` to place a column after another.
What does `ALTER TABLE products DROP PRIMARY KEY;` do?
A
Deletes all rows in the table B
Drops the table C
Removes the primary key constraint from the table D
Removes the first column
Analysis & Theory
It removes the primary key from the `products` table.
Can you add multiple columns in one `ALTER TABLE` command?
A
No, only one column per statement B
Yes, using a comma between each `ADD` C
Yes, but only if the table is empty D
Only with the `CREATE TABLE` command
Analysis & Theory
You can add multiple columns using `ALTER TABLE` with multiple `ADD` clauses separated by commas.