Possible Duplicate:
List of all index & index columns in SQL Server DB
I would like to know if there is a way to verify if an index exists in a SQL Server database for a specific table based on the columns name:
Let's say I run the following script:
CREATE NONCLUSTERED INDEX [MyIndexName]
ON [dbo].[MyTable] ([CustomerId])
INCLUDE ([Id],[ModificationDate],[ProductId])
GO
Now I would like to check if the index exists based on the table name and columns (and the columns in the include clause), not the actual index name.
(SQL Server 2008 R2)
Thanks
Try this query:
if exists(
SELECT 1
FROM sys.indexes
WHERE name = 'INDEX'
AND object_id = OBJECT_ID('TABLENAME')
)
begin
....
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With