Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Quickest Way to Find an Index Expand / Collapse
Author
Message
Posted Monday, September 17, 2012 10:42 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Wednesday, May 22, 2013 8:43 AM
Points: 442, Visits: 620
Hi Folks

can comeone tell me the quickest way to find an index in some 100 plus databases ?
is there a view or system table that houses that info that I can search through ?

All I have is the index name

Thanks
Jim
Post #1360329
Posted Monday, September 17, 2012 11:07 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 6:35 PM
Points: 23,064, Visits: 31,593
The system view sys.indexes in each database.



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1360353
Posted Monday, September 17, 2012 11:11 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Wednesday, May 22, 2013 8:43 AM
Points: 442, Visits: 620
Hi Lynn

you mean i have to look in each database seperately ?

no view that encompases al the databases ?

Jim
Post #1360357
Posted Monday, September 17, 2012 11:21 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 6:35 PM
Points: 23,064, Visits: 31,593
JC-3113 (9/17/2012)
Hi Lynn

you mean i have to look in each database seperately ?

no view that encompases al the databases ?

Jim


Basically, yes. There are ways around it but I don't have time to enumerate them at the moment.




Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1360364
Posted Monday, September 17, 2012 11:31 AM
Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Yesterday @ 11:25 AM
Points: 690, Visits: 5,922
You can generate the SQL to look for the index you have in each of your databases by using something like this:

select 'select *
from ' + name + '.sys.indexes i
where i.name = ''typeYourIndexNameHere'''
from master.sys.databases
where name not in ('master', 'tempdb', 'model', 'msdb')

Might save you a little bit of time.
Post #1360373
Posted Monday, September 17, 2012 12:03 PM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Wednesday, May 22, 2013 8:43 AM
Points: 442, Visits: 620
Thanks very much roryp 96873

i will give it a shot

Jim
Post #1360383
Posted Tuesday, September 18, 2012 5:36 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Wednesday, July 16, 2014 8:33 AM
Points: 2,616, Visits: 4,720
You can use the un-documented SP "sp_MSforeachdb" for this

IF OBJECT_ID('tempdb..#tmp_Indexes') IS NOT NULL
DROP TABLE #tmp_Indexes

DECLARE @strSQL VARCHAR(2000)
DECLARE @IndexName VARCHAR(1000)

CREATE TABLE #tmp_Indexes
(
DatabaseName VARCHAR(100),
IndexName VARCHAR(1000)
)

SET @IndexName = 'mst_Employees_IX01' -- You can enter the name of the index here

SET @strSQL = ' SELECT ''?'', name FROM ?..sysindexes WHERE name LIKE ''%' + @IndexName + '%'' '

INSERT #tmp_Indexes( DatabaseName, IndexName )
EXECUTE sp_MSforeachdb @strSQL

SELECT * FROM #tmp_Indexes

IF OBJECT_ID('tempdb..#tmp_Indexes') IS NOT NULL
DROP TABLE #tmp_Indexes

Edit: Added a comment in the code



Kingston Dhasian

How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Post #1360701
Posted Tuesday, September 18, 2012 9:28 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Wednesday, May 22, 2013 8:43 AM
Points: 442, Visits: 620
Thanks Kingston

I will take a look see

Jim
Post #1360857
Posted Tuesday, September 18, 2012 11:03 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Wednesday, May 22, 2013 8:43 AM
Points: 442, Visits: 620
Hi Kingston
'
even though thi seeems to run, it is geberating an error

Thanks
Jim

1> IF OBJECT_ID('tempdb..#tmp_Indexes') IS NOT NULL
2> DROP TABLE #tmp_Indexes
3>
4> DECLARE @strSQL VARCHAR(2000)
5> DECLARE @IndexName VARCHAR(1000)
6>
7> CREATE TABLE #tmp_Indexes
8> (
9> DatabaseName VARCHAR(100),
10> IndexName VARCHAR(1000)
11> )
12>
13> SET @IndexName = 'AllDocs_PK' -- You can enter the name of the index here
14>
15> SET @strSQL = ' SELECT ''?'', name FROM ?..sysindexes WHERE name LIKE ''%' + @IndexName + '%'' '
16>
17> INSERT #tmp_Indexes( DatabaseName, IndexName )
18> EXECUTE sp_MSforeachdb @strSQL
19>
20> SELECT * FROM #tmp_Indexes
21>
22> IF OBJECT_ID('tempdb..#tmp_Indexes') IS NOT NULL
23> DROP TABLE #tmp_Indexes
24> go
Msg 102, Level 15, State 1, Server NSAB-SS80-SQL-N, Line 1
Incorrect syntax near '-'.
Msg 102, Level 15, State 1, Server NSAB-SS80-SQL-N, Line 1
Incorrect syntax near '-'.
Msg 102, Level 15, State 1, Server NSAB-SS80-SQL-N, Line 1
Incorrect syntax near '-'.
Msg 102, Level 15, State 1, Server NSAB-SS80-SQL-N, Line 1
Incorrect syntax near '-'.
Msg 102, Level 15, State 1, Server NSAB-SS80-SQL-N, Line 1
Incorrect syntax near '-'.
Msg 102, Level 15, State 1, Server NSAB-SS80-SQL-N, Line 1
Incorrect syntax near '-'.
Msg 102, Level 15, State 1, Server NSAB-SS80-SQL-N, Line 1
Incorrect syntax near '-'.
Msg 102, Level 15, State 1, Server NSAB-SS80-SQL-N, Line 1
Incorrect syntax near '-'.
Msg 102, Level 15, State 1, Server NSAB-SS80-SQL-N, Line 1
Incorrect syntax near '-'.
Msg 102, Level 15, State 1, Server NSAB-SS80-SQL-N, Line 1
Incorrect syntax near '-'.
Msg 102, Level 15, State 1, Server NSAB-SS80-SQL-N, Line 1
Incorrect syntax near '-'.
Msg 102, Level 15, State 1, Server NSAB-SS80-SQL-N, Line 1
Incorrect syntax near '-'.
Msg 102, Level 15, State 1, Server NSAB-SS80-SQL-N, Line 1
Incorrect syntax near '-'.
Msg 102, Level 15, State 1, Server NSAB-SS80-SQL-N, Line 1
Incorrect syntax near '-'.
Post #1360903
Posted Tuesday, September 18, 2012 11:07 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Wednesday, May 22, 2013 8:43 AM
Points: 442, Visits: 620
Hi roryp 96873

I had to modify the code as it does not like '-' in the database name so i bracketed them. I also concatenated the database name to the index so you know where the index resides as it is in more than one database in my case.

Jim

code generates sql to find an index in every database

select
'select ' + '''[' + name + '].''' + '+ name from [' + name + '].sys.indexes i where i.name = ''AllDocs_PK'''
from
master.sys.databases
where
name not in
(
'master',
'tempdb',
'model',
'msdb'
);
go
Post #1360905
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse