BEGIN TRANSACTION
SET QUOTED_IDENTIFIER ON
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
SET ARITHABORT ON
SET NUMERIC_ROUNDABORT OFF
SET CONCAT_NULL_YIELDS_NULL ON
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
COMMIT
BEGIN TRANSACTION
--这一句为关键
--假设表名为Tempa,字段名为a
CREATE TABLE dbo.Tmp_tempa
(
a int NOT NULL IDENTITY (1, 1)
) ON [PRIMARY]
GO
SET IDENTITY_INSERT dbo.Tmp_tempa ON
GO
IF EXISTS(SELECT * FROM dbo.tempa)
EXEC('INSERT INTO dbo.Tmp_tempa (a)
SELECT a FROM dbo.tempa TABLOCKX')
GO
SET IDENTITY_INSERT dbo.Tmp_tempa OFF
GO
DROP TABLE dbo.tempa
GO
EXECUTE sp_rename N'dbo.Tmp_tempa', N'tempa', 'OBJECT'
GO
COMMIT