How can I test if a table already has a specific index present?
Id normally test for an object with: if object_ID('My Object') is null then...
What technique works with an index? Or can you use the object_Id function, how do you reference the index?
Many thanks.You can check if a table has an index at all, not a specific index, unless you want to test for an existance of the name:
if exists (select 1 from dbo.sysindexes where object_name(id)='your_table' and indid between 2 and 254) print 'There is at least 1 non-clustered index'
else print 'No non-clustered indexes found'|||IF INDEXPROPERTY ( OBJECT_ID('your_table') , 'your_table_index' , 'IndexID' ) IS NULL
If you know the name the above should work; I have not tested it.
Tim S|||sp_helpindex tableName
OR
IF EXISTS (SELECT indid
FROM sysindexes
WHERE id = OBJECT_ID('tableName')
AND name = 'indexName') THEN
....sql
Showing posts with label index. Show all posts
Showing posts with label index. Show all posts
Friday, March 23, 2012
How to test existance for an index
How do I test for the existance of an index with in a specific table?
Thanks,
Bryanselect *
from dbo.sysindexes
where id = object_id(N'dbo.MyTable', 'U') and name = N'MyIndex'
"BDB" wrote:
> How do I test for the existance of an index with in a specific table?
> Thanks,
> Bryan
>
>|||The following stored proc will give list of indexes for given table.
EXECUTE sp_MShelpindex <table_name> , NULL, 1|||Thank you.
"KH" <KH@.discussions.microsoft.com> wrote in message
news:286BE372-C9BB-4CD0-8B52-6A3BBADEC429@.microsoft.com...
> select *
> from dbo.sysindexes
> where id = object_id(N'dbo.MyTable', 'U') and name = N'MyIndex'
>
> "BDB" wrote:
>
Thanks,
Bryanselect *
from dbo.sysindexes
where id = object_id(N'dbo.MyTable', 'U') and name = N'MyIndex'
"BDB" wrote:
> How do I test for the existance of an index with in a specific table?
> Thanks,
> Bryan
>
>|||The following stored proc will give list of indexes for given table.
EXECUTE sp_MShelpindex <table_name> , NULL, 1|||Thank you.
"KH" <KH@.discussions.microsoft.com> wrote in message
news:286BE372-C9BB-4CD0-8B52-6A3BBADEC429@.microsoft.com...
> select *
> from dbo.sysindexes
> where id = object_id(N'dbo.MyTable', 'U') and name = N'MyIndex'
>
> "BDB" wrote:
>
Sunday, February 19, 2012
how to stop incremental population
i have a catalog and add directory which has 10,000 documents and all are index but if i add 1000 documents to that directory and i don't want those 1000 documents to be indexed. i want only previous 10,000 index document and don't want to new document to be indexed. is there any way can stop the new document to be indexed, please let me it's bit urgent.
Thanking you in anticipationHuh? What do you mean you don't want some of the records indexed? Are you talking about database table indexes?|||quite interesting!!... why do u need such a thing? ... may be creating a view is the answer NOT blocking index...
Thanking you in anticipationHuh? What do you mean you don't want some of the records indexed? Are you talking about database table indexes?|||quite interesting!!... why do u need such a thing? ... may be creating a view is the answer NOT blocking index...
Subscribe to:
Posts (Atom)