MySQL How to add a column in a table?

逃离我推掉我的手 2022-06-13 13:24 350阅读 0赞

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;

发表评论

表情:
评论列表 (有 0 条评论,350人围观)

还没有评论,来说两句吧...

相关阅读