I’m using sql server 2005/2008 and I have a table that it’s PK (rec_index) is also indexed.
CREATE TABLE [dbo].[MyTable]
(
[rec_index] INT IDENTITY(1,1) PRIMARY KEY CLUSTERED,
file_desc nvarchar(50),
is_modified bit
)
However unfortunately I already have a table like this in my DB which O created without the index.
How can I ask if the table already is indexed do nothing, else add an index? I can’t drop it and than re-create it since i will loose data.
I’m looking for something like "if not exists <index for rec_index> do <create index for rec_index>"
maybe something like: