To delete a particular column in a relation the command used is:a)DEL...
To remove a column, ALTER command can be used in the following manner
ALTER TABLE < table="" name="" /> DROP COLUMN < column="" name="" />
Whatever data was in the column disappears. The table constraints involving the column are also dropped.
View all questions of this test
To delete a particular column in a relation the command used is:a)DEL...
Deleting a Column in a Relation using ALTER Command
In SQL, ALTER command is used to modify the existing structure of a table or a relation. One of the modifications that can be made using ALTER command is deleting a particular column from a relation. The syntax for deleting a column using ALTER command is as follows:
ALTER TABLE table_name
DROP COLUMN column_name;
Here, the keyword ALTER is used to modify the table structure, followed by the name of the table from which the column is to be deleted. Then, the keyword DROP COLUMN is used to specify that a particular column is to be deleted. Finally, the name of the column to be deleted is mentioned.
For example, consider a relation named STUDENT with the following schema:
STUDENT (RollNo, Name, Age, Gender, Address)
To delete the column Address from the STUDENT relation, the following ALTER command can be used:
ALTER TABLE STUDENT
DROP COLUMN Address;
This will remove the Address column from the STUDENT relation, and the new schema of the relation will be:
STUDENT (RollNo, Name, Age, Gender)
It is important to note that when a column is deleted from a relation, all the data stored in that column is also deleted permanently. Therefore, it is recommended to take a backup of the data before performing any structural modifications on a table.
Conclusion
To delete a particular column from a relation, the ALTER command with the DROP COLUMN subcommand is used. The syntax of the command specifies the name of the table and the column to be deleted. This command permanently deletes the column and all the data stored in it.
To make sure you are not studying endlessly, EduRev has designed Railways study material, with Structured Courses, Videos, & Test Series. Plus get personalized analysis, doubt solving and improvement plans to achieve a great score in Railways.