试试这个:declare @tb_name nvarchar(100)
declare @i int
declare @tb table(id int identity(1,1),name nvarchar(1000))set @i = 1
set @tb_name = 't' --以这个值开头的所有表
insert into @tb(name)
select t.name
from sys.tables t
where t.name like @tb_name+'%'
while @i <= (select COUNT(*) from @tb)
begin
select @tb_name = name from @tb where id = @i;
exec('select * from '+@tb_name);
set @i = @i + 1
end
declare @i int
declare @tb table(id int identity(1,1),name nvarchar(1000))set @i = 1
set @tb_name = 't' --以这个值开头的所有表
insert into @tb(name)
select t.name
from sys.tables t
where t.name like @tb_name+'%'
while @i <= (select COUNT(*) from @tb)
begin
select @tb_name = name from @tb where id = @i;
exec('select * from '+@tb_name);
set @i = @i + 1
end
BEGIN DROP TABLE #temp END
DECLARE @index int , @count int , @schemaname varchar(50) , @tablename varchar(50)
set @index=1
set @count=(select count(*) from sysobjects where xtype='U' AND name LIKE 't%' )----数据库中有多少个表select row_number() over(order by name) as rowNumber,name,
( SELECT a.name from sys.tables t inner join sys.schemas a ON t.schema_id=a.schema_id WHERE t.name=ob.name) as schemaname
into #temp from sysobjects ob where xtype='U' ---具体要显示的表名
-- select * from #tempWHILE(@index<@count)
BEGIN
set @schemaname=(SELECT schemaname from #temp where rowNumber=@index)
set @tablename=(SELECT name from #temp where rowNumber=@index)
exec('select * from '+ @schemaname+'.'+@tablename)
set @index=@index+1
END