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]
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;
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
syntaxTo 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;
相关文章推荐
- add column for a table if this column not exists using T-SQL in SQLServer
- void addColumn(TableColumn aColumn)
- rails reverse words you can't use them in as your column or tablename
- Cannot insert explicit value for identity column in table ‘table’ when IDENTITY_INSERT is set to OFF
- UITableView 知识更新A table view displays a list of items in a single column. UITableView is a subclas
- Mysql官方文档中争对安全添加列的处理方法。Mysql Add a Column to a table if not exists
- Oracle alter table add column example
- Add a column to table(Handling)
- 3.You need to extract details of those products in the SALES table where the PROD_ID column contains
- GP BUG APPEND TABLE ADD COLUMN
- How To Add Search Bar in Table View
- MySQL - EF : The value for column 'IsPrimaryKey' in table 'TableDetails' is DBNull
- Refreshing One Column based on the value of Another Column in ADFdi Table
- Judge whether a column exists in a table
- Add an onclick event in the DataGrid for any Column
- How Can i Store photo (image) in column of table
- Add column to existing table with default value
- Cannot insert explicit value for identity column in table 'settings' when IDENTITY_INSERT is set to OFF.
- query db name and table name by the column name in db server
- 解决beego中Orm操作日志显示Error 1054: Unknown column '' in 'field list'或者出现 table ‘’ not exist