Click here to Skip to main content
15,891,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi friend i want to apply index to database table for example there are 10 columns in my database & want to apply index on one column through c# at run time so how can i do it.please help me thanks
Posted

1 solution

Do you mean create an index?

If so, you have you can use a Stored Procedure (or SQL statement) that creates an index on the table/columns you want. This reference[^] will give you a whole slew of options because you will need to customize the index to suit your needs.

But the question I have to ask is why do you need to do this? Indexes are not something that you should toy with "on the fly". They grow, massively in some cases, for a reason and that's to cut down on seek times afterwards.
 
Share this answer
 
Comments
maheshpardeshi 11-Sep-11 9:25am    
thanks for reply but in my project i want to change the index of database as user search data by using different attribute in high dimensional database.& i want coding in c# which reference you have give i saw it all ready but i want a coding in c# so when i will change the index from coding it will get change permanently to database
Mustafa Ismail Mustafa 11-Sep-11 9:34am    
This is what you are looking for then reference. But beware, this will be discontinued in the next edition of SQL server.

If this answers your question, don't forget to mark the question as answered. But I'm still pretty certain you should not be doing something like this at runtime.
maheshpardeshi 11-Sep-11 9:38am    
sorry friend your answer is correct but please send me a c# code reference
Mustafa Ismail Mustafa 11-Sep-11 9:42am    
That is C#. SQL-DMO (Database Management Object) are a high level .NET library to access high level functions. I'm almost 100% sure that there is no way to alter indexes from C# without doing it this way. This might help you (CP Article).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900