I've created a stored procedure to add data to a table. In mock fashion the steps are:
- truncate original table
- Select data into the original table
The query that selects data into the original table is quite long (it can take almost a minute to complete), which means that the table is then empty of data for over a minute.
To fix this empty table I changed the stored procedure to:
- select data into #temp table
- truncate Original table
- insert * from #temp into Original
While the stored procedure was running, I did a select *
on the original table and it was empty (refreshing, it stayed empty until the stored procedure completed).
Does the truncate happen at the beginning of the procedure no matter where it actually is in the code? If so is there something else I can do to control when the data is deleted?
See Question&Answers more detail:os