How do I check if an index exists before creating it in a script?
Posted on 2005-04-02
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].[spCreateScenarioNHrooms]') 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.
a. how to check if an index exists before creating it?
b. what's the normal practice for creating an index in a script?