目前有三张表 分别是user ,character 和user_character_relation
三个表的id字段都是自动增长的,我想对user_character_relation(id,user_id,character_id)这个表进行批量插入,其格式是
id user_id character_id
1 1 1
2 1 2
3 1 3
4 1 4
5 1 5
6 1 6
7 2 7
8 2 8
9 2 9
10 2 10
11 2 11
12 2 12
我写的 SQL语句是这样的 求大神修改
drop procedure if exists emind;
delimiter//
create procedure emind()
begin
delclare i int default 0;
delclare j int default 0;
select conut(*) into i from user;
select i; select conut(*) into j from `character`; select j; while i<(怎么填写) do while j<(怎么填写) do
insert into user_character_relation(`user_id`,`character_id`)values(i,j); (select i=i%6+1;)//感觉写的不对
( select j=j+1;)
end while;
end;//. . .
. . .
三个表的id字段都是自动增长的,我想对user_character_relation(id,user_id,character_id)这个表进行批量插入,其格式是
id user_id character_id
1 1 1
2 1 2
3 1 3
4 1 4
5 1 5
6 1 6
7 2 7
8 2 8
9 2 9
10 2 10
11 2 11
12 2 12
我写的 SQL语句是这样的 求大神修改
drop procedure if exists emind;
delimiter//
create procedure emind()
begin
delclare i int default 0;
delclare j int default 0;
select conut(*) into i from user;
select i; select conut(*) into j from `character`; select j; while i<(怎么填写) do while j<(怎么填写) do
insert into user_character_relation(`user_id`,`character_id`)values(i,j); (select i=i%6+1;)//感觉写的不对
( select j=j+1;)
end while;
end;//. . .
. . .
解决方案 »
- mySQL 获取当前连接数据的账号名
- Can't connect to MySQL server on '127.0.0.1' 10061
- Mysql 字符串和数字转换问题,我新手请指教,谢谢了
- 关于索引的弱智问题,这是本人在CSDN上第一次发帖,处女座,久闻CSDN人很热心
- 求某个版本的MYSQL
- 关于mysql_stmt_prepare()的错误
- 关于MYSQL视图更新问题,求教!!
- 如何将图片存入到mysql数据库中?
- mysql 怎么样把空值或null查询出来
- 话题与回复
- MYSQL5.5.38的my.cnf参数选项设置问题
- 求助怎么取两个关联表中的自增长字段赋值到存储过程中给第三个表批量添加数据
while @i <= i do
set @j = 1;
while @j <= j do
insert into user_character_relation(`user_id`,`character_id`)values(@i,@j);
set @j = @j + 1;
end while;
set @i = @i + 1;
end while;