怎样向有大量数据的表中添加索引

wylc123 1年前 ⋅ 790 阅读
create table t_sys_test_temp like t_sys_test;
alter table t_sys_test_temp add index age_index(age);
INSERT into t_sys_test_temp(id,name,age,card_id,address,create_time,update_time,manager_id,deleted,sex)
select id,name,age,card_id,address,create_time,update_time,manager_id,deleted,sex from t_sys_test 
rename table t_sys_test to temp2 ,t_sys_test_temp to t_sys_test ;
drop table temp2;

总体思路就是:
1先创建临时表t_sys_test_temp
2向临时表t_sys_test_temp 添加索引
3将目标表的数据查询出来插入到临时表,再将目标表t_sys_test重命名为temp2,
将临时表t_sys_test_temp 重命名为结果表t_sys_test
4删除临时表temp2


相关文章推荐

全部评论: 0

    我有话说: