您的位置:首页 > 数据库 > MySQL

MySQL How to add a column in a table?

2017-07-07 19:43 615 查看
ALTER TABLE statement can change the structure of a table.You can use it to add, modify, or drop/delete columns in a table.

note:To use ALTER TABLE, you need ALTER, CREATE, and INSERT privileges for the table.

syntax

ALTER TABLE tbl_name

[alter_specification [, alter_specification] …]

[partition_options]

Add column in table

syntax

To add a column in a table, the ALTER TABLE syntax in SQL is:

ALTER TABLE tbl_name

ADD [COLUMN] col_name column_definition [FIRST | AFTER col_name ]

example

ALTER TABLE test ADD test_column VARCHAR(60)

This example will add a column named test_column to the end of the test table.

If you want to insert the new column after a specific column,such as name,use this statement:

ALTER TABLE test ADD test_column VARCHAR(60) AFTER name

If you want the new column to be first, use this statement:

ALTER TABLE test ADD test_column VARCHAR(60) FIRST;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: