two relating question: I have a table that is in use in a production or live environment. Is it appropriate and possible to begin a transaction on that table to ensure no one is using that table while it is dropped and re-generated and then committed or rolled back so that the users on live side will not notice? It may be better to delete rows and then repopulate rows. 2nd part of the question is how would I go about performing this drop or deletion of row in a transact statement, or should this be done on a tempory database table?
Thanks.
1)to lock all table when updating you can use Table Hints (see http://msdn.microsoft.com/en-us/library/ms187373%28v=SQL.100%29.aspx), for example
2)to delete all rows in table you need to use TRUNCATE TABLE. AS BOL says, TRUNCATE TABLE always locks the table and page but not each row.
So, if somebody locks one of the record in this table, you cannot lock this table and TRUNCATE cannot begin.