首页 > 代码库 > 修改列为Identity
修改列为Identity
/* 为了防止任何可能出现的数据丢失问题,您应该先仔细检查此脚本,然后再在数据库设计器的上下文之外运行此脚本。*/
BEGIN TRANSACTION
SET QUOTED_IDENTIFIER ON
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
GO
CREATE TABLE dbo.Tmp_trans
(
id int NOT NULL IDENTITY (1, 1),
trans_time datetime NULL,
sales decimal(10, 2) NULL
) ON [PRIMARY]
GO
ALTER TABLE dbo.Tmp_trans SET (LOCK_ESCALATION = TABLE)
GO
SET IDENTITY_INSERT dbo.Tmp_trans ON
GO
IF EXISTS(SELECT * FROM dbo.trans)
EXEC(‘INSERT INTO dbo.Tmp_trans (id, trans_time, sales)
SELECT id, trans_time, sales FROM dbo.trans WITH (HOLDLOCK TABLOCKX)‘)
GO
SET IDENTITY_INSERT dbo.Tmp_trans OFF
GO
DROP TABLE dbo.trans
GO
EXECUTE sp_rename N‘dbo.Tmp_trans‘, N‘trans‘, ‘OBJECT‘
GO
COMMIT
修改列为Identity