Mysql batch add a new column stored procedure in the table _ MySQL

Source: Internet
Author: User
Tags mysql functions
For websites with a large access volume, the request log table adds a new column for each table to create a business independently for each table every day. after a long time, the stored procedure is as follows: the log table structure type is tbl_ads_req_20140801 and tbl_ads_req_20140802DELIMITER. the request log table is created independently on a single table every day. the business needs to add a new column for each table. after a long time, the stored procedure is as follows:

Log table structure type tbl_ads_req_20140801, tbl_ads_req_20140802...

DELIMITER // create procedure sp2 () begindeclare sTime varchar (32); declare eTime varchar (32); declare sName varchar (128); declare lName varchar (128 ); declare sqlVar varchar (128); declare rest int; set sTime = '000000'; set eTime = '000000'; set sName = CONCAT ('tbl _ ads_req _', ''); set lName =''; set rest = 1; while rest> 0 do set sTime = (select DATE_FORMAT (select ADDDATE (sTime, 1 )), '% Y % m % d'); set lName = CONCAT (sName, sTime); set sqlVar = CONCAT ('alter table', lName, 'Add app_package varchar (64) '); set @ v_s = sqlVar; prepare stmt from @ v_s; EXECUTE stmt; set rest = DATEDIFF (eTime, sTime); END while; end; // DELIMITER;

Some mysql functions need to be checked by yourself!

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.