Change the names of Mysql database tables to uppercase bitsCN.com in batches.
Change the names of Mysql database tables to uppercase in batches
[SQL] DELIMITER // DROP PROCEDURE IF EXISTS uppercase // CREATE PROCEDURE uppercase (IN dbname VARCHAR (200) BEGIN DECLARE done INT DEFAULT 0; DECLARE oldname VARCHAR (200 ); DECLARE cur cursor for select table_name FROM information_schema.TABLES WHERE table_schema = dbname; declare continue handler for not found set done = 1; OPEN cur; repeat fetch cur INTO oldname; SET @ newname = UPPER (oldname); # IF newname equals to oldname, do nothing; # select 'A' <> 'A '; -> 0 # select 'A' <> BINARY 'A';-> 1 SET @ isNotSame = @ newname <> BINARY oldname; if not done & @ isNotSame then set @ SQL = CONCAT ('Rename table', oldname, 'to', @ newname); PREPARE tmpstmt FROM @ SQL; EXECUTE tmpstmt; deallocate prepare tmpstmt; end if; UNTIL done end repeat; CLOSE cur; END // DELIMITER; # call the stored procedure # call uppercase ('database name ');#
BitsCN.com