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
CREATE TABLE dbo.Tmp_Users
	(
	Serial int NOT NULL,
	Code int NOT NULL,
	Name varchar(50) NULL,
	Password varchar(MAX) NULL,
	Active bit NULL,
	Permition varchar(MAX) NULL,
	RecorderRef int NULL,
	RecordDate char(10) NULL,
	OfficeDetailRef int NULL
	)  ON [PRIMARY]
	 TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE dbo.Tmp_Users SET (LOCK_ESCALATION = TABLE)
GO
IF EXISTS(SELECT * FROM dbo.Users)
	 EXEC('INSERT INTO dbo.Tmp_Users (Serial, Code, Name, Password, Active, Permition, RecorderRef, RecordDate, OfficeDetailRef)
		SELECT Serial, Code, Name, CONVERT(varchar(MAX), Password), Active, Permition, RecorderRef, RecordDate, OfficeDetailRef FROM dbo.Users WITH (HOLDLOCK TABLOCKX)')
GO
ALTER TABLE dbo.BankAccount
	DROP CONSTRAINT FK_BankAccount_Users
GO
ALTER TABLE dbo.CheckGetPayHeader
	DROP CONSTRAINT FK_CheckGetPayHeader_UsersEditor
GO
ALTER TABLE dbo.CheckGetPayHeader
	DROP CONSTRAINT FK_CheckGetPayHeader_UsersRecorder
GO
ALTER TABLE dbo.CashGetPay
	DROP CONSTRAINT FK_CashGetPay_UsersEditor
GO
ALTER TABLE dbo.CashGetPay
	DROP CONSTRAINT FK_CashGetPay_UsersRecorder
GO
ALTER TABLE dbo.CashGetPay
	DROP CONSTRAINT FK_CashGetPay_UsersVerifier
GO
ALTER TABLE dbo.AccGroupCodeBook
	DROP CONSTRAINT FK_AccGroupCodeBook_Users
GO
ALTER TABLE dbo.AccGeneralCodeBook
	DROP CONSTRAINT FK_AccGeneralCodeBook_Users
GO
ALTER TABLE dbo.GritProduct
	DROP CONSTRAINT FK_GritProduct_Recorder
GO
ALTER TABLE dbo.GritProduct
	DROP CONSTRAINT FK_GritProduct_Editor
GO
ALTER TABLE dbo.AccAdjutantL1CodeBook
	DROP CONSTRAINT FK_AccAdjutantL1CodeBook_Users
GO
ALTER TABLE dbo.AccEntityL1CodeBook
	DROP CONSTRAINT FK_AccEntityL1CodeBook_Users
GO
ALTER TABLE dbo.AccEntityL2CodeBook
	DROP CONSTRAINT FK_AccEntityL2CodeBook_Users
GO
ALTER TABLE dbo.GetterOrPayerFactor
	DROP CONSTRAINT FK_GetterOrPayerFactor_Recorder
GO
ALTER TABLE dbo.GetterOrPayerFactor
	DROP CONSTRAINT FK_GetterOrPayerFactor_Editor
GO
ALTER TABLE dbo.GritFactor
	DROP CONSTRAINT FK_GritFactor_Recorder
GO
ALTER TABLE dbo.GritFactor
	DROP CONSTRAINT FK_GritFactor_Editor
GO
ALTER TABLE dbo.GritFactor
	DROP CONSTRAINT FK_GritFactor_Verifier
GO
ALTER TABLE dbo.Broker
	DROP CONSTRAINT FK_Broker_Users
GO
ALTER TABLE dbo.AccDocumentHeader
	DROP CONSTRAINT FK_AccTmpDocHeader_UsersEditor
GO
ALTER TABLE dbo.AccDocumentHeader
	DROP CONSTRAINT FK_AccTmpDocHeader_UsersRecorder
GO
ALTER TABLE dbo.AccDocumentHeader
	DROP CONSTRAINT FK_AccTmpDocHeader_UsersVerifier
GO
ALTER TABLE dbo.CostBase
	DROP CONSTRAINT FK_CostBase_Recorder
GO
ALTER TABLE dbo.CostBase
	DROP CONSTRAINT FK_CostBase_Editor
GO
ALTER TABLE dbo.CostCenter
	DROP CONSTRAINT FK_CostCenter_Recorder
GO
ALTER TABLE dbo.CostCenter
	DROP CONSTRAINT FK_CostCenter_Editor
GO
ALTER TABLE dbo.FactorUpdate
	DROP CONSTRAINT FK_FactorUpdate_Users
GO
ALTER TABLE dbo.CostCash
	DROP CONSTRAINT FK_CostCash_Recorder
GO
ALTER TABLE dbo.CostCash
	DROP CONSTRAINT FK_CostCash_Editor
GO
ALTER TABLE dbo.Bank
	DROP CONSTRAINT FK_Bank_Users
GO
ALTER TABLE dbo.CostHeader
	DROP CONSTRAINT FK_CostHeader_UsersRecorder
GO
ALTER TABLE dbo.CostHeader
	DROP CONSTRAINT FK_CostHeader_UsersEditor
GO
ALTER TABLE dbo.CostHeader
	DROP CONSTRAINT FK_CostHeader_UsersVerifier
GO
DROP TABLE dbo.Users
GO
EXECUTE sp_rename N'dbo.Tmp_Users', N'Users', 'OBJECT' 
GO
ALTER TABLE dbo.Users ADD CONSTRAINT
	PK_Users 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.CostHeader ADD CONSTRAINT
	FK_CostHeader_UsersRecorder FOREIGN KEY
	(
	RecorderRef
	) REFERENCES dbo.Users
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.CostHeader ADD CONSTRAINT
	FK_CostHeader_UsersEditor FOREIGN KEY
	(
	EditorRef
	) REFERENCES dbo.Users
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.CostHeader ADD CONSTRAINT
	FK_CostHeader_UsersVerifier FOREIGN KEY
	(
	VerifierRef
	) REFERENCES dbo.Users
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.CostHeader SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.Bank ADD CONSTRAINT
	FK_Bank_Users FOREIGN KEY
	(
	RecorderRef
	) REFERENCES dbo.Users
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.Bank SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.CostCash ADD CONSTRAINT
	FK_CostCash_Recorder FOREIGN KEY
	(
	RecorderRef
	) REFERENCES dbo.Users
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.CostCash ADD CONSTRAINT
	FK_CostCash_Editor FOREIGN KEY
	(
	EditorRef
	) REFERENCES dbo.Users
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.CostCash SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.FactorUpdate ADD CONSTRAINT
	FK_FactorUpdate_Users FOREIGN KEY
	(
	RecorderRef
	) REFERENCES dbo.Users
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.FactorUpdate SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.CostCenter ADD CONSTRAINT
	FK_CostCenter_Recorder FOREIGN KEY
	(
	RecorderRef
	) REFERENCES dbo.Users
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.CostCenter ADD CONSTRAINT
	FK_CostCenter_Editor FOREIGN KEY
	(
	EditorRef
	) REFERENCES dbo.Users
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.CostCenter SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.CostBase ADD CONSTRAINT
	FK_CostBase_Recorder FOREIGN KEY
	(
	RecorderRef
	) REFERENCES dbo.Users
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.CostBase ADD CONSTRAINT
	FK_CostBase_Editor FOREIGN KEY
	(
	EditorRef
	) REFERENCES dbo.Users
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.CostBase SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.AccDocumentHeader ADD CONSTRAINT
	FK_AccTmpDocHeader_UsersEditor FOREIGN KEY
	(
	EditorRef
	) REFERENCES dbo.Users
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.AccDocumentHeader ADD CONSTRAINT
	FK_AccTmpDocHeader_UsersRecorder FOREIGN KEY
	(
	RecorderRef
	) REFERENCES dbo.Users
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.AccDocumentHeader ADD CONSTRAINT
	FK_AccTmpDocHeader_UsersVerifier FOREIGN KEY
	(
	VerifierRef
	) REFERENCES dbo.Users
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.AccDocumentHeader SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.Broker ADD CONSTRAINT
	FK_Broker_Users FOREIGN KEY
	(
	RecorderRef
	) REFERENCES dbo.Users
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.Broker SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.GritFactor ADD CONSTRAINT
	FK_GritFactor_Recorder FOREIGN KEY
	(
	RecorderRef
	) REFERENCES dbo.Users
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.GritFactor ADD CONSTRAINT
	FK_GritFactor_Editor FOREIGN KEY
	(
	EditorRef
	) REFERENCES dbo.Users
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.GritFactor ADD CONSTRAINT
	FK_GritFactor_Verifier FOREIGN KEY
	(
	VerifierRef
	) REFERENCES dbo.Users
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.GritFactor SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.GetterOrPayerFactor ADD CONSTRAINT
	FK_GetterOrPayerFactor_Recorder FOREIGN KEY
	(
	RecorderRef
	) REFERENCES dbo.Users
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.GetterOrPayerFactor ADD CONSTRAINT
	FK_GetterOrPayerFactor_Editor FOREIGN KEY
	(
	EditorRef
	) REFERENCES dbo.Users
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.GetterOrPayerFactor SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.AccEntityL2CodeBook ADD CONSTRAINT
	FK_AccEntityL2CodeBook_Users FOREIGN KEY
	(
	RecorderRef
	) REFERENCES dbo.Users
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.AccEntityL2CodeBook SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.AccEntityL1CodeBook ADD CONSTRAINT
	FK_AccEntityL1CodeBook_Users FOREIGN KEY
	(
	RecorderRef
	) REFERENCES dbo.Users
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.AccEntityL1CodeBook SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
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 SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.GritProduct ADD CONSTRAINT
	FK_GritProduct_Recorder FOREIGN KEY
	(
	RecorderRef
	) REFERENCES dbo.Users
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.GritProduct ADD CONSTRAINT
	FK_GritProduct_Editor FOREIGN KEY
	(
	EditorRef
	) REFERENCES dbo.Users
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.GritProduct SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.AccGeneralCodeBook ADD CONSTRAINT
	FK_AccGeneralCodeBook_Users FOREIGN KEY
	(
	RecorderRef
	) REFERENCES dbo.Users
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.AccGeneralCodeBook SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.AccGroupCodeBook ADD CONSTRAINT
	FK_AccGroupCodeBook_Users FOREIGN KEY
	(
	RecorderRef
	) REFERENCES dbo.Users
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.AccGroupCodeBook SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.CashGetPay ADD CONSTRAINT
	FK_CashGetPay_UsersEditor FOREIGN KEY
	(
	EditorRef
	) REFERENCES dbo.Users
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.CashGetPay ADD CONSTRAINT
	FK_CashGetPay_UsersRecorder FOREIGN KEY
	(
	RecorderRef
	) REFERENCES dbo.Users
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.CashGetPay ADD CONSTRAINT
	FK_CashGetPay_UsersVerifier FOREIGN KEY
	(
	VerifierRef
	) REFERENCES dbo.Users
	(
	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.CheckGetPayHeader ADD CONSTRAINT
	FK_CheckGetPayHeader_UsersEditor FOREIGN KEY
	(
	EditorRef
	) REFERENCES dbo.Users
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.CheckGetPayHeader ADD CONSTRAINT
	FK_CheckGetPayHeader_UsersRecorder FOREIGN KEY
	(
	RecorderRef
	) REFERENCES dbo.Users
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.CheckGetPayHeader SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.BankAccount ADD CONSTRAINT
	FK_BankAccount_Users FOREIGN KEY
	(
	RecorderRef
	) REFERENCES dbo.Users
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.BankAccount SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
