Sunday 15 April 2012

sql - How do I create an index from a stored procedure or create index on every table in MySQL? -


These are two things I have tried with their error messages so far:

  DELIMITER // create the manufacturing process ModifiedIndex (t varchar (256)) declare the newer version (256); DECLARE i int; MakeIndexSql varchar declared (256); Set idx = concat ('idx_', t, '_modified_on'); Set i = (selection number (*) from INFORMATION_SCHEMA. STATISTICS where table_name = t and index_name = idx); If i & gt; 0 then setindxqual = concat ('create index', idx, 'on', 't,' (modified_on); '); Prepare STMT with MakeIndexSql; Stmt executed; end if; END // DELIMITER; Call Enhanced Indices ('AHDibit Frequencies'); Call createModifiedIndex ...  

Error 1064 (42000) on line 5: There is an error in your SQL syntax; Check the manual that matches your MySQL server version, which is for the right syntax to use near the 'Make Index SQL'; Stmt executed; end if; This is another attempt but it will not work because MySQL does not allow IF / THEN outside the stored procedures.

   
  set @i = (INFORMATION_SCHEMA.STATISTICS from selection number (*) where table_name = 'ACHDebitFrequencies' and index_name = 'idx_ACHDebitFrequencies_modified_on'); If @ m & gt; 0 Then start creating index 'idx_ACHDebitFrequencies_modified_on' on HD video frequency (revised_on); End; end if; ...   

ERROR 1064 (42000) on line 3: There is an error in your SQL syntax; Closest 'if @ i & gt; To use the correct syntax, check the manual related to your MySQL server version. 0 Then start the object 'idx_ACHDebitFrequencies_modified_on' on ACHD on line 1

version mysql-5.1.62-r1

The main problem with your process was that the PREPARE statement only works with user variables or strings. It can not prepare a statement from any procedure variation.


before creating st_tm_stmt
... ready_stmt is either a string literal or user Variable which contains the text of the SQL statement. "lang-sql prettyprint-override"> DELIMITER // create process ModifiedIndex (T VARARAR (256)) IDA VARCHAR (256); DECLARE I INT; SET idx = CONCAT ('idx_', t, '_modified_on'); SET i = (SELECT COUNT (*) information from SOCEMA.SATATICS, where table_name = t and index_name = idx); IF I = 0 THEN SET @makeIndexSQL = CONCAT ('Create Index', idx, 'ON', T, '(modified_on);'); Prepare STMT from @Make Index SQL; EXTUTE STMT; DEALLOCATE STMT; - Use DEALLOCATE when you are finished with the statement IF; END // DELIMITER;

No comments:

Post a Comment