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
GO
CREATE TABLE dbo.Tmp_AccEntityKind
	(
	Serial smallint NOT NULL,
	Code smallint NULL,
	Description varchar(50) NULL,
	RecorderRef int NULL,
	RecordDate char(10) NULL,
	OfficeDetailRef int NULL
	)  ON [PRIMARY]
GO
ALTER TABLE dbo.Tmp_AccEntityKind SET (LOCK_ESCALATION = TABLE)
GO
IF EXISTS(SELECT * FROM dbo.AccEntityKind)
	 EXEC('INSERT INTO dbo.Tmp_AccEntityKind (Serial, Description)
		SELECT Serial, Description FROM dbo.AccEntityKind WITH (HOLDLOCK TABLOCKX)')
GO
ALTER TABLE dbo.AccEntityL1CodeBook
	DROP CONSTRAINT FK_AccEntityL1CodeBook_AccEntityKind
GO
ALTER TABLE dbo.AccAdjutantL1Bridge
	DROP CONSTRAINT FK_AccAdjutantL1Bridge_AccEntityKind
GO
ALTER TABLE dbo.AccDefaultEntityL1CodeBook
	DROP CONSTRAINT FK_AccDefaultEntityL1CodeBook_AccEntityKind
GO
DROP TABLE dbo.AccEntityKind
GO
EXECUTE sp_rename N'dbo.Tmp_AccEntityKind', N'AccEntityKind', 'OBJECT' 
GO
ALTER TABLE dbo.AccEntityKind ADD CONSTRAINT
	PK_AccEntityKind PRIMARY KEY CLUSTERED 
	(
	Serial
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.AccDefaultEntityL1CodeBook ADD CONSTRAINT
	FK_AccDefaultEntityL1CodeBook_AccEntityKind FOREIGN KEY
	(
	AccEntityKindRef
	) REFERENCES dbo.AccEntityKind
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.AccDefaultEntityL1CodeBook SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.AccAdjutantL1Bridge ADD CONSTRAINT
	FK_AccAdjutantL1Bridge_AccEntityKind FOREIGN KEY
	(
	AccEntityKindRef
	) REFERENCES dbo.AccEntityKind
	(
	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.AccEntityL1CodeBook ADD CONSTRAINT
	FK_AccEntityL1CodeBook_AccEntityKind FOREIGN KEY
	(
	AccEntityKindRef
	) REFERENCES dbo.AccEntityKind
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.AccEntityL1CodeBook SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
