Hi, I have one temperary table (#results) having the 30000 records. If i give simple query "select * from #results" , taking time of 25 min to complete query sucessfully. is there any possibility to reduce the time. Please provide the advices.
Do you really need all of those rows from that temp table? Why not choose the columns you want to see the performance, in any case make sure the TEMPDB is not having issues in this case. Better to view SQL server error log for any warnings or errors.
Check your code to see if it is creating the temp table using this syntax: SELECT * INTO #MyTempTable FROM MyTable This syntax will try to lock the source table. Always use the following syntax instead: CREATE TABLE #MyTempTable (column definitions) INSERT INTO #MyTempTable (list of columns) SELECT list of columns FROM MyTable Another suggestion is to use a table variable instead of a temporary table. And in either case, add a primary key.
Possible reasons could be, If your table does not contain a primary key, it can take more time Check the size of the tempdb log. If the tempdb is not optimized your query would take more time. Restart your server, so that tempdb will be initialized and then re-run your query. If your query using a remote server, need to check the network bandwidth.