I have the following:
CREATE NONCLUSTERED INDEX [MyTableIndex] ON [dbo].[tablename] ([tablename_ID],[tablename_Field1]) INCLUDE ([Tablename_Field2],[Tablename_Field3])
I want to create an if statement to check if this exists. How do I do this?
If a table has no clustered index, its data rows are stored in an unordered structure called a heap.
In SQL Server 2005 and earlier, a maximum of 249 non-clustered indexes could be created on a table but now in SQL Server 2008 that limit has been increased and now 999 non-clustered indexes can be created on a single table.
IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'MyTableIndex' AND object_id = OBJECT_ID('tablename')) BEGIN -- Index with this name, on this table does NOT exist 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