Alaska Cowboy
asked on
How do I check if an index exists before creating it in a script?
I'm trying to add an index via a script, but want to check if it exists first.
I use this for procedures:
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spCreat eScenarioN Hrooms]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
but it doesn't seem as if I can use " IsIndex".
The larger question is how to alter a table completely and save the data. What's the normal practice for adding via a script? I don't what the dba to slit my throat if the script blows up. But I also don't want to re-create the entire table (saving data, re-importing data, whatever) just to add one measley index.
So,
a. how to check if an index exists before creating it?
b. what's the normal practice for creating an index in a script?
Thanks !
Bill
I use this for procedures:
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spCreat
but it doesn't seem as if I can use " IsIndex".
The larger question is how to alter a table completely and save the data. What's the normal practice for adding via a script? I don't what the dba to slit my throat if the script blows up. But I also don't want to re-create the entire table (saving data, re-importing data, whatever) just to add one measley index.
So,
a. how to check if an index exists before creating it?
b. what's the normal practice for creating an index in a script?
Thanks !
Bill
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.