Microsoft has a few undocumented procedures that perform "foreach" operations on tables (sp_msforeachtable
) and databases (sp_msforeachdb
). Both of these rely on another undocumented proc called sp_msforeachworker
which you might be able to exploit to create a foreachschema type of routine. Theres an article (reg required) here that demonstrates this approach.
That said, its unlikely Azure supports anything of these, so you might have to fashion your own using a crude loop:
declare @schemas table (i int identity(1,1), name sysname);
insert into @schemas
select name from sys.schemas where name like 's[0-9]%';
declare @i int, @name sysname, @cmd nvarchar(max);
select @i = min(i) from @schemas;
while @i is not null
begin
select @name = name from @schemas where i = @i;
set @cmd = replace(N'select count(*) from [{0}].[Logs];', '{0}', @name);
print @cmd;
--exec(@cmd);
select @i = min(i) from @schemas where i > @i;
end