Alter Command in SQL:
The Alter Table Command has 3 sub-domains that are used to serve its Purpose.
- ALTER TABLE – ADD Column
- ALTER TABLE – DROP Column
- ALTER TABLE – MODIFY Column
Let’s look up into the General Syntax and its Practical use for all 3 of them one by one.
ALTER TABLE – ADD Column:
ALTER TABLE table_name ADD column_name datatype;
Let’s take an example that seems to be much more Realistic than others. Let’s say the Store owner decides to add the GST Number to all its products after the Implementation of GST in India. SO what he has to do is add a new column now.
ALTER TABLE store ADD GST_No INT;
ALTER TABLE – MODIFY Column:
ALTER TABLE table_name MODIFY column_name datatype;
Following the same situation, the Shop owner decides to change the datatype of the Column as he notices that the GST Number can have the alphabets as well.
ALTER TABLE store MODIFY GST_No VARCHAR(20);
ALTER TABLE – DROP Column:
And after all, if he decides to delete the Column once again and bring back the old format.
ALTER TABLE store DROP COLUMN GST_No;
NOTE: There can be slight modifications in the Syntax of Modify Statement in other versions of SQL and hence it is better to confirm if you’re using something else!