Batch Build MySQL Table

Source: Internet
Author: User

Today, with MySQL's sub-table problem, you can use scripting to iterate through the creation of a new table, or you can build it using SQL. The following is an example of establishing a player_0 to player_9 statement.

Delimiter//CREATE procedure create_table () BEGIN DECLARE ' @i ' int (11); DECLARE ' @sqlstr ' varchar (2560); SET ' @i ' = 0; While the ' @i ' < do SET @sqlstr = CONCAT ("CREATE TABLE player_",

' @i ',

"(' player_id ' int (one) not null auto_increment, ' account_id ' int (one) not null COMMENT ' user ID ', ' personaname ' varchar () NO T NULL COMMENT ' nickname ', PRIMARY KEY (' player_id ')) engine=innodb DEFAULT charset=utf8 comment= ' user table ' Auto_increment=1 '); Prepare stmt from @sqlstr; Execute stmt;
SET ' @i ' = ' @i ' + 1; END while; END; Call Create_table (); drop procedure create_table;

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.