27 Lecture

CS403

Midterm & Final Term Short Notes

Alter Table Statement

The ALTER TABLE statement is a DDL command in SQL that is used to modify the structure of an existing table. It allows you to add, modify or delete columns, change the data type of a column, rename a table, and set constraints on columns. The AL


Important Mcq's
Midterm & Finalterm Prepration
Past papers included

Download PDF
  1. Which SQL command is used to modify the structure of an existing table? a. SELECT b. INSERT c. UPDATE d. ALTER TABLE Answer: d. ALTER TABLE What is the purpose of the ALTER TABLE statement in SQL? a. To create a new table b. To delete a table c. To modify the structure of an existing table d. To insert data into a table Answer: c. To modify the structure of an existing table Which keyword is used to add a new column to an existing table using the ALTER TABLE statement? a. ADD b. MODIFY c. DROP d. RENAME Answer: a. ADD Which keyword is used to modify the data type of a column using the ALTER TABLE statement? a. ADD b. MODIFY c. DROP d. RENAME Answer: b. MODIFY Which keyword is used to delete a column from an existing table using the ALTER TABLE statement? a. ADD b. MODIFY c. DROP d. RENAME Answer: c. DROP Which keyword is used to rename an existing table using the ALTER TABLE statement? a. ADD b. MODIFY c. DROP d. RENAME Answer: d. RENAME Which keyword is used to set a primary key constraint on a column using the ALTER TABLE statement? a. PRIMARY KEY b. FOREIGN KEY c. UNIQUE d. CHECK Answer: a. PRIMARY KEY Which keyword is used to add a foreign key constraint to an existing table using the ALTER TABLE statement? a. PRIMARY KEY b. FOREIGN KEY c. UNIQUE d. CHECK Answer: b. FOREIGN KEY Which keyword is used to set a unique constraint on a column using the ALTER TABLE statement? a. PRIMARY KEY b. FOREIGN KEY c. UNIQUE d. CHECK Answer: c. UNIQUE Which keyword is used to add a check constraint to an existing table using the ALTER TABLE statement? a. PRIMARY KEY b. FOREIGN KEY c. UNIQUE d. CHECK Answer: d. CHECK



Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included

Download PDF
  1. What is the ALTER TABLE statement used for in SQL? Answer: The ALTER TABLE statement is used to modify the structure of an existing table in SQL. How do you add a new column to an existing table using the ALTER TABLE statement? Answer: You can add a new column to an existing table using the ALTER TABLE statement with the ADD keyword followed by the column name and data type. Can you modify the data type of an existing column using the ALTER TABLE statement? Answer: Yes, you can modify the data type of an existing column using the ALTER TABLE statement with the MODIFY keyword followed by the column name and new data type. How do you delete a column from an existing table using the ALTER TABLE statement? Answer: You can delete a column from an existing table using the ALTER TABLE statement with the DROP keyword followed by the column name. How do you rename an existing table using the ALTER TABLE statement? Answer: You can rename an existing table using the ALTER TABLE statement with the RENAME keyword followed by the new table name. What is a primary key constraint and how do you set it using the ALTER TABLE statement? Answer: A primary key constraint is a unique identifier for a row in a table. You can set a primary key constraint using the ALTER TABLE statement with the ADD keyword followed by the PRIMARY KEY keyword and the column name. What is a foreign key constraint and how do you add it to an existing table using the ALTER TABLE statement? Answer: A foreign key constraint is used to link two tables together based on a common column. You can add a foreign key constraint to an existing table using the ALTER TABLE statement with the ADD keyword followed by the FOREIGN KEY keyword and the column name. What is a unique constraint and how do you set it using the ALTER TABLE statement? Answer: A unique constraint ensures that each value in a column is unique. You can set a unique constraint using the ALTER TABLE statement with the ADD keyword followed by the UNIQUE keyword and the column name. What is a check constraint and how do you add it to an existing table using the ALTER TABLE statement? Answer: A check constraint is used to ensure that the values in a column meet a certain condition. You can add a check constraint to an existing table using the ALTER TABLE statement with the ADD keyword followed by the CHECK keyword and the condition. Can you modify the name of an existing column using the ALTER TABLE statement? Answer: Yes, you can modify the name of an existing column using the ALTER TABLE statement with the MODIFY keyword followed by the column name and the new name.

In SQL, the ALTER TABLE statement is used to modify the structure of an existing table. This statement allows you to add, modify, or delete columns, as well as set constraints such as primary key, foreign key, unique, and check constraints. To add a new column to an existing table, you can use the ALTER TABLE statement with the ADD keyword followed by the column name and data type. To modify the data type of an existing column, you can use the ALTER TABLE statement with the MODIFY keyword followed by the column name and new data type. And to delete a column from an existing table, you can use the ALTER TABLE statement with the DROP keyword followed by the column name. You can also use the ALTER TABLE statement to rename an existing table with the RENAME keyword followed by the new table name. Setting constraints on a table is an important aspect of database design. A primary key constraint is used to uniquely identify each row in a table. To set a primary key constraint using the ALTER TABLE statement, you can use the ADD keyword followed by the PRIMARY KEY keyword and the column name. A foreign key constraint is used to link two tables together based on a common column. To add a foreign key constraint using the ALTER TABLE statement, you can use the ADD keyword followed by the FOREIGN KEY keyword and the column name. A unique constraint is used to ensure that each value in a column is unique. To set a unique constraint using the ALTER TABLE statement, you can use the ADD keyword followed by the UNIQUE keyword and the column name. A check constraint is used to ensure that the values in a column meet a certain condition. To add a check constraint using the ALTER TABLE statement, you can use the ADD keyword followed by the CHECK keyword and the condition. In summary, the ALTER TABLE statement is a powerful tool in SQL that allows you to modify the structure of an existing table and set important constraints for database design.