Mysql batch Add a new column stored procedure in the table, mysql new

Source: Internet
Author: User
Tags mysql functions

Mysql batch Add a new column stored procedure in the table, mysql new

Generally, for websites with a large access volume, the request log table is created independently on a daily basis. 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 = '20140801';set eTime = '20140831';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!


How does mysql batch change a column of data?

The question is, are there any rules on the data you want to change?
As you wrote ,......, 25, 26. If there is a rule, it's easy.
You can use the Stored Procedure for batch processing.

Mysql batch insert

Saved as. SQL script
Then open the mysql command line,
Go to the directory where the script is stored (cd ).
Input: \. Full path of the SQL statement (including the SQL file name. Note that the path should be separated)
Enter
You can import data in batches.

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.