create  PROCEDURE insertinto
as
begin
declare @id int;
set @id=1;
while @id<10
begin
insert into person (id,name) values(@id,'123')
set @id=@id+1
end
end

批量插入数据:
定义变量,执行循环,将int转化为varchar。例如:convert(varchar(10),@bmc)

declare @name  varchar(50);
sql 批量插入-LMLPHPdeclare @pwd varchar(10);
sql 批量插入-LMLPHPset @pwd='123456';
sql 批量插入-LMLPHP    declare @bmc int;
sql 批量插入-LMLPHP        set @bmc=101;
sql 批量插入-LMLPHP     while(cast(@bmc as int) <120)
sql 批量插入-LMLPHP      begin
sql 批量插入-LMLPHP        set @name='TV8'+convert(varchar(10),@bmc);        
sql 批量插入-LMLPHP        insert into dbo.T_TopView_Admin(F_Psnid,F_status,F_BroPwd,F_Edittime,F_StartTime,F_EndTime,F_UserType) values('TV8'+convert(varchar(10),@bmc),1,'123456',getdate(),20080320,20090319,1)
sql 批量插入-LMLPHP        set @bmc=@bmc+1
sql 批量插入-LMLPHP      end

批量插入数据,这个实例是用户两个数据结构类似的两张表进行数据导入

declare @fid int;
sql 批量插入-LMLPHP    set @fid=1;
sql 批量插入-LMLPHPwhile @fid<100
sql 批量插入-LMLPHPbegin
sql 批量插入-LMLPHP    insert into T_Mail_Test_Attach(F_ID,F_ContentID,F_AttachName,F_AttachSize,F_AttachAddress,F_EditTime) select top 1 F_ID,F_MailID,F_AttachName,F_AttachSize,F_AttachAddr,F_EditTime from dbo.T_TLMail_Attach where F_ID>@fid order by F_ID asc
sql 批量插入-LMLPHP    set @fid=@fid+1
sql 批量插入-LMLPHPend

05-11 17:55