/*
   شنبه, 27 بهمن 1403 - 17:18:22 ب.ظ
   User: 
   Server: TAHERIAN
   Database: ATNDB
   Application: 
*/

Use ATNDBTest
Go
/*=============================================================================================================*/
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
ALTER TABLE dbo.CheckGetPayDetail ADD CheckBookDetailRef Bigint NULL
GO
ALTER TABLE dbo.CheckGetPayDetail SET (LOCK_ESCALATION = TABLE)
GO



-- انتقال اطلاعات ستون قدیم به ستون جدید
Update 
	CheckGetPayDetail
Set
	CheckBookDetailRef = CheckBookDetail.Serial
From
	CheckGetPayDetail Inner Join 
	CheckBookDetail On CheckBookDetail.CheckGetPayDetailRef = CheckGetPayDetail.Serial
GO



-- حذف ستون قدیمی
ALTER TABLE dbo.CheckBookDetail DROP CONSTRAINT FK_CheckBookDetail_CheckGetPayDetail
GO
ALTER TABLE dbo.CheckGetPayDetail SET (LOCK_ESCALATION = TABLE)
GO
DROP INDEX IDX_CheckBookDetail_CheckGetPayDetailRef ON dbo.CheckBookDetail
GO
ALTER TABLE dbo.CheckBookDetail DROP COLUMN CheckGetPayDetailRef
GO
ALTER TABLE dbo.CheckBookDetail SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
