#添加用户、用户账户储存过程
drop procedure if exists insert_user;
create PROCEDURE insert_user(Max_number INT) #Max_number变量为插入最大数据量
BEGIN
DECLARE i INT;
DECLARE j INT;
DECLARE UserId LONG;
DECLARE AccountId LONG;
SET UserId=(SELECT MAX(user_id) from user); #获取用户表最后一条记录的user_id值
if UserId=NULL THEN
SET UserId=0;
END IF;
SET AccountId=(SELECT MAX(account_id) from user_account); #获取用户账户表最后一条记录的account_id值
if AccountId is NULL THEN
SET AccountId=0;
END IF;
SET i=10000;
SET j=0;
while j<Max_number do
set UserId=UserId+1;
set AccountId=AccountId+1;
insert into user VALUES(UserId,0,0,1,NULL,CONCAT('A',i),CONCAT('A',i),CONCAT('4302811988091',i)L); #用户表
insert into user_account VALUES(AccountId,UserId,'会员','999999999',1,NULL,CONCAT('137140',1),NOW()); #用户账户表
set i=i+1;
set j=j+1;
IF j=5000 THEN
SET j=0;
COMMIT;
end IF;
SELECT UserId,AccountId; #显示UserId,AccountId数量
end while;
COMMIT;
END
call insert_user(100000);