create proc P_RandRecord @tablename varchar(25) as exec('select identity(int,1,1) as idd,* into #t from '+@tablename) select * into #t1 from #t where 1=2 declare @n int set @n=0 while @n<>10 begin insert into #t1 select * from #t where idd=(cast(rand()*100) as int) @n=@n+1 end select distinct top 10 * from #t1
select top 10 * from 表 order by newid()这样为什么不行? top 方法中,,top 10 后面不能直接用*或者为空,必须加详细列名
as
exec('select identity(int,1,1) as idd,* into #t from '+@tablename)
select * into #t1 from #t where 1=2
declare @n int
set @n=0
while @n<>10
begin
insert into #t1 select * from #t where idd=(cast(rand()*100) as int)
@n=@n+1
end
select distinct top 10 * from #t1
top 方法中,,top 10 后面不能直接用*或者为空,必须加详细列名