2

The scenario is as follows. I need to drop a particular index at the beginning of the C# application. After all the insert sql statements which are part of processing are complete, I need to create the index again.

The reason I need index drop and creation as part of the application is because I will be giving this application to the deployment team. The deployment team will then be running the application in production.

Is inline sql the best way to create an index - clustered or non-clustered in SQL server from C#?

Or is it there any other way?

7
  • 1
    You write a SQL script - in any text editor of your choice - and you execute it ...... what is the question, really?!?!? Commented May 2, 2013 at 18:24
  • I wouyld like to trigger it via C#. I know how to trigger regular dynamic sql and stored procedure from C#. Was just wondering how to trigger creation of an index from C#. I am running this as part of a c# application which I will hand over to deployment team to run in production Commented May 2, 2013 at 18:54
  • 1
    It might help if you stop using the word "trigger", or at least explain what it means for you. If your basic question is how to create an index from C#, then you can just write a script as @marc_s said, or use SMO. Commented May 2, 2013 at 19:41
  • Trigger = "kick off" in this scenario. I know there is the sql trigger but i think it is pretty clear in this particular context what I mean by trigger. Commented May 2, 2013 at 21:00
  • If you are creating indexes from a C# application, something may have gone wrong. Commented May 2, 2013 at 21:04

2 Answers 2

3

you can use ExecuteNonQuery and simply send along a CREATE INDEX command.

Sign up to request clarification or add additional context in comments.

Comments

0

Your question is phrased a little strangely.

Are you asking how to create indexes or how to cause the statistics to be updated (for the optimizers to decide which index would give the answer to a query the quickest) ?

Creating indexes is with CREATE INDEX.

Causing the stats to be recalculated is UPDATE STATISTICS.

Both can be done via C# or any other method.

An index is updated whenever anything is created/updated/deleted.

2 Comments

I know how to trigger regular dynamic sql and stored procedure from C#. Was just wondering how to trigger creation of an index from C#.I am running this as part of a c# application which I will hand over to deployment team to run in production
Please see the comments under my question for some more clarifications.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.