Alter Table in MySql

In this tutorial we will see the commands which we can use to make changes in our table (as per April 2k21).

  • To add a column in an existing table:
Syntax: ALTER TABLE table_name ADD column_name DATATYPE;
  • To delete a column in an existing table:
Syntax: ALTER TABLE table_name DROP column_name;
  • To change the data type of a column in an existing table:
Syntax: ALTER TABLE table_name MODIFY COLUMN column_name NEW DATA TYPE;
  • To rename a column in an existing table:
Syntax: ALTER TABLE table_name CHANGE column_name NEW_COLUMN_NAME;
  • To update the column as NOT NULL Constraint:
Syntax: ALTER TABLE table_name MODIFY column_name DATATYPE NOT NULL;
  • To Sort the data in the Table:
Syntax: SELECT "column_name" FROM "table-name" [WHERE "condition"] ORDER BY "column_name" [ASC/DESC];

Joydeep M
Latest posts by Joydeep M (see all)
Tagged : / / / / /

Leave a Reply