Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


how to check the Schema Objects Details in Each Database using SP


how to check the Schema Objects Details in Each Database using SP

Author
Message
sps-554505
sps-554505
Valued Member
Valued Member (67 reputation)Valued Member (67 reputation)Valued Member (67 reputation)Valued Member (67 reputation)Valued Member (67 reputation)Valued Member (67 reputation)Valued Member (67 reputation)Valued Member (67 reputation)

Group: General Forum Members
Points: 67 Visits: 224
Also I would need couple of details ,could you help me
---
This is what I needed,
1)Objects which do not belong to DBO

This is the query we are using to find out

select schema_name(schema_id)as ObjectName, name,type,type_desc from sys.objects
where schema_name(schema_id) <> 'dbo'
and type in('U','P','V', 'FN','TF','IF','PK','UQ')
go

2)Database users which do not have DBO as their default schema

SELECT *
FROM sys.database_principals
WHERE [type] IN ('U','S')
AND ISNULL(default_schema_name,'')<>'dbo'

We would like to create a report out of it and let a procedure run in every instance on a daily basis. The procedures should write the information into seperate tables in theOne of DB(Like ABC)database
I need to have the Sp in one Database and it needs to check all the Database and fetch the details into separate tables as per the database name

Could you please help me
magasvs
magasvs
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1285 Visits: 752
Hi,
You may use these two ways:

1) Build dynamic query:

SET NOCOUNT ON

DECLARE @db NVARCHAR (50), @sqlStr NVARCHAR(4000)
DECLARE @tbl_dbs TABLE (dbName NVARCHAR(50))

INSERT @tbl_dbs SELECT Name from master.sys.databases

WHILE EXISTS
(SELECT dbName FROM @tbl_dbs)

BEGIN

SELECT TOP 1 @db = dbName
, @sqlStr = 'INSERT ABC..YourTable (ObjectName, name,type,type_desc ) SELECT schema_name(schema_id)as ObjectName, name,type,type_desc
from ' + @db + '.sys.objects
where schema_name(schema_id) <> ''dbo''
and type in(''U'',''P'',''V'', ''FN'',''TF'',''IF'',''PK'',''UQ'')'
FROM @tbl_dbs

EXEC master.dbo.sp_executesql @sqlStr

DELETE FROM @tbl_dbs
WHERE dbName = @db

END

2) Use undocumented stored procedure (which is not actually recommended):

EXEC sp_MSforeachDB 'INSERT ABC..YourTable (ObjectName, name,type,type_desc )
SELECT schema_name(schema_id)as ObjectName, name,type,type_desc
from ?.sys.objects
where schema_name(schema_id) <> ''dbo''
and type in(''U'',''P'',''V'', ''FN'',''TF'',''IF'',''PK'',''UQ'')'
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search