此存储过程实现批量添加随机数据到数据库中。
CREATE PROCEDURE add_UserInfo
AS
DECLARE @count INTEGER
DECLARE @index INTEGER
SET @count=(select max(id) from FlashList)
SET @index= 1
WHILE @index<=@count
BEGIN
INSERT INTO TableName(values,values,values,values)
VALUES (values,@index,cast(30000+10000*rand()as int) , cast(4000+1000*rand()as int) )
SET @index=@index+1
END
GO
/*--执行存储过程--*/
EXEC add_UserInfo
CREATE PROCEDURE add_UserInfo2
AS
declare @name varchar(20)
declare @sex varchar(10)
declare @age int
declare @maxId int
set @maxId=(select max(ID) from dbo.hr)
declare @i int
declare @j int
declare @per int
declare @newId int
set @i=0
set @j=0
set @per=8
set @newId=@maxId+1
while @i<32
begin
set @j=0
while @j<@per
begin
insert into dbo.hr(ID,name,age,sex,localAddress,remark,photo) values(@newId, @name, @age, @sex,@i, null,null)
set @j=@j+1
set @newId=@newId+1
end
set @i=@i+1
end
go