mysql创建索引笔记

1.添加PRIMARY KEY(主键索引。就是 唯一 且 不能为空。):

ALTER TABLE `table_name` ADD PRIMARY KEY ( `column` ) 

2.添加UNIQUE(唯一索引) :

ALTER TABLE `table_name` ADD UNIQUE ( `column` ) 
 
3.添加INDEX(普通索引) :
ALTER TABLE `table_name` ADD INDEX index_name ( `column` )
 
4.添加FULLTEXT(全文索引,是全文索引,用于在一篇文章中,检索文本信息的。) :
ALTER TABLE `table_name` ADD FULLTEXT ( `column`) 
 
5.添加多列索引:
ALTER TABLE `table_name` ADD INDEX index_name ( `column1`, `column2`, `column3` )
 
6,临时表使用

create TEMPORARY table temp_1 like user
create TEMPORARY table temp_2 like project

insert into temp_1
select * from (
select * from user where usertype=8
and uid not in (
select uid from po_user) order by create_time desc) a

insert into temp_2 select * from project where response_code in(
select username from temp_1
)

insert into po_user(uid,pid,project_name,is_deleted,last_modify_time,last_modify_user)

select uid,pid,project_name,1 as is_deleted,now() as last_modify_time,'手动修复数据' as last_modify_user from temp_1
join temp_2 on temp_1.username =temp_2.response_code

select * from po_user

 
原文地址:https://www.cnblogs.com/zd1994/p/7510910.html