declare @tb_name as varchar(50);
declare @sql as varchar(200);
DECLARE cur_tb CURSOR FORWARD_ONLY for
SELECT NAME FROM sysobjects t WHERE t.xtype='U';
open cur_tb;
fetch next from cur_tb into @tb_name;
while @@FETCH_STATUS = 0
begin
set @sql='select top 5 * from '+@tb_name;
exec(@sql);
fetch next from cur_tb into @tb_name;
end
close cur_tb
deallocate cur_tb
SQL Server中查询所有表的前5条数据
最新推荐文章于 2022-01-14 16:54:43 发布