MySQLストレージを使用した高速なマルチスコアテーブルの作成
2569 ワード
常にデータベースを設計し、分割テーブルの数が多い場合があり、単一の作成に時間がかかる場合があります.そこで、ストレージテンプレートを書き、複数の分割テーブルを迅速に作成できます.たとえば、次のようにします.
--
DROP PROCEDURE IF EXISTS `gameLog_month`;
create procedure gameLog_month(in val_s int, in val_e int)
begin
declare i int;
set i=val_s;
while ido
set @sql_create_table = concat(
'CREATE TABLE IF NOT EXISTS hunan_db_log_', i,
"(
`id` int(11) NOT NULL AUTO_INCREMENT,
`gameType` varchar(20) DEFAULT '' COMMENT ' ',
`userId` int(11) DEFAULT 0 COMMENT ' id',
`deskId` int(11) DEFAULT 0 COMMENT ' ID',
`deskNum` tinyint(2) DEFAULT 0 COMMENT ' 1;2;3;4;5;6,1 ',
`tableMode` tinyint(2) DEFAULT 0 COMMENT ' :5 ',
`score` int(11) DEFAULT 0 COMMENT ' ',
`scoreBase` int(11) DEFAULT 0 COMMENT ' ',
`playSign` int(11) DEFAULT 0 COMMENT ' ',
`agentId` int(11) DEFAULT 0 COMMENT ' ID',
`logTime` int(11) DEFAULT 0 COMMENT ' ',
`winlevel` tinyint(2) DEFAULT 0 COMMENT ' 0-10, 0 ,10 ',
`createTime` datetime DEFAULT NULL COMMENT ' ',
PRIMARY KEY (`id`),
INDEX `gameType` (`gameType`) USING BTREE,
INDEX `userId` (`userId`) USING BTREE,
INDEX `logTime` (`logTime`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT=' , '
");
PREPARE sql_create_table FROM @sql_create_table;
EXECUTE sql_create_table;
set i=i+1;
end while;
end;