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


Quickest Way to Find an Index


Quickest Way to Find an Index

Author
Message
JC-3113
JC-3113
SSC-Addicted
SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)

Group: General Forum Members
Points: 450 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
Lynn Pettis
Lynn Pettis
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24207 Visits: 37978
The system view sys.indexes in each database.

Cool
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)
JC-3113
JC-3113
SSC-Addicted
SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)

Group: General Forum Members
Points: 450 Visits: 620
Hi Lynn

you mean i have to look in each database seperately ?

no view that encompases al the databases ?

Jim
Lynn Pettis
Lynn Pettis
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24207 Visits: 37978
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.

Cool
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)
roryp 96873
roryp 96873
SSC Eights!
SSC Eights! (843 reputation)SSC Eights! (843 reputation)SSC Eights! (843 reputation)SSC Eights! (843 reputation)SSC Eights! (843 reputation)SSC Eights! (843 reputation)SSC Eights! (843 reputation)SSC Eights! (843 reputation)

Group: General Forum Members
Points: 843 Visits: 6598
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.
JC-3113
JC-3113
SSC-Addicted
SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)

Group: General Forum Members
Points: 450 Visits: 620
Thanks very much roryp 96873

i will give it a shot

Jim
Kingston Dhasian
Kingston Dhasian
Hall of Fame
Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)

Group: General Forum Members
Points: 3003 Visits: 5007
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/
JC-3113
JC-3113
SSC-Addicted
SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)

Group: General Forum Members
Points: 450 Visits: 620
Thanks Kingston

I will take a look see

Jim
JC-3113
JC-3113
SSC-Addicted
SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)

Group: General Forum Members
Points: 450 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 '-'.
JC-3113
JC-3113
SSC-Addicted
SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)SSC-Addicted (450 reputation)

Group: General Forum Members
Points: 450 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
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