I have a rather simple command which I occasionally run:
BEGIN TRAN T1;
truncate table mytable
insert into mytable select name from myview
COMMIT TRAN T1;
This command has two ugly side effects: Firstly, select requests on mytable often time out. Secondly, select requests on mytable sometimes return no results. I don't care if it returns the pre-transaction results or the post-transaction results, but don't want it to return anything in the middle, or to time out. One solution I thought of, and which will almost definitely help, is to first copy the view into a temp table (as the view is a little expensive). This won't fully solve the problem, but it will almost definitely make the window narrow enough for the problem to be ignored. Frankly, the window is narrow enough to ignore it now, but I don't like ignoring it. Another solution, which is an example of crazy over-engineering, would be to replace the table with two tables (e.g. a double-buffer), and call the newest, properly populated table.
Is there a more elegant way to replace a table with a new one?