0

I have a third party application from which queries will hit the SQL Server 2008 database to fetch the data ASAP (near to real time). The same query can be called by multiple users at different times.

Is there a way to store the latest result and serve the results for subsequent queries without actually hitting the database again and again for the same piece of data?

3 Answers 3

1

Get the results from a procedure that stores data in a global temporary table, or change to a permanent table if you regularly drop connections: change tempdb..##Results to Results. param = 1 refreshes the data:

Create procedure [getresults] (@refresh int = 0)
as
begin
IF @refresh = 1 and OBJECT_ID('tempdb..##Results') IS NOT NULL
    drop table ##Results
IF OBJECT_ID('tempdb..##Results') IS NULL
    select * into ##Results from [INSERT SQL HERE]

SELECT * FROM ##RESULTS
END
Sign up to request clarification or add additional context in comments.

2 Comments

Storing result is fine, How to handle data update scenrio?
Force a data update by putting this in an insert update trigger on all the tables queried: IF OBJECT_ID('tempdb..##Results') IS NOT NULL DROP TABLE ##RESULTS
0

Can you create an indexed view for the data?

When the data is updated the view will be updated when the 3rd party makes a call the view contents will be returned without needing to hit the base tables

Comments

0

Unfortunately the SQL server you are using doesn't have cache system like for example, MySQL query cache. But as per the documentation I just saw here: Buffer Management Data pages which are read during a SELECT are first brought into the buffer cache. Subsequent requests reading the same data can thus be served quicker than the initial request without needing to access the disc.

1 Comment

You can also look into 3rd party cache systems. There are many available with each having their own pros & cons. Or you can also try to index the tables to see if there is actual improvement in performance.

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.