我有一个程序在表中随机填充记录。 但是当我执行该过程时,该过程只插入一行。 可以帮助任何人!
create procedure aa
( @row INT
)
as
begin
declare @numint as int
declare @string as VARCHAR(10)
declare @length as INT
declare @code as INT
declare @oid as uniqueidentifier
set @numint =0;
WHILE @numint <= @row
BEGIN
SET @numint = @numint + 1;
set @oid = newid();
SET @length = ROUND(10*RAND(),0);
SET @string = '';
WHILE @length > 0 BEGIN
SET @length = @length-1;
SET @code = ROUND(10*RAND(),0) - 1;
IF @code BETWEEN 1 AND 26
SET @string = @string + CHAR(ASCII('a')+@code-1);
ELSE
SET @string = @string + ' ';
END
end
-- Ready for the record
SET NOCOUNT ON;
INSERT INTO test_table VALUES (
@oid,
@numint,
ROUND(2000000*RAND()-1000000,2),
CONVERT(DATETIME, ROUND(50000*RAND()-10000,2)),
@string
)
END
exec procedure '10'
答案 0 :(得分:0)
您的insert语句不在循环中。将它向上移动到第一个循环内部,你应该得到正确的行数。