Showing posts with label quotdrop. Show all posts
Showing posts with label quotdrop. Show all posts

Friday, March 9, 2012

how to Drop an index if exists

Hi all,

I come from MySQL.

In sqlserverce

I'm looking for an equivalent command..to

"DROP INDEX IF EXISTS inventory.idxItems"

or somthing similar so that I do not get an error or crash the C# app when I try to drop a nonexisting index..

also for droping a table.

Use can use the INFORMATION.SCHEMA veiws, both for tables and indexes, like this:

SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = ’MyUserTable’

or

SELECT INDEX_NAME
FROM INFORMATION_SCHEMA.INDEXES
WHERE INDEX_NAME = ’MyUserIndex’

For more information (not a lot though), see http://msdn2.microsoft.com/en-us/library/ms174156.aspx