T-SQL生成随机记录

方法一:while循环

create table #s(id int identity(1,1) primary key,name nvarchar(20),age int)
declare @i int
set @i = 1
while(@i<=10)
begin
    insert into #s(name,age) values(left(newid(),8),rand()*100)
    set @i = @i + 1
end
select * from #s
drop table #s

方法二:go语句(sql2005+)

create table #s(id int identity(1,1) primary key,name nvarchar(20),age int)
go --必需
insert into #s(name,age) values(left(newid(),8),rand()*100)
go 10 --执行10次
select * from #s
drop table #s


评论: 0 | 引用: 0 | 查看次数: 3915
发表评论
登录后再发表评论!