SQL statement used to create a regular MySQL table

Source: Internet
Author: User


SQL statement for MySQL to CREATE tables regularly -- view the event plan SELECT @ event_scheduler -- open the event plan www.2cto.com SET GLOBAL event_scheduler = 1 -- stored PROCEDURE, CREATE a table CREATE PROCEDURE create_table () every month () BEGIN declare str_date varchar (16); SET str_date = date_format (now (), "% Y % m"); SET @ sqlcmd1 = CONCAT ('create TABLE db_mail_message _ ', str_date, "(apptaskid varchar (100) not null, taskname varchar (200) not null, incluenduid varchar (200) not null, appreceiveuid varchar (100) not null, sendtime varchar (50) not null, handletime varchar (50) not null, url varchar (500) not null, remark varchar (500) not null, endtime varchar (50) not null, imapuid varchar (100) not null, addstatus int (1) not null default '0', readstatus int (1) not null default '0', deletestatus int (1) not null default '0 ', completestatus int (1) not null default '0', primary key (apptaskid), KEY db_imapuid_index (imapuid) ENGINE = MyISAM default charset = utf8 ;"); PREPARE p1 FROM @ sqlcmd1; EXECUTE p1; deallocate prepare p1; END -- create event: the stored procedure create event if not exists e_testON schedule every 1 secondon completion preservedo call test (); www.2cto.com -- creates an event every second: create event if not exists e_test on schedule every 1 month starts DATE_ADD (DATE_SUB (CURDATE (), interval day (CURDATE ()-1 DAY), INTERVAL 1 MONTH), INTERVAL 1 HOUR) on completion preserve do call test (); -- ENABLE event alter event e_test on completion preserve enable; -- DISABLE event alter event e_test on completion preserve disable;

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.