問題描述
在 SQL Server 2005 上,是否可以在事務內(nèi)刪除并重新創(chuàng)建表(從另一個數(shù)據(jù)庫復制)?
On SQL Server 2005, is it possible to drop and recreate a table (copy from another database) inside of a transaction?
此外,在事務期間嘗試訪問該表的任何進程是否會失敗或等待事務完成?
Also, would any process trying to access that table during the transaction fail or wait for the transaction to complete?
推薦答案
將數(shù)據(jù)復制到不同的表中,然后切換舊表和新表.使用 sp_rename 或查看 使用分區(qū)切換有效傳輸數(shù)據(jù).后一個選項更好,因為它保留了對表的所有權限和約束,但它確實需要企業(yè)版.
Copy the data into a different table, then switch the old and new tables. Use either sp_rename or see Transferring Data Efficiently by Using Partition Switching. The later option is better because it preserves all permissions and constraints on the table, but it does require Enterprise Edition.
這篇關于在 SQL Server 上的事務內(nèi)部刪除和創(chuàng)建表,對其他進程的影響的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!