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;
本文介绍了如何使用SQL中的ALTERTABLE语句来修改表结构,特别是如何添加新的列到现有表中。提供了详细的语法说明及示例,包括将新列添加到表尾部、指定列之后或作为第一列的方法。
613

被折叠的 条评论
为什么被折叠?



