/*
   Friday, March 30, 20121:48:11 PM
   User: 
   Server: .
   Database: ATNDBTest
   Application: 
*/

/* To prevent any potential data loss issues, you should review this script in detail before running it outside the context of the database designer.*/
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
ALTER TABLE dbo.FactorAccCode
	DROP CONSTRAINT FK_FactorAccCode_FactorAccCodeKind
GO
ALTER TABLE dbo.FactorAccCodeKind SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.FactorAccCode
	DROP CONSTRAINT FK_FactorAccCode_FactorHeader
GO
ALTER TABLE dbo.FactorHeader SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
CREATE TABLE dbo.Tmp_FactorAccCode
	(
	Serial bigint NOT NULL,
	FactorHeaderRef bigint NULL,
	FactorDetailRef bigint NULL,
	FactorAccCodeKindRef smallint NULL,
	DebitAccGroupCodeBookRef bigint NULL,
	DebitAccGeneralCodeBookRef bigint NULL,
	DebitAccAdjutantL1CodeBookRef bigint NULL,
	DebitAccEntityL1CodeBookRef bigint NULL,
	DebitAccEntityL2CodeBookRef bigint NULL,
	CreditAccGroupCodeBookRef bigint NULL,
	CreditAccGeneralCodeBookRef bigint NULL,
	CreditAccAdjutantL1CodeBookRef bigint NULL,
	CreditAccEntityL1CodeBookRef bigint NULL,
	CreditAccEntityL2CodeBookRef bigint NULL
	)  ON [PRIMARY]
GO
ALTER TABLE dbo.Tmp_FactorAccCode SET (LOCK_ESCALATION = TABLE)
GO
IF EXISTS(SELECT * FROM dbo.FactorAccCode)
	 EXEC('INSERT INTO dbo.Tmp_FactorAccCode (Serial, FactorHeaderRef, FactorAccCodeKindRef, DebitAccGroupCodeBookRef, DebitAccGeneralCodeBookRef, DebitAccAdjutantL1CodeBookRef, DebitAccEntityL1CodeBookRef, DebitAccEntityL2CodeBookRef, CreditAccGroupCodeBookRef, CreditAccGeneralCodeBookRef, CreditAccAdjutantL1CodeBookRef, CreditAccEntityL1CodeBookRef, CreditAccEntityL2CodeBookRef)
		SELECT Serial, FactorHeaderRef, FactorAccCodeKindRef, DebitAccGroupCodeBookRef, DebitAccGeneralCodeBookRef, DebitAccAdjutantL1CodeBookRef, DebitAccEntityL1CodeBookRef, DebitAccEntityL2CodeBookRef, CreditAccGroupCodeBookRef, CreditAccGeneralCodeBookRef, CreditAccAdjutantL1CodeBookRef, CreditAccEntityL1CodeBookRef, CreditAccEntityL2CodeBookRef FROM dbo.FactorAccCode WITH (HOLDLOCK TABLOCKX)')
GO
DROP TABLE dbo.FactorAccCode
GO
EXECUTE sp_rename N'dbo.Tmp_FactorAccCode', N'FactorAccCode', 'OBJECT' 
GO
ALTER TABLE dbo.FactorAccCode ADD CONSTRAINT
	PK_FactorAccCode PRIMARY KEY CLUSTERED 
	(
	Serial
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

GO
ALTER TABLE dbo.FactorAccCode ADD CONSTRAINT
	FK_FactorAccCode_FactorHeader FOREIGN KEY
	(
	FactorHeaderRef
	) REFERENCES dbo.FactorHeader
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.FactorAccCode ADD CONSTRAINT
	FK_FactorAccCode_FactorAccCodeKind FOREIGN KEY
	(
	FactorAccCodeKindRef
	) REFERENCES dbo.FactorAccCodeKind
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
COMMIT
