I am working on a program that could get the whereabouts of an item from the database. Problem is it is querying from a SQL table of 9 million records. Appreciate if some one could advise me the fastest/effective way to get the records.
I tried to use sql stored procedure to insert into the temp table and then grab all the records from the temp table. But it took about 4 mins, which is not really acceptable.
I am using asp.net 2.0 connecting to sql server 2000.
http://devpinoy.org/blogs/cruizer
cruizer:but you're only retrieving one row...?
It varies. Depending on the user's selection.
bronkman:Your query should be optimised to make full use of the indexes. Explain execution plans should be useful. I never encourage the use of temp tables if they can be avoided. Take a look at this link: http://www.sql-server-performance.com/articles/per/derived_temp_tables_p1.aspx. Of course, there are exceptions to it, especially when it comes to huge databases. So, check this link http://www.quest-pipelines.com/newsletter-v3/0602_D.htm out and see if the tips are useful.
The melody of logic will always play out the truth. ~ Narumi Ayumu, Spiral
Triggers is also something that I would advise to avoid. Try using transactions instead. Sometimes it is better to update a total field of the master table each time a detail record is inserted or updated. That said, it is better to test the performance since you have a large database.
Also, although indexes help, do ensure that your indexes are well maintained. Indexes on foreign keys can also be created, or tables can be de-normalised if necessary, for performance.