我想知道是否有办法在 MySQL 上创建或销毁索引之前检查索引是否存在.几年前似乎有一个功能请求,但我找不到任何解决方案的文档.这需要在使用 MDB2 的 PHP 应用程序中完成.
I was wondering if there's a way to check if an index exists before creating it or destroying it on MySQL. It appears that there was a feature request for this a few years back, but I can't find any documentation for a solution. This needs to be done in a PHP app using MDB2.
这是我的 4 个班轮:
Here is my 4 liner:
set @exist := (select count(*) from information_schema.statistics where table_name = 'table' and index_name = 'index' and table_schema = database());
set @sqlstmt := if( @exist > 0, 'select ''INFO: Index already exists.''', 'create index i_index on tablename ( columnname )');
PREPARE stmt FROM @sqlstmt;
EXECUTE stmt;
这篇关于我如何使用“如果存在"?用于在 MySQL 中创建或删除索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!