ALTER MySQL Table
How to alter a mysql table ?
ALTER MySQL TABLE :ALTER TABLE
is used to change the structure of an existing table. We can add or delete columns, change the type of existing columns, or rename columns or the table itself. We can also change the comment for the table and type of the table.
ALTER TABLE tbl_name alter_specification [, alter_specification] ...
The below table will describe the alter specification :
The below descriptions shows how to alter mysql tables using queries.
We can also RENAME
the table using ALTER TABLE
. The following example query renames the table student to class.
mysql> ALTER TABLE student RENAME class;
The above query will change the table name.
The ADD COLUMN
modifier is used to add a column to a table. The following example query adds a field called marks to the student table.
Next we move to the alterations in displaying the tables.