USE MASTER;
DECLARE @name sysname;
DECLARE @sql nvarchar(max) = '
SELECT
DB_NAME() AS [database_name],
OBJECT_SCHEMA_NAME(object_id) AS [schema_name],
name AS ObjectName,
type,
type_desc
FROM sys.objects Where type in (''FN'',''U'',''V'',''IT'',''P '')
';
DECLARE @theSQL nvarchar(max);
DECLARE @results TABLE (
[database_name] sysname,
[schema_name] sysname,
[ObjectName] sysname,
[type] sysname,
[type_desc] sysname
);
DECLARE dbs CURSOR STATIC LOCAL FORWARD_ONLY READ_ONLY
FOR
SELECT name
FROM sys.databases
-- you may want to exclude system databases here
WHERE name NOT IN ('master', 'model', 'msdb', 'tempdb', 'distribution')
And state_desc!='OFFLINE'
OPEN dbs;
FETCH NEXT FROM dbs INTO @name;
WHILE @@FETCH_STATUS = 0
BEGIN
SET @theSQL = 'EXEC ' + QUOTENAME(@name) + '.sys.sp_executesql @sql';
INSERT @results
EXEC sys.sp_executesql @theSQL, N'@sql nvarchar(max)', @sql
FETCH NEXT FROM dbs INTO @name;
END
CLOSE dbs;
DEALLOCATE dbs;
SELECT *
FROM @results;
DECLARE @name sysname;
DECLARE @sql nvarchar(max) = '
SELECT
DB_NAME() AS [database_name],
OBJECT_SCHEMA_NAME(object_id) AS [schema_name],
name AS ObjectName,
type,
type_desc
FROM sys.objects Where type in (''FN'',''U'',''V'',''IT'',''P '')
';
DECLARE @theSQL nvarchar(max);
DECLARE @results TABLE (
[database_name] sysname,
[schema_name] sysname,
[ObjectName] sysname,
[type] sysname,
[type_desc] sysname
);
DECLARE dbs CURSOR STATIC LOCAL FORWARD_ONLY READ_ONLY
FOR
SELECT name
FROM sys.databases
-- you may want to exclude system databases here
WHERE name NOT IN ('master', 'model', 'msdb', 'tempdb', 'distribution')
And state_desc!='OFFLINE'
OPEN dbs;
FETCH NEXT FROM dbs INTO @name;
WHILE @@FETCH_STATUS = 0
BEGIN
SET @theSQL = 'EXEC ' + QUOTENAME(@name) + '.sys.sp_executesql @sql';
INSERT @results
EXEC sys.sp_executesql @theSQL, N'@sql nvarchar(max)', @sql
FETCH NEXT FROM dbs INTO @name;
END
CLOSE dbs;
DEALLOCATE dbs;
SELECT *
FROM @results;
No comments:
Post a Comment