MySQL Worksheet 2: ALTER Commands class XI and Class XII

 


MySQL Worksheet 2:  ALTER Commands

Name: ___________________
Date: ___________________

Part A: Multiple Choice Questions

  1. 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
  2. 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
  3. 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

  1. T/F: The ALTER TABLE command can only be used to add columns.

  2. T/F: You cannot revert changes made by the ALTER TABLE command once it is executed.

  3. T/F: The ALTER TABLE ... RENAME command can be used to change the name of the entire table.

Part C: Fill in the Blanks

  1. The command to change the name of a column in a table is __________.

  2. To remove a unique constraint from a column, you would use __________.

  3. An example of a column modification that allows for NULL values is __________.

Part D: Short Answer Questions

  1. Write the SQL command to add a column named "Email" (VARCHAR(100)) to the "Employees" table.

  2. Write the SQL command to change the data type of the "Salary" column in the "Employees" table to DECIMAL(10, 2).

  3. Explain the purpose of the DROP COLUMN command in the context of database management.

Part E: Practical Application

  1. Write a command to rename the "FirstName" column to "GivenName" in the "Employees" table.

  2. Write a command to remove the "HireDate" column from the "Employees" table.

  3. If you want to add a new column "DepartmentID" (INT) that cannot be NULL to the "Employees" table, what command would you use?


Post a Comment

0 Comments