What is the purpose of the `ALTER TABLE` statement?
A
To create a new table B
To delete a table C
To modify an existing table structure D
To insert records into a table
Analysis & Theory
`ALTER TABLE` modifies the structure of an existing table.
Which SQL command adds a new column to an existing table?
A
ALTER TABLE table_name ADD column_name datatype; B
ALTER TABLE table_name CREATE column_name datatype; C
MODIFY TABLE table_name ADD column_name datatype; D
UPDATE TABLE table_name ADD column_name datatype;
Analysis & Theory
Use `ALTER TABLE ... ADD` to add a new column.
How do you delete a column from a table?
A
ALTER TABLE table_name REMOVE column_name; B
ALTER TABLE table_name DELETE column_name; C
ALTER TABLE table_name DROP column_name; D
ALTER TABLE table_name ERASE column_name;
Analysis & Theory
`ALTER TABLE ... DROP COLUMN ...` deletes a column.
Which command changes the data type of a column?
A
ALTER TABLE table_name CHANGE column_name datatype; B
ALTER TABLE table_name MODIFY column_name datatype; C
ALTER TABLE table_name UPDATE column_name datatype; D
ALTER TABLE table_name SET column_name datatype;
Analysis & Theory
`ALTER TABLE ... MODIFY COLUMN ...` changes the data type (in some databases like MySQL).
How do you rename a column in a table (standard SQL)?
A
ALTER TABLE table_name RENAME COLUMN old_name TO new_name; B
ALTER TABLE table_name CHANGE old_name new_name datatype; C
ALTER TABLE table_name MODIFY old_name new_name; D
ALTER TABLE table_name UPDATE old_name TO new_name;
Analysis & Theory
Standard SQL syntax is `ALTER TABLE ... RENAME COLUMN ... TO ...`.
What does the following command do? `ALTER TABLE Employees ADD DateOfBirth DATE;`
A
Adds a new table called DateOfBirth B
Deletes the DateOfBirth column C
Adds a DateOfBirth column of type DATE D
Changes DateOfBirth column data type
Analysis & Theory
It adds a new DATE column named DateOfBirth.
Which of the following is TRUE about `ALTER TABLE`?
A
It cannot be used to rename a table B
It can only add columns C
It can add, drop, or modify columns D
It deletes all data in the table
Analysis & Theory
`ALTER TABLE` can add, drop, rename, or modify columns and constraints.
How do you rename a table in SQL?
A
ALTER TABLE old_name RENAME TO new_name; B
ALTER TABLE old_name CHANGE NAME new_name; C
ALTER TABLE old_name SET NAME new_name; D
ALTER TABLE old_name RENAME AS new_name;
Analysis & Theory
Use `ALTER TABLE ... RENAME TO ...` to rename a table.
What happens to existing data when you add a new column without specifying DEFAULT?
A
Existing rows are deleted B
Existing rows have NULL in the new column C
Existing rows have 0 in the new column D
Existing rows have empty strings in the new column
Analysis & Theory
New column values are NULL for existing rows unless a DEFAULT is provided.
Which of these statements will add a NOT NULL constraint to an existing column?
A
ALTER TABLE table_name ADD CONSTRAINT column_name NOT NULL; B
ALTER TABLE table_name MODIFY column_name datatype NOT NULL; C
ALTER TABLE table_name SET column_name NOT NULL; D
ALTER TABLE table_name UPDATE column_name NOT NULL;
Analysis & Theory
Use `ALTER TABLE ... MODIFY` to change constraints (syntax may vary by RDBMS).