Change Table Structure Using Alter Table

MySQL ALTER TABLE

MySQL ALTER TABLE statement that changes existing table structure such as adding or removing column, changing column attribute, etc.

Syntax

ALTER TABLE table_name action1[,action2,…]

To alter an existing table:

  • First, you specify the table name that you want to change after the ALTER TABLE keywords.
  • Second, you list a set of actions that you want to apply to the table. An action can be anything such as adding a new column, adding primary key, renaming table, etc. The ALTER TABLE statement allows you to apply multiple actions in a single ALTER TABLE statement, each action is separated by a comma (,).
Ouery:-add New Colonm into exiting Table.

ALTER TABLE 
emp ADD COLUMN 
date varchar( 100 ) NULL AFTER salary;

Ouery:-Drop a column from exiting Table.

ALTER TABLE emp
DROP COLUMN date;

Ouery:-Renaming table Name of exiting Table Name.

ALTER TABLE emp
RENAME TO employee

Admin has written 171 articles