残念ながら、再作成せずにそれを行う方法はありません。すべてのデータを使用して新しいテーブルを作成しANSI_NULLS ON
、そこにコピーする必要があります。
次のようになります。
SET ANSI_NULLS ON;
CREATE TABLE new_MyTBL (
....
)
-- stop all processes changing your data at this point
SET IDENTITY_INSERT new_MyTBL ON
INSERT new_MyTBL (...) -- including IDENTITY field
SELECT ... -- including IDENTITY field
FROM MyTBL
SET IDENTITY_INSERT new_MyTBL OFF
-- alter/drop WITH SCHEMABINDING objects at this point
EXEC sp_rename @objname = 'MyTBL', @newname = 'old_MyTBL'
EXEC sp_rename @objname = 'new_MyTBL', @newname = 'MyTBL'
-- alter/create WITH SCHEMABINDING objects at this point
-- re-enable your processes
DROP TABLE old_MyTBL -- do that when you are sure that system works OK
依存するオブジェクトがある場合は、名前を変更するとすぐに新しいテーブルで機能します。しかし、それらのいくつかは手動で行うWITH SCHEMABINDING
必要がDROP
ありCREATE
ます。