In-depth explanation of using parameters for table names in mysql stored procedures

Source: Internet
Author: User

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 (11) not null AUTO_INCREMENT,
'User _ id' int (11) not null,
'City _ id' int (11) not null,
'Email 'varchar (300) not null,
'Channel _ id' int (11) 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 (800) 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 _ e-mail '('email '),
KEY 'idx _ channel_id '('Channel _ id ')
) ENGINE = MyISAM default charset = utf8 ;');

Prepare stmt from @ s;
Execute stmt;

DEALLOCATE prepare stmt;

End

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.