Thursday, February 17, 2011

How To Drop Already Created Index in a sdf file(SQL CE)

Today I had to delete an index already created in a table in a SQL CE database, i.e in a sdf file.
The problem of deleteing/droping an already created index in a table in sdf file is that (1) if you have opened it in SQL Server 2005 editor or (2) using Visual Studio editor, you can not just delete/drop the index though both editor provides you an option for deleteing / droping using content menu item.

The bottom line is, you just can not delete/drop an already created Index in a table in sdf file using either SQL Server 2005 editor or Visual Studio editor.

An already created Index in a table in sdf file can only be dropped/deleted using a query as explained following,
=========================================================

DROP INDEX "TABLE_NAME"."INDEX_NAME"

Where "TABLE_NAME" is the name of the table to which index belong to.
"INDEX_NAME" is the name of the already created index which we want to delete/drop.

=========================================================

Example : If you have a table named "CUSTOMER_POSM_REQUEST" and already existing Index name is "RECORD_ID_INDEX" then as mentioned above, the query would be like this:

DROP INDEX CUSTOMER_POSM_REQUEST.RECORD_ID_INDEX

=========================================================

Use the above query and run the query in either of the editor mentioned above. Index will be deleted. Not sure what is the reason behind that. Need to dig it further :)

No comments: