设表的名字为aaa
字段名为a
BEGIN TRANSACTION
SET QUOTED_IDENTIFIER ON
GO
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
GO
COMMIT
BEGIN TRANSACTION
CREATE TABLE dbo.Tmp_aaa
(
a datetime NULL,
e int NOT NULL IDENTITY (1, 1)
) ON [PRIMARY]
GO
SET IDENTITY_INSERT dbo.Tmp_aaa ON
GO
IF EXISTS(SELECT * FROM dbo.aaa)
EXEC('INSERT INTO dbo.Tmp_aaa(a, e)
SELECT a, e FROM dbo.aaa TABLOCKX')
GO
SET IDENTITY_INSERT dbo.Tmp_aaa OFF
GO
DROP TABLE dbo.aaa
GO
EXECUTE sp_rename 'dbo.Tmp_aaa', 'aaa'
GO
COMMIT
这是企业管理器生成的脚本
建议你在企业管理器中把它修改为 IDENTITY (1, 1)
看它生成的脚本
然后copy出来就可以了