Differenze tra le versioni di "MySql:Cancellare un indice controllando prima se esiste"

(Esempio)
(Esempio #2)
 
Riga 15: Riga 15:
 
=== Esempio #2 ===
 
=== Esempio #2 ===
 
<pre>
 
<pre>
SET @tabella = 'aker_accountingcostcenterdetails';
+
SET @tabella = '<%PREFIX%>_messages';
SET @indice = 'accountingcostcenter_id';
+
SET @indice = 'reference';
 
SET @exist := (SELECT COUNT(*) FROM information_schema.statistics WHERE `table_name` = @tabella and `index_name` = @indice and `table_schema` = database());
 
SET @exist := (SELECT COUNT(*) FROM information_schema.statistics WHERE `table_name` = @tabella and `index_name` = @indice and `table_schema` = database());
 
SET @sqlstmt := IF( @exist > 0 , CONCAT( 'ALTER TABLE ', @tabella, ' DROP INDEX ', @indice, ';' ), 'SELECT ''INFO: Indice non trovato.''');
 
SET @sqlstmt := IF( @exist > 0 , CONCAT( 'ALTER TABLE ', @tabella, ' DROP INDEX ', @indice, ';' ), 'SELECT ''INFO: Indice non trovato.''');

Versione attuale delle 15:35, 14 apr 2023

← Torna a MySQL

Articoli correlati

Esempi

Esempio #1

SET @exist := (SELECT COUNT(*) FROM information_schema.statistics WHERE `table_name` = '<nome-tabella>' and `index_name` = '<nome-indice>' and `table_schema` = database());
SET @sqlstmt := IF( @exist > 0 , 'ALTER TABLE `<nome-tabella>` DROP INDEX `<nome-indice>`;', 'SELECT ''INFO: Indice non trovato.''');
PREPARE stmt FROM @sqlstmt;
EXECUTE stmt;

Esempio #2

SET @tabella = '<%PREFIX%>_messages';
SET @indice = 'reference';
SET @exist := (SELECT COUNT(*) FROM information_schema.statistics WHERE `table_name` = @tabella and `index_name` = @indice and `table_schema` = database());
SET @sqlstmt := IF( @exist > 0 , CONCAT( 'ALTER TABLE ', @tabella, ' DROP INDEX ', @indice, ';' ), 'SELECT ''INFO: Indice non trovato.''');
PREPARE stmt FROM @sqlstmt;
EXECUTE stmt;