The ALTER order gives an approach to change a current table's design, which means alterations like eliminating or adding sections, adjusting records, changing information types, or evolving names. Adjust likewise holds back to apply changes when a metadata lock is dynamic.
Using ALTER to Modify Columns
Adjust matched with DROP eliminates a current section. Be that as it may, it falls flat if the section is the last segment.
Survey the model given underneath −
mysql> ALTER TABLE products_tbl DROP version_num;
Utilize an ALTER...ADD articulation to add sections −
mysql> ALTER TABLE products_tbl ADD discontinued CHAR(1);
Utilize the catchphrases FIRST and AFTER to determine situation of the section −
ALTER TABLE products_tbl ADD discontinued CHAR(1) FIRST; ALTER TABLE products_tbl ADD discontinued CHAR(1) AFTER quantity;
Note the FIRST and AFTER catchphrases just apply to ALTER...ADD articulations. Moreover, you should drop a table and afterward add it to reposition it.
Change a segment definition or name by utilizing the MODIFY or CHANGE condition in an ALTER explanation. The conditions have comparative impacts, however use generously unique language structure.
Audit a CHANGE model given beneath −
mysql> ALTER TABLE products_tbl CHANGE discontinued status CHAR(4);
In a proclamation utilizing CHANGE, indicate the first segment and afterward the new segment that will supplant it. Audit a MODIFY model underneath −
mysql> ALTER TABLE products_tbl MODIFY discontinued CHAR(4);
The ALTER order additionally considers changing default esteems. Audit a model −
mysql> ALTER TABLE products_tbl ALTER discontinued SET DEFAULT N;
You can likewise utilize it to eliminate default requirements by blending it with a DROP statement −
mysql> ALTER TABLE products_tbl ALTER discontinued DROP DEFAULT;
Using ALTER to Modify Tables
Change table sort with the TYPE statement −
mysql> ALTER TABLE products_tbl TYPE = INNODB;
Rename a table with the RENAME watchword −
mysql> ALTER TABLE products_tbl RENAME TO products2016_tbl;