title: After insert trigger - SQL Server 2008
body: <p>I have data coming in from datastage that is being put in our SQL Server 2008 database in a table: <code>stg_table_outside_data</code>. The ourside source is putting the data into that table every morning.  I want to move the data from <code>stg_table_outside_data</code> to <code>table_outside_data</code> where I keep multiple days worth of data.  </p>
  
  <p>I created a stored procedure that inserts the data from <code>stg_table_outside_Data</code> into <code>table_outside_data</code> and then truncates <code>stg_table_outside_Data</code>. The outside datastage process is outside of my control, so I have to do this all within SQL Server 2008. I had originally planned on using a simple after insert statement, but datastage is doing a commit after every 100,000 rows. The trigger would run after the first commit and cause a deadlock error to come up for the datastage process.  </p>
  
  <p>Is there a way to set up an after insert to wait 30 minutes then make sure there wasn't a new commit within that time frame?  Is there a better solution to my problem?  The goal is to get the data out of the staging table and into the working table without duplications and then truncate the staging table for the next morning's load.  </p>
  
  <p>I appreciate your time and help.  </p>