Use ATNDBTest
Go

/* 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.AccAdjutantL1CodeBook
	DROP CONSTRAINT FK_AccAdjutantL1CodeBook_AccGeneralCodeBook
GO
ALTER TABLE dbo.AccGeneralCodeBook SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.AccAdjutantL1CodeBook
	DROP CONSTRAINT FK_AccAdjutantL1CodeBook_Users
GO
ALTER TABLE dbo.Users SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
CREATE TABLE dbo.Tmp_AccAdjutantL1CodeBook
	(
	Serial bigint NOT NULL,
	AccGeneralCodeBookRef bigint NULL,
	Code bigint NULL,
	FADetail varchar(100) NULL,
	ENDetail varchar(100) NULL,
	Active bit NULL,
	RecorderRef int NULL,
	RecordDate char(10) NULL,
	EditorRef int NULL,
	EditDate char(10) NULL,
	OfficeDetailRef int NULL
	)  ON [PRIMARY]
GO
ALTER TABLE dbo.Tmp_AccAdjutantL1CodeBook SET (LOCK_ESCALATION = TABLE)
GO
IF EXISTS(SELECT * FROM dbo.AccAdjutantL1CodeBook)
	 EXEC('INSERT INTO dbo.Tmp_AccAdjutantL1CodeBook (Serial, AccGeneralCodeBookRef, Code, FADetail, Active, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef)
		SELECT Serial, AccGeneralCodeBookRef, Code, Detail, Active, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef FROM dbo.AccAdjutantL1CodeBook WITH (HOLDLOCK TABLOCKX)')
GO
ALTER TABLE dbo.SystemAccCodeDefaultPerOffice
	DROP CONSTRAINT FK_SystemAccCodeDefaultPerOffice_CreditAccAdjutantL1CodeBook
GO
ALTER TABLE dbo.SystemAccCodeDefaultPerOffice
	DROP CONSTRAINT FK_SystemAccCodeDefaultPerOffice_DebitAccAdjutantL1CodeBook
GO
ALTER TABLE dbo.SystemAccCodeDefaultPerPart
	DROP CONSTRAINT FK_SystemAccCodeDefaultPerPart_CreditAccAdjutantL1CodeBook
GO
ALTER TABLE dbo.SystemAccCodeDefaultPerPart
	DROP CONSTRAINT FK_SystemAccCodeDefaultPerPart_DebitAccAdjutantL1CodeBook
GO
ALTER TABLE dbo.CashGetPay
	DROP CONSTRAINT FK_CashGetPay_CreditAccAdjutantL1CodeBook
GO
ALTER TABLE dbo.CashGetPay
	DROP CONSTRAINT FK_CashGetPay_DebitAccAdjutantL1CodeBook
GO
ALTER TABLE dbo.AccAdjutantL1Bridge
	DROP CONSTRAINT FK_AccAdjutantL1Bridge_AccAdjutantL1CodeBook
GO
ALTER TABLE dbo.AccDocumentDetail
	DROP CONSTRAINT FK_AccDocumentDetail_AccAdjutantL1CodeBook
GO
ALTER TABLE dbo.FactorAccCode
	DROP CONSTRAINT FK_FactorAccCode_AccAdjutantL1CodeBook_Credit
GO
ALTER TABLE dbo.FactorAccCode
	DROP CONSTRAINT FK_FactorAccCode_AccAdjutantL1CodeBook_Debit
GO
DROP TABLE dbo.AccAdjutantL1CodeBook
GO
EXECUTE sp_rename N'dbo.Tmp_AccAdjutantL1CodeBook', N'AccAdjutantL1CodeBook', 'OBJECT' 
GO
ALTER TABLE dbo.AccAdjutantL1CodeBook ADD CONSTRAINT
	PK_AccAdjutantL1CodeBook 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.AccAdjutantL1CodeBook ADD CONSTRAINT
	FK_AccAdjutantL1CodeBook_Users FOREIGN KEY
	(
	RecorderRef
	) REFERENCES dbo.Users
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.AccAdjutantL1CodeBook ADD CONSTRAINT
	FK_AccAdjutantL1CodeBook_AccGeneralCodeBook FOREIGN KEY
	(
	AccGeneralCodeBookRef
	) REFERENCES dbo.AccGeneralCodeBook
	(
	serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.FactorAccCode ADD CONSTRAINT
	FK_FactorAccCode_AccAdjutantL1CodeBook_Credit FOREIGN KEY
	(
	CreditAccAdjutantL1CodeBookRef
	) REFERENCES dbo.AccAdjutantL1CodeBook
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.FactorAccCode ADD CONSTRAINT
	FK_FactorAccCode_AccAdjutantL1CodeBook_Debit FOREIGN KEY
	(
	DebitAccAdjutantL1CodeBookRef
	) REFERENCES dbo.AccAdjutantL1CodeBook
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.FactorAccCode SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.AccDocumentDetail ADD CONSTRAINT
	FK_AccDocumentDetail_AccAdjutantL1CodeBook FOREIGN KEY
	(
	AccAdjutantL1CodeBookRef
	) REFERENCES dbo.AccAdjutantL1CodeBook
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.AccDocumentDetail SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.AccAdjutantL1Bridge ADD CONSTRAINT
	FK_AccAdjutantL1Bridge_AccAdjutantL1CodeBook FOREIGN KEY
	(
	AccAdjutantL1CodeBookRef
	) REFERENCES dbo.AccAdjutantL1CodeBook
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.AccAdjutantL1Bridge SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.CashGetPay ADD CONSTRAINT
	FK_CashGetPay_CreditAccAdjutantL1CodeBook FOREIGN KEY
	(
	CreditAccAdjutantL1CodeBookRef
	) REFERENCES dbo.AccAdjutantL1CodeBook
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.CashGetPay ADD CONSTRAINT
	FK_CashGetPay_DebitAccAdjutantL1CodeBook FOREIGN KEY
	(
	DebitAccAdjutantL1CodeBookRef
	) REFERENCES dbo.AccAdjutantL1CodeBook
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.CashGetPay SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.SystemAccCodeDefaultPerPart ADD CONSTRAINT
	FK_SystemAccCodeDefaultPerPart_CreditAccAdjutantL1CodeBook FOREIGN KEY
	(
	CreditAccAdjutantL1CodeBookRef
	) REFERENCES dbo.AccAdjutantL1CodeBook
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.SystemAccCodeDefaultPerPart ADD CONSTRAINT
	FK_SystemAccCodeDefaultPerPart_DebitAccAdjutantL1CodeBook FOREIGN KEY
	(
	DebitAccAdjutantL1CodeBookRef
	) REFERENCES dbo.AccAdjutantL1CodeBook
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.SystemAccCodeDefaultPerPart SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.SystemAccCodeDefaultPerOffice ADD CONSTRAINT
	FK_SystemAccCodeDefaultPerOffice_CreditAccAdjutantL1CodeBook FOREIGN KEY
	(
	CreditAccAdjutantL1CodeBookRef
	) REFERENCES dbo.AccAdjutantL1CodeBook
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.SystemAccCodeDefaultPerOffice ADD CONSTRAINT
	FK_SystemAccCodeDefaultPerOffice_DebitAccAdjutantL1CodeBook FOREIGN KEY
	(
	DebitAccAdjutantL1CodeBookRef
	) REFERENCES dbo.AccAdjutantL1CodeBook
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.SystemAccCodeDefaultPerOffice SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
