创建100张相同格式的表,如何写sql

kelly859 2012-06-28 11:45:48
如上,需要创建xxx_00、xxx_01...xxx_99,格式相同,有没有快速建表语句啊,不需要一个一个的创建,试了下不行

CREATE TABLE xxx_00,xxx_01,xxx_02...这样是语法错误的
...全文
172 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
rucypli 2012-06-28
  • 打赏
  • 举报
回复
在shell里面写个循环机行了
小小小小蜗牛 2012-06-28
  • 打赏
  • 举报
回复
写个触发器
在触发器里面添加一个创建循环 当添加删除修改的时候 就。。。
没试过 不知道可不可行
Barton 2012-06-28
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 的回复:]

可以利用EXCEL中生成如下语句。
CREATE TABLE xxx_00 (id int primary key, c int, f1 int);
CREATE TABLE xxx_01 (id int primary key, c int, f1 int);
CREATE TABLE xxx_02 (id int primary key, c int, f1 int);
CREATE……
[/Quote]

你这做法跟我公司一位同仁很相似,每次更新或者是insert数据他就用excel生成几千行的代码,然后执行。
wwwwb 2012-06-28
  • 打赏
  • 举报
回复
for /l %%i in (1,1,10) do (d:\mysql55\bin\mysql -uroot -p123 aa -e "create table xxx_%%i(a int)" )
ACMAIN_CHM 2012-06-28
  • 打赏
  • 举报
回复
可以利用EXCEL中生成如下语句。
CREATE TABLE xxx_00 (id int primary key, c int, f1 int);
CREATE TABLE xxx_01 (id int primary key, c int, f1 int);
CREATE TABLE xxx_02 (id int primary key, c int, f1 int);
CREATE TABLE xxx_03 (id int primary key, c int, f1 int);
CREATE TABLE xxx_04 (id int primary key, c int, f1 int);
CREATE TABLE xxx_05 (id int primary key, c int, f1 int);
CREATE TABLE xxx_06 (id int primary key, c int, f1 int);
CREATE TABLE xxx_07 (id int primary key, c int, f1 int);
CREATE TABLE xxx_08 (id int primary key, c int, f1 int);
CREATE TABLE xxx_09 (id int primary key, c int, f1 int);
CREATE TABLE xxx_10 (id int primary key, c int, f1 int);
CREATE TABLE xxx_11 (id int primary key, c int, f1 int);
CREATE TABLE xxx_12 (id int primary key, c int, f1 int);
CREATE TABLE xxx_13 (id int primary key, c int, f1 int);
CREATE TABLE xxx_14 (id int primary key, c int, f1 int);
CREATE TABLE xxx_15 (id int primary key, c int, f1 int);
CREATE TABLE xxx_16 (id int primary key, c int, f1 int);
CREATE TABLE xxx_17 (id int primary key, c int, f1 int);
CREATE TABLE xxx_18 (id int primary key, c int, f1 int);
CREATE TABLE xxx_19 (id int primary key, c int, f1 int);
CREATE TABLE xxx_20 (id int primary key, c int, f1 int);
CREATE TABLE xxx_21 (id int primary key, c int, f1 int);
CREATE TABLE xxx_22 (id int primary key, c int, f1 int);
CREATE TABLE xxx_23 (id int primary key, c int, f1 int);
CREATE TABLE xxx_24 (id int primary key, c int, f1 int);
CREATE TABLE xxx_25 (id int primary key, c int, f1 int);
CREATE TABLE xxx_26 (id int primary key, c int, f1 int);
CREATE TABLE xxx_27 (id int primary key, c int, f1 int);
CREATE TABLE xxx_28 (id int primary key, c int, f1 int);
CREATE TABLE xxx_29 (id int primary key, c int, f1 int);
CREATE TABLE xxx_30 (id int primary key, c int, f1 int);
CREATE TABLE xxx_31 (id int primary key, c int, f1 int);
CREATE TABLE xxx_32 (id int primary key, c int, f1 int);
CREATE TABLE xxx_33 (id int primary key, c int, f1 int);
CREATE TABLE xxx_34 (id int primary key, c int, f1 int);
CREATE TABLE xxx_35 (id int primary key, c int, f1 int);
CREATE TABLE xxx_36 (id int primary key, c int, f1 int);
CREATE TABLE xxx_37 (id int primary key, c int, f1 int);
CREATE TABLE xxx_38 (id int primary key, c int, f1 int);
CREATE TABLE xxx_39 (id int primary key, c int, f1 int);
CREATE TABLE xxx_40 (id int primary key, c int, f1 int);
CREATE TABLE xxx_41 (id int primary key, c int, f1 int);
CREATE TABLE xxx_42 (id int primary key, c int, f1 int);
CREATE TABLE xxx_43 (id int primary key, c int, f1 int);
CREATE TABLE xxx_44 (id int primary key, c int, f1 int);
CREATE TABLE xxx_45 (id int primary key, c int, f1 int);
CREATE TABLE xxx_46 (id int primary key, c int, f1 int);
CREATE TABLE xxx_47 (id int primary key, c int, f1 int);
CREATE TABLE xxx_48 (id int primary key, c int, f1 int);
CREATE TABLE xxx_49 (id int primary key, c int, f1 int);
CREATE TABLE xxx_50 (id int primary key, c int, f1 int);
CREATE TABLE xxx_51 (id int primary key, c int, f1 int);
CREATE TABLE xxx_52 (id int primary key, c int, f1 int);
CREATE TABLE xxx_53 (id int primary key, c int, f1 int);
CREATE TABLE xxx_54 (id int primary key, c int, f1 int);
CREATE TABLE xxx_55 (id int primary key, c int, f1 int);
CREATE TABLE xxx_56 (id int primary key, c int, f1 int);
CREATE TABLE xxx_57 (id int primary key, c int, f1 int);
CREATE TABLE xxx_58 (id int primary key, c int, f1 int);
CREATE TABLE xxx_59 (id int primary key, c int, f1 int);
CREATE TABLE xxx_60 (id int primary key, c int, f1 int);
CREATE TABLE xxx_61 (id int primary key, c int, f1 int);
CREATE TABLE xxx_62 (id int primary key, c int, f1 int);
CREATE TABLE xxx_63 (id int primary key, c int, f1 int);
CREATE TABLE xxx_64 (id int primary key, c int, f1 int);
CREATE TABLE xxx_65 (id int primary key, c int, f1 int);
CREATE TABLE xxx_66 (id int primary key, c int, f1 int);
CREATE TABLE xxx_67 (id int primary key, c int, f1 int);
CREATE TABLE xxx_68 (id int primary key, c int, f1 int);
CREATE TABLE xxx_69 (id int primary key, c int, f1 int);
CREATE TABLE xxx_70 (id int primary key, c int, f1 int);
CREATE TABLE xxx_71 (id int primary key, c int, f1 int);
CREATE TABLE xxx_72 (id int primary key, c int, f1 int);
CREATE TABLE xxx_73 (id int primary key, c int, f1 int);
CREATE TABLE xxx_74 (id int primary key, c int, f1 int);
CREATE TABLE xxx_75 (id int primary key, c int, f1 int);
CREATE TABLE xxx_76 (id int primary key, c int, f1 int);
CREATE TABLE xxx_77 (id int primary key, c int, f1 int);
CREATE TABLE xxx_78 (id int primary key, c int, f1 int);
CREATE TABLE xxx_79 (id int primary key, c int, f1 int);
CREATE TABLE xxx_80 (id int primary key, c int, f1 int);
CREATE TABLE xxx_81 (id int primary key, c int, f1 int);
CREATE TABLE xxx_82 (id int primary key, c int, f1 int);
CREATE TABLE xxx_83 (id int primary key, c int, f1 int);
CREATE TABLE xxx_84 (id int primary key, c int, f1 int);
CREATE TABLE xxx_85 (id int primary key, c int, f1 int);
CREATE TABLE xxx_86 (id int primary key, c int, f1 int);
CREATE TABLE xxx_87 (id int primary key, c int, f1 int);
CREATE TABLE xxx_88 (id int primary key, c int, f1 int);
CREATE TABLE xxx_89 (id int primary key, c int, f1 int);
CREATE TABLE xxx_90 (id int primary key, c int, f1 int);
CREATE TABLE xxx_91 (id int primary key, c int, f1 int);
CREATE TABLE xxx_92 (id int primary key, c int, f1 int);
CREATE TABLE xxx_93 (id int primary key, c int, f1 int);
CREATE TABLE xxx_94 (id int primary key, c int, f1 int);
CREATE TABLE xxx_95 (id int primary key, c int, f1 int);
CREATE TABLE xxx_96 (id int primary key, c int, f1 int);
CREATE TABLE xxx_97 (id int primary key, c int, f1 int);
CREATE TABLE xxx_98 (id int primary key, c int, f1 int);
CREATE TABLE xxx_99 (id int primary key, c int, f1 int);
rucypli 2012-06-28
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

写个存储过程,然后调用;
DELIMITER //
CREATE PROCEDURE demo_in_test(IN p_in int)
BEGIN
declare i int;
set i=0;
while i<p_in do
//这里写创建表的语句,表明当然是变化的哦
set i=i+1;
en……
[/Quote]

DELIMITER //
CREATE PROCEDURE demo_in_test(IN p_in int)
BEGIN
declare i int;
set i=0;
while i<p_in do
set @sql=concat('create table xxx_',i,'(a int)');
prepare stmt from @sql;
execute stmt;
set i=i+1;
end while;
END;
rucypli 2012-06-28
  • 打赏
  • 举报
回复
for i in `seq 1 100`
do
mysql -uroot -pxxx dbname -e "create table xxx_$i(a int)"
done
libo_sina 2012-06-28
  • 打赏
  • 举报
回复
写个存储过程,然后调用;
DELIMITER //
CREATE PROCEDURE demo_in_test(IN p_in int)
BEGIN
declare i int;
set i=0;
while i<p_in do
//这里写创建表的语句,表明当然是变化的哦
set i=i+1;
end while;
END;

kelly859 2012-06-28
  • 打赏
  • 举报
回复
我想在sql脚本里写

56,677

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧