Have a bit of glitches from the time I was using SQL Server back in 2006 and the many other databases I played with (and which I have not touched since then).
I need to create a materialized view to quickly get access to the data without overloading the DB but also to pull them what it was made static by the time the view was created.
SQL Server seems to support the materialized views with the Indexed views, but to be created these require among the other thing the following:
- the WITH SCHEMABINDING construct
- a clustered INDEX
Failing in that, my understanding is the view is not auto refreshing, which is probably what I need?
My goal is to get a view, that I can refresh whenever I need.
So far I created a Materialized view in the SQL 2005 instance I have access to with the following statement:
CREATE MATERIALIZED VIEW xys AS
SELECT 123
FROM X
WHERE ...
GROUP BY
Any memory refresher?
Best Answer
Thinking about the requirements:
Especially the part about the data being static captured at a moment in time, I doubt a view is what you want. I think you may want something more like CDC, but that wasn't introduced until SQL Server 2008. For SQL Server 2005, a database snapshot may meet your needs.
Dominique's answer also potentially an option. There are multiple ways to fulfil above two requirements. Another example might be to create a stored procedure as shown below and schedule via SQL Server Agent. E.g. assuming source table:
and a "Snapshot table" created to match:
then you could do something like this: