mysql索引查询、创建createindex与addindex的区别
1、索引查询
------TABLE_SCHEMA  库名;TABLE  表名
------AND UPPER(INDEX_NAME) != 'PRIMARY'  只查询索引,不需要主键
SELECT
CONCAT('ALTER TABLE `',TABLE_NAME,'` ', 'ADD ',
IF(NON_UNIQUE = 1,
CASE UPPER(INDEX_TYPE)mysql下载add produce
WHEN 'FULLTEXT' THEN 'FULLTEXT INDEX'
WHEN 'SPATIAL' THEN 'SPATIAL INDEX'
ELSE CONCAT('INDEX `',
INDEX_NAME,
'` USING ',
INDEX_TYPE
)
END,
IF(UPPER(INDEX_NAME) = 'PRIMARY',
CONCAT('PRIMARY KEY USING ',
INDEX_TYPE
),
CONCAT('UNIQUE INDEX `',
INDEX_NAME,
'` USING ',
INDEX_TYPE
)
)
),'(', GROUP_CONCAT(DISTINCT CONCAT('`', COLUMN_NAME, '`') ORDER BY SEQ_IN_INDEX ASC SEPARATOR ', '), ');') AS
'Show_Add_Indexes'
FROM information_schema.STATISTICS
WHERE TABLE_SCHEMA = 'test'  and TABLE ='test_table'
AND UPPER(INDEX_NAME) != 'PRIMARY'
GROUP BY TABLE_NAME, INDEX_NAME
ORDER BY TABLE_NAME ASC, INDEX_NAME ASC;
2、索引删除
alter table table_name drop index index_name;
3、创建索引
alter table table_name add index_name using btree('column_name',...,'column_name');
create unique index index_name on table_name('column_name');
两者区别:
(1)add index_name ⽀持⼀次多个索引创建alter table table_name add index_name using btree('column_name',...,'column_name'),add index_name using btree('column_name',...,'column_name')
(2)add index_name 可以创建 PRIMARY KEY
(3)create  index 创建时必须制定index_name,alter 可以使⽤默认名

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。