
Use ATNDBTest
Go



/*
   چهارشنبه, 28 اسفند 139801:17:45 ب.ظ
   User: 
   Server: TAHERIAN
   Database: ATNDB
   Application: 
*/

-- انتقال کدینگ حساب معین کسور به سمت بدهکار تا بعدا سمت بستانکار را حذف کنیم
Update 
	PAY.Factor
Set
	DebitAccAdjutantL1CodeBookRef = CreditAccAdjutantL1CodeBookRef
Where
	FactorGroupRef = 20


-- حذف ستونهای حساب بدهکار و بستانکار و فقط ستون معین بدهکار را تغییر نام داده و نگهداری می کنیم
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

If Exists(SELECT * FROM sys.objects WHERE name ='FK_PAY_Factor_CreditAccAdjutantL1CodeBook')
Begin
	ALTER TABLE PAY.Factor DROP CONSTRAINT FK_PAY_Factor_CreditAccAdjutantL1CodeBook
End
GO
ALTER TABLE dbo.AccAdjutantL1CodeBook SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO

If Exists(SELECT * FROM sys.objects WHERE name ='FK_PAY_Factor_DebitAccEntityL2CodeBook')
Begin
	ALTER TABLE PAY.Factor DROP CONSTRAINT FK_PAY_Factor_DebitAccEntityL2CodeBook
End
GO

If Exists(SELECT * FROM sys.objects WHERE name ='FK_PAY_Factor_CreditAccEntityL2CodeBook')
Begin
	ALTER TABLE PAY.Factor DROP CONSTRAINT FK_PAY_Factor_CreditAccEntityL2CodeBook
End
GO
ALTER TABLE dbo.AccEntityL2CodeBook SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO

If Exists(SELECT * FROM sys.objects WHERE name ='FK_PAY_Factor_DebitAccEntityL1CodeBook')
Begin
	ALTER TABLE PAY.Factor DROP CONSTRAINT FK_PAY_Factor_DebitAccEntityL1CodeBook
End
GO

If Exists(SELECT * FROM sys.objects WHERE name ='FK_PAY_Factor_CreditAccEntityL1CodeBook')
Begin
	ALTER TABLE PAY.Factor DROP CONSTRAINT FK_PAY_Factor_CreditAccEntityL1CodeBook
End
GO
ALTER TABLE dbo.AccEntityL1CodeBook SET (LOCK_ESCALATION = TABLE)
GO
COMMIT







BEGIN TRANSACTION
GO
EXECUTE sp_rename N'PAY.Factor.DebitAccAdjutantL1CodeBookRef', N'Tmp_AccAdjutantL1CodeBookRef_1', 'COLUMN' 
GO
EXECUTE sp_rename N'PAY.Factor.Tmp_AccAdjutantL1CodeBookRef_1', N'AccAdjutantL1CodeBookRef', 'COLUMN' 
GO

ALTER TABLE PAY.Factor
	DROP COLUMN DebitAccEntityL1CodeBookRef, DebitAccEntityL2CodeBookRef, CreditAccAdjutantL1CodeBookRef, CreditAccEntityL1CodeBookRef, CreditAccEntityL2CodeBookRef
GO
ALTER TABLE PAY.Factor SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
