概述
批量创建表,先写个函数(详情看下面),然后执行call 函数名(注意不要忘记写参数)
CREATE DEFINER=tequila
@%
PROCEDURE anno_ncbi_rel
(in val_s int, in val_e int)
begin
declare i int;
set i=val_s;
while i<val_e+1 do
set @sql_create_table = concat(
‘CREATE TABLE IF NOT EXISTS anno_ncbi_rel_’, i,
"(
ncbi_rel_id
int(12) NOT NULL AUTO_INCREMENT COMMENT ‘主键id’,
chr
char(2) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT ‘染色体编号’,
pos
int(32) NOT NULL COMMENT ‘pos’,
gene
varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT ‘基因名’,
ncbi_transcript_id
varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT ‘nm号’,
strand
char(2) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT ‘正负链’,
cds
varchar(12) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT ‘蛋白质编码区’,
exon
varchar(12) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT ‘外显子区’,
PRIMARY KEY (ncbi_rel_id
) USING BTREE,
INDEX chr
(chr
) USING BTREE,
INDEX pos
(pos
) USING BTREE
) ENGINE = MyISAM AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
");
PREPARE sql_create_table FROM @sql_create_table;
EXECUTE sql_create_table;
set i=i+1;
end while;
end
最后
以上就是大气黑夜为你收集整理的mysql批量创建表1-500的全部内容,希望文章能够帮你解决mysql批量创建表1-500所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复