SQL ALTER TABLE

SQL ALTER TABLE

 SQL ALTER TABLE


Use the ALTER TABLE query on MySQL database to change the table structure. For example, you need to add an extra column, delete some column, or change the database type, or size of any column.

Syntax:

ALTER TABLE table_name
  [alter_specification [, alter_specification] ...]

ALTER TABLE – Add Column

Use the following example command to add a new column to the existing table at the first column.

Adding a new column after a specific column.

ALTER TABLE – Drop Column

You can delete any existing column from the MySQL database table. You can face issues with the deletion of columns due to foreign keys or other constraints.

ALTER TABLE – Modify Column

You can also modify the existing column of the database table using an altered table query. Remember that changing the column may loss of existing data. For example, shortening the size of the file may truncate the extra content from columns.

MySQL
1
2
ALTER TABLE table_name
  MODIFY COLUMN column_name datatype;
Reactions

Post a Comment

0 Comments

close