Search results
MySQL ALTER TABLE Statement. The ALTER TABLE statement is used to add, delete, or modify columns in an existing table. The ALTER TABLE statement is also used to add and drop various constraints on an existing table.
You will learn how to use the MySQL ALTER TABLE statement to add a column, alter a column, rename a column, drop a column and rename a table.
Summary: in this tutorial, you will learn how to add a new column, drop a column, modify an existing column, rename an existing column and rename a table using MySQL ALTER TABLE statement.
Add an index with a specific name to a table on a column: ALTER TABLE table ADD INDEX [name](column, ...); Code language: SQL (Structured Query Language) (sql) Add primary key into a table: ALTER TABLE table_name ADD PRIMARY KEY (column_name,...); Remove the primary key of a table: ALTER TABLE table_name DROP PRIMARY KEY; Drop a table:
The ALTER TABLE command adds, deletes, or modifies columns in a table. The ALTER TABLE command also adds and deletes various constraints in a table. The following SQL adds an "Email" column to the "Customers" table:
With the ALTER TABLE statement, you can rename tables, rename columns, add columns, drop columns, modify column properties, etc. ALTER TABLE syntax ALTER TABLE table_name [ alter_action options ], ...
Following is the syntax of the ALTER Table statement − ALTER TABLE table_name [alter_option ...]; Where, table_name is the name of the existing table you need to change and the alter_option represents the change you need to perform on the table such as ADD COLUMNS, DROP COLUMN etc.