SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Finding Object On Your SQL Instance


Finding Object On Your SQL Instance

Author
Message
Site Owners
Site Owners
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: Administrators
Points: 13663 Visits: 62
Comments posted to this topic are about the item Finding Object On Your SQL Instance
Kalyan@Boddupalli
Kalyan@Boddupalli
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 26
Just curious to know, in what kind of situation do we need to know the existence of an object in a db??

Thanks,
Kalyan
Paul.Andrew
Paul.Andrew
SSC-Enthusiastic
SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)

Group: General Forum Members
Points: 168 Visits: 152
In one of our data warehouses we deploy similar database schemes to handle customer data sets. From time to time it's useful to know which databases contain the same objects, which in turn is helpful to our analysts knowing they can point quieries at different custommer databases without consequence.

Then sometimes scrolling down a huge tree of tables or filtering the tree is just to much effort compared to pressing F5 :-)

Thanks for looking
janis.l.murphy
janis.l.murphy
SSC Journeyman
SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)SSC Journeyman (85 reputation)

Group: General Forum Members
Points: 85 Visits: 127
Thanks for giving me something to chew on. Another way to do this is something like this:


DECLARE @DatabaseName VARCHAR(126)
DECLARE @Object VARCHAR(126)
DECLARE @dbList TABLE(DatabaseName VARCHAR(126), QualifiedName VARCHAR(MAX))
--Enter object you are trying to find:
-- (The object name MAY contain schema.
-- If it does, that will be added to the search criteria)
SET @Object = '<<object name>>'

DECLARE @SQL VARCHAR(MAX)

SET @SQL = 'USE [?];DECLARE @db VARCHAR(100) = ''?'';
DECLARE @schemaId INT = SCHEMA_ID(PARSENAME(''' + @Object + ''',2))
DECLARE @objectName VARCHAR(128) = PARSENAME(''' + @Object + ''',1)
IF (SELECT COUNT(0) FROM sys.objects WHERE name = @objectName) > 0
SELECT @db [db_name],
''[''+@db+''].[''+OBJECT_SCHEMA_NAME(object_id)+''].[''+@objectName+'']''
FROM sys.objects WHERE name = @objectName
AND (@schemaId IS NULL OR schema_id = @schemaId )'

INSERT INTO @dbList
EXEC sp_MSforeachdb @SQL

SELECT * FROM @dbList ORDER BY 1


Paul.Andrew
Paul.Andrew
SSC-Enthusiastic
SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)

Group: General Forum Members
Points: 168 Visits: 152
Nice, didn't realise there was such a system procedure to do that! Many thanks
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