MySQL Worksheet 2: ALTER Commands
Name: ___________________
Date: ___________________
Part A: Multiple Choice Questions
Which of the following commands is used to add a new column to an existing table?
- a) ALTER TABLE ... ADD COLUMN
- b) MODIFY TABLE ... ADD
- c) UPDATE TABLE ... ADD
- d) ADD TABLE ... COLUMN
To change the data type of an existing column in a table, you would use:
- a) ALTER TABLE ... CHANGE
- b) ALTER TABLE ... MODIFY
- c) Both a and b
- d) ALTER TABLE ... UPDATE
Which command would you use to drop a column from a table?
- a) REMOVE COLUMN
- b) ALTER TABLE ... DROP COLUMN
- c) DELETE COLUMN
- d) DROP TABLE ... COLUMN
Part B: True/False Questions
T/F: The
ALTER TABLE
command can only be used to add columns.T/F: You cannot revert changes made by the
ALTER TABLE
command once it is executed.T/F: The
ALTER TABLE ... RENAME
command can be used to change the name of the entire table.
Part C: Fill in the Blanks
The command to change the name of a column in a table is __________.
To remove a unique constraint from a column, you would use __________.
An example of a column modification that allows for NULL values is __________.
Part D: Short Answer Questions
Write the SQL command to add a column named "Email" (VARCHAR(100)) to the "Employees" table.
Write the SQL command to change the data type of the "Salary" column in the "Employees" table to DECIMAL(10, 2).
Explain the purpose of the
DROP COLUMN
command in the context of database management.
Part E: Practical Application
Write a command to rename the "FirstName" column to "GivenName" in the "Employees" table.
Write a command to remove the "HireDate" column from the "Employees" table.
If you want to add a new column "DepartmentID" (INT) that cannot be NULL to the "Employees" table, what command would you use?
0 Comments
Please do note create link post in comment section