Go deep into Mysql stored procedure table name use parameter to pass in the detailed _mysql

Source: Internet
Author: User
Tags prepare stmt

BEGIN

DECLARE date_str varchar (8);
DECLARE table_prefix varchar (20);
Set table_prefix= ' Mail_rare_visit_ ';
Set date_str = Date_format (Current_date (), '%y%m%d ');
Set @table_name = Concat (Table_prefix, DATE_STR);
Set @s = Concat (' CREATE TABLE ', @table_name, ' (
' id ' int (one) not NULL auto_increment,
' user_id ' int (one) is not NULL,
' city_id ' int (one) is not NULL,
' Email ' varchar not NULL,
' channel_id ' int (one) DEFAULT NULL,
' W_revenue ' decimal (7,6) not NULL DEFAULT 0.000000,
' W_buy ' decimal (7,6) not NULL DEFAULT 0.000000,
' W_browse ' decimal (7,6) not NULL DEFAULT 0.000000,
' rec_goods ' varchar DEFAULT NULL,
' Update_time ' timestamp not NULL DEFAULT current_timestamp on update current_timestamp,
PRIMARY KEY (' id '),
KEY ' idx_user_id ' (' user_id '),
KEY ' idx_city_id ' (' user_id '),
KEY ' idx_email ' (' email '),
KEY ' idx_channel_id ' (' channel_id ')
Engine=myisam DEFAULT Charset=utf8; ');

Prepare stmt from @s;
Execute stmt;

deallocate prepare stmt;

End

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.