fho
asked on
single procedure against multiple databases
Hi
I want to create a single procedure in master that will be called within a loop in each database of my server.
The goal is to count objects of each of my 500 databases and to report them.
It works when I launch the dynamic query while connected in a database, but it returns the report for master when I exec the proc.
use mydb
exec master..myproc
returns number of objects by type for the master database.
Stored procedure that I want to exec in each of my 500 databases:
create proc myproc
as
set nocount on
print 'Server : ' + @@servername
print 'Database : ' + db_name()
print ''
print '************************* ********** ********** ********** ********** ********** ********** *******'
print 'Object number by Type for database : ' + db_name()
print '************************* ********** ********** ********** ********** ********** ********** *******'
print ''
select substring(v.name,5,31) as 'Type d''objet', count(o.xtype) as 'Nombre d''objets'
from sysobjects o, master.dbo.spt_values v
where o.xtype = substring(v.name,1,2) collate database_default and v.type = 'O9T'
group by v.name
order by v.name
TIA
Fred
I want to create a single procedure in master that will be called within a loop in each database of my server.
The goal is to count objects of each of my 500 databases and to report them.
It works when I launch the dynamic query while connected in a database, but it returns the report for master when I exec the proc.
use mydb
exec master..myproc
returns number of objects by type for the master database.
Stored procedure that I want to exec in each of my 500 databases:
create proc myproc
as
set nocount on
print 'Server : ' + @@servername
print 'Database : ' + db_name()
print ''
print '*************************
print 'Object number by Type for database : ' + db_name()
print '*************************
print ''
select substring(v.name,5,31) as 'Type d''objet', count(o.xtype) as 'Nombre d''objets'
from sysobjects o, master.dbo.spt_values v
where o.xtype = substring(v.name,1,2) collate database_default and v.type = 'O9T'
group by v.name
order by v.name
TIA
Fred
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.