faster alter table add column
2016-08-07 09:41
267 查看
Create a new table (using the structure of the current table) with the new column(s) included.
execute a
rename the current table
rename the new table using the name of the current table.
1.
2.
3&4.
The usual trick for loading MyISAM table efficiently is to disable keys, load the data and renalbe the keys:
REF:
http://stackoverflow.com/questions/5677932/optimize-mysql-for-faster-alter-table-add-column
http://dba.stackexchange.com/questions/9746/mysql-fastest-way-to-alter-table-for-innodb
http://dba.stackexchange.com/questions/134269/fastest-way-to-add-new-column-in-mysql
execute a
INSERT INTO new_table SELECT (column1,..columnN) FROM current_table;
rename the current table
rename the new table using the name of the current table.
1.
CREATE TABLE new_table LIKE table;
2.
INSERT INTO new_table SELECT * FROM table;
3&4.
RENAME TABLE table = old_table, table = new_table;
The usual trick for loading MyISAM table efficiently is to disable keys, load the data and renalbe the keys:
mysql> ALTER TABLE test.load_data DISABLE KEYS; -- load data mysql> ALTER TABLE test.load_data ENABLE KEYS;
dropped all indexes -- then added the field and recreate indexes
REF:
http://stackoverflow.com/questions/5677932/optimize-mysql-for-faster-alter-table-add-column
http://dba.stackexchange.com/questions/9746/mysql-fastest-way-to-alter-table-for-innodb
http://dba.stackexchange.com/questions/134269/fastest-way-to-add-new-column-in-mysql
相关文章推荐
- 在线生产系统执行 alter table add column type default x ;的分析
- Oracle alter table add column example
- SQL SERVER删除列,报错."由于一个或多个对象访问此列,ALTER TABLE DROP COLUMN ... 失败"
- GP BUG APPEND TABLE ADD COLUMN
- MySQL ALTER TABLE: ALTER vs CHANGE vs MODIFY COLUMN
- ORA-01758: table must be empty to add mandatory (NOT NULL) column
- MSSql Server 索引'uq_f_userName' 依赖于 列'f_userName'。由于一个或多个对象访问此列,ALTER TABLE ALTER COLUMN f_userName 失败
- SQL删除数据表中字段时出现【由于一个或多个对象访问此列,ALTER TABLE DROP COLUMN *** 失败。 】
- sql语句增加表单字段ALTER TABLE ADD 增加多个字段 外键约束
- alter table *** add constraint *** 用法
- MySQL How to add a column in a table?
- add column for a table if this column not exists using T-SQL in SQLServer
- ORA-14097: column type or size mismatch in ALTER TABLE EXCHANGE PARTITION
- alter table fx.pet modify column `species` varchar(20) binary;
- Sybase add/delete column from table
- [Hive - LanguageManual] Alter Table/Partition/Column
- mysql alter table add foreign (errno: 150)添加外键150错误
- create index 与 alter table add index 区别
- Mysql官方文档中争对安全添加列的处理方法。Mysql Add a Column to a table if not exists
- MySQL如何创建主键?Alter table add PRIMARY KEY的用法和例子