This set of SQL Multiple Choice Questions & Answers (MCQs) focuses on “SQL Alter Table”.
1. Which of the following command is used to modify the structure of a table in SQL?
a) CREATE
b) DROP
c) ALTER
d) INSERT
View Answer
Explanation: The ALTER command is used to modify the structure of a table in SQL. The CREATE command is used to create a table or database. The DROP command is used to delete the structure of a table or database. The INSERT command is used to insert data inside the tables.
2. In SQL, the ALTER command can be put under which of the following category?
a) DDL (Data Definition Language)
b) DML (Data Manipulation Language)
c) DCL (Data Control Language)
d) TCL (Transaction Control Language)
View Answer
Explanation: In SQL, the ALTER command comes under the category of DDL (Data Definition Language) which is used to define the structure of the table. DML (Data Manipulation Language) is used to manipulate the data inside the table. DCL (Data Control Language) is used by the database administrator to configure security access to relational databases. TCL (Transaction Control Language) is used to commit or rollback the changes made by DML commands.
3. In SQL, the ALTER command cannot be used to perform which of the following task?
a) Add Column
b) Drop Column
c) Modify Column
d) Restore Column
View Answer
Explanation: In SQL, the ALTER command cannot be used to perform the restore column function. The ALTER command is used to add, drop or modify an existing column in a table.
4. In SQL, which of the following statement can be used to add a column to an existing table using the ALTER command?
a)
ALTER TABLE TABLE_NAME ADD column_name datatype;
b)
ALTER TABLE_NAME ADD column_name datatype;
c)
ALTER TABLE TABLE_NAME column_name datatype;
d)
ALTER TABLE ADD column_name datatype;
Explanation: The syntax used to add a new column to an existing table using the ALTER command is –
ALTER TABLE TABLE_NAME ADD column_name datatype;
ADD keyword is always present in the statement with the ALTER and the TABLE keyword and the table name and the column name.
5. In SQL, which of the following statement can be used to drop a column from an existing table using the ALTER command?
a)
ALTER TABLE_NAME DROP COLUMN column_name;
b)
ALTER TABLE TABLE_NAME DROP column_name;
c)
ALTER TABLE TABLE_NAME DROP COLUMN column_name;
d)
ALTER TABLE DROP COLUMN column_name;
Explanation: The syntax used to drop a column from an existing table using the ALTER command is –
ALTER TABLE TABLE_NAME DROP COLUMN column_name;
DROP keyword is always present in the statement with the ALTER and the TABLE keyword and the table name and the column name.
6. In SQL, which of the following statement can be used to modify a column in an existing table using the ALTER command?
a)
ALTER TABLE TABLE_NAME MODIFY COLUMN column_name datatype;
b)
ALTER TABLE_NAME MODIFY COLUMN column_name datatype;
c)
ALTER TABLE TABLE_NAME MODIFY COLUMN datatype;
d)
ALTER TABLE TABLE_NAME COLUMN column_name datatype;
Explanation: The syntax used to drop a column from an existing table using the ALTER command is –
ALTER TABLE TABLE_NAME MODIFY COLUMN column_name datatype;
MODIFY keyword is always present in the statement with the ALTER, the TABLE and the COLUMN keyword and the table name and the column name.
7. In SQL, the ALTER command can be used to add and drop various constraints on an existing table.
a) True
b) False
View Answer
Explanation: In SQL, the ALTER command can be used to add and drop various constraints to an existing table. This can be done by using the MODIFY or DROP version of the command.
8. In SQL, which of the following statement can be used to add a constraint in an existing table using the ALTER command?
a)
ALTER TABLE TABLE_NAME ADD CONSTRAINT constraint_name (condition/column_name);
b)
ALTER TABLE TABLE_NAME ADD CONSTRAINT constraint_name constraint_type (condition/column_name);
c)
ALTER TABLE TABLE_NAME ADD CONSTRAINT constraint_type (condition/column_name);
d)
ALTER TABLE TABLE_NAME ADD constraint_name constraint_type (condition/column_name);
Explanation: The syntax used to add a constraintto an existing table using the ALTER command is –
ALTER TABLE TABLE_NAME ADD CONSTRAINT constraint_name constraint_type (condition/column_name);
For example –
ALTER TABLE Employee ADD CONSTRAINT MyConstraint UNIQUE (column1, column3);
Here, constraint_name is a name given to the constraint used by the user.
9. In SQL, which of the following statement can be used to drop a constraint from an existing table using the ALTER command?
a)
ALTER TABLE TABLE_NAME DROP CONSTRAINT/INDEX constraint_name;
b)
ALTER TABLE TABLE_NAME CONSTRAINT/INDEX constraint_name;
c)
ALTER TABLE TABLE_NAME DROP CONSTRAINT/INDEX;
d)
ALTER TABLE TABLE_NAME DROP CONSTRAINT/INDEX constraint_type;
Explanation: The syntax used to drop a constraint from an existing table using the ALTER command is
ALTER TABLE TABLE_NAME DROP CONSTRAINT/INDEX constraint_name;
For example –
ALTER TABLE Employee DROP CONSTRAINT MyConstraint;
INDEX is used rather than CONSTRAINT in MySQL when removing INDEX based constraint such as UNIQUE. Here, MyConstraint is a name given to UNIQUE constraint added to the table.
10. In SQL, which of the following statement can be used to rename an existing table using the ALTER command?
a)
ALTER TABLE RENAME TO new_table_name;
b)
ALTER TABLE_NAME RENAME TO new_table_name;
c)
ALTER TABLE TABLE_NAME RENAME new_table_name;
d)
ALTER TABLE TABLE_NAME RENAME TO new_table_name;
Explanation: The syntax used to rename an existing table using the ALTER command is –
ALTER TABLE TABLE_NAME RENAME TO new_table_name;
RENAME TO keyword is always present in the statement with the ALTER and the TABLE keyword and the table name and the new table name.
11. In SQL, which of the following statement can be used to rename a column in an existing table using the ALTER command?
a)
ALTER TABLE TABLE_NAME RENAME COLUMN TO new_name;
b)
ALTER column_name RENAME TO new_column_name;
c)
ALTER TABLE TABLE_NAME RENAME new_column_name;
d)
ALTER TABLE TABLE_NAME RENAME COLUMN old_name TO new_name;
Explanation: The syntax used to rename an existing table using the ALTER command is –
ALTER TABLE TABLE_NAME RENAME COLUMN old_name TO new_name;
RENAME TO keyword is always present in the statement with the ALTER, the TABLE and the COLUMN keyword and the table name, the old column name and the new column name.
Sanfoundry Global Education & Learning Series – SQL.
To practice all areas of SQL, here is complete set of 1000+ Multiple Choice Questions and Answers.