MySQL How to add a column in a table?
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;
还没有评论,来说两句吧...