Mysql modifies the table name to uppercase stored procedures _mysql

Source: Internet
Author: User
Tags prepare table name

This article shares the MySQL stored procedure that modifies the table name to uppercase, as follows

1. Conditions:
1.1 MySQL settings are case sensitive
2. Execute the following stored procedures:

 #call uppercase (' Library name ') DROP PROCEDURE IF EXISTS uppercase;  
  
CREATE PROCEDURE Uppercase (in dbname VARCHAR) is 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 does FOUND SET done = 1;  
  
OPEN cur;  
  
REPEAT FETCH cur into oldname;  
SET @newname = UPPER (oldname);   
SET @isNotSame = @newname <> BINARY oldname;    
IF not do && @isNotSame THEN SET @SQL = CONCAT (' Rename table ', Oldname, ' to ', LOWER (@newname), ' _tmp ');   
PREPARE tmpstmt from @SQL;  

EXECUTE tmpstmt;   
SET @SQL = CONCAT (' Rename table ', LOWER (@newname), ' _tmp ' to ', @newname, ' ");   
PREPARE tmpstmt from @SQL; 
  
EXECUTE tmpstmt;  
  
Deallocate PREPARE tmpstmt;   
End IF;   
UNTIL do end REPEAT;   
Close cur; End 

3. Execute the statement
Call uppercase (' Library name ');

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.