查询相应的表检查
1.3 深入一个,创建一个一次能插入多条数据的存储过程
代码块
create procedure proc_add
(
number int -- 打算新插入多少条数据
)
begin
declare v_name varchar(20);
declare v_i int;
set v_i=0;
select max(id) into v_i from student; -- 获得当前表中最大id,并存储进变量v_i
set number=v_i+number; -- 最大id
set v_i=v_i+1; -- 插入的id从当前id+1开始
while v_i<=number do -- 插入的id值从id+1 ~ number
set v_name=concat('bill' , v_i ); -- 拼接name,因为name不能相同
INSERT INTO `student` VALUES (v_i, v_name, 'male', '20', '2011-07-16' );
INSERT INTO `detail_info` VALUES (v_i, v_name, '2011-08-16 22:05:45', '13881954050', 'xinjiang');
set v_i=v_i + 1;
end while;
end;