本文介紹了我如何使用“如果存在"?用于在 MySQL 中創建或刪除索引?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我想知道是否有辦法在 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模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!