Batch create log table information script in MySQL

Source: Internet
Author: User

The Log Information table script is created in MySQL in bulk through stored procedures as follows:

Drop PROCEDURE if EXISTS reqsp;delimiter//create PROCEDURE reqsp (stime varchar (+), etime varchar (+), Tchema varchar (32) ) begindeclare sName varchar (1024);d eclare uid varchar (n);d eclare orderId varchar (+);d eclare sqlvar varchar (+/--);  Declare rest int;set rest = 1;while Rest > 0 Do set stime = (select Date_format (select Adddate (stime,1)), '%y%m%d '); Set sName = CONCAT (' tbl_resp_ ', stime); Set uid = CONCAT (' idx_id_resp_ ', stime); Set orderId = CONCAT (' idx_order_resp_ ', stime); Select COUNT (1) from information_schema.tables where table_name = SName and table_schema=tchema into @cnt; If @cnt = 0 Then Set sqlvar=concat (' CREATE table ', SName, ' (ID varchar () is not null, ', ' order varchar ') is not NULL,  ', ' ads int ' is not null, ', ' type varchar ' is not NULL, ', ' group Int (ten) not null, ', ' template int (ten) not null, ', ' Banner varchar (+) default null, ', ' app varchar (+) default null, ', ' create_time datetime not NULL, ', ' key ', UID , ' (UID), ', ' key ', OrderId, ' (Order_id) ', ') Engine=myisam DEFAULT Charset=utf8 '), set @v_s =sqlvar;prepare stmt from @v_s; EXECUTE stmt;deallocate PREPARE Stmt;end if; Set rest = DATEDIFF (etime,stime); END while;end;//DELIMITER;

Call REQSP (' 20141001 ', ' 20151001 ', ' dbname ')

First parameter start time 20141001

Second parameter end time 20151001

The third parameter is the database name

Batch create log table information script in MySQL

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.