Mysql inserts data into sub-tables, and mysql inserts data
Use mysql;
/* Create the original data table */
Drop table if exists 'articleinfo ';
Create table 'articleinfo '(
'Id' bigint unsigned not null AUTO_INCREMENT primary key,
'Title' VARCHAR (20) default null,
'Content' VARCHAR (20) default null,
'Comment _ time' VARCHAR (20) DEFAULT NULL
) ENGINE = InnoDB default charset = utf8 AUTO_INCREMENT = 1;
/* Create a stored procedure to add some data to the original data table */
Delimiter $
Drop procedure if exists proc_articleinfo;
Create procedure proc_articleinfo ()
Begin
Declare I int;
Set I = 1;
While (I <= 32) do
Insert into articleinfo (title, content, comment_time)
Values (concat ('database basics ', I), concat ('basic knowledge of hard learn', I % 4), DATE_FORMAT (NOW (), '% Y-% m-% d % H: % I: % s '));
Set I = I + 1;
End while;
End;
$
Delimiter;
/* Call the Stored Procedure */
Call proc_articleinfo ();
/* Create a sub-table */
Drop table if exists 'tb _ articleinfo_0 ';
Create table 'tb _ articleinfo_0 '(
'Id' bigint unsigned not null AUTO_INCREMENT primary key,
'Title' VARCHAR (20) default null,
'Content' VARCHAR (20) default null,
'Comment _ time' VARCHAR (20) DEFAULT NULL
) ENGINE = MyISAM default charset = utf8 AUTO_INCREMENT = 1;
Create table 'tb _ articleinfo_1 'LIKE 'tb _ articleinfo_0 ';
Create table 'tb _ articleinfo_2 'LIKE 'tb _ articleinfo_0 ';
Create table 'tb _ articleinfo_3 'LIKE 'tb _ articleinfo_0 ';
/* Create a master table */
Drop table if exists 'tb _ articleinfo ';
Create table 'tb _ articleinfo '(
'Id' bigint unsigned not null AUTO_INCREMENT,
'Title' VARCHAR (20) default null,
'Content' VARCHAR (20) default null,
'Comment _ time' VARCHAR (20) default null,
Index ('id ')
) ENGINE = MRG_MYISAM UNION = ('tb _ articleinfo_0 ', 'tb _ articleinfo_1', 'tb _ articleinfo_2 ', 'tb _ articleinfo_3 ') INSERT_METHOD = last default charset = utf8 AUTO_INCREMENT = 1;
/* Insert data to the sub-table */
Insert into tb_articleinfo_0 (title, content, comment_time)
Select title, content, comment_time from articleinfo where id % 4 = 0;
Insert into tb_articleinfo_1 (title, content, comment_time)
Select title, content, comment_time from articleinfo where id % 4 = 1;
Insert into tb_articleinfo_2 (title, content, comment_time)
Select title, content, comment_time from articleinfo where id % 4 = 2;
Insert into tb_articleinfo_3 (title, content, comment_time)
Select title, content, comment_time from articleinfo where id % 4 = 3;
Commit;
/* Query data */
Select * from articleinfo;
Select * from tb_articleinfo_0;
Select * from tb_articleinfo_1;
Select * from tb_articleinfo_2;
Select * from tb_articleinfo_3;