/* 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.AccTotalTemp
	DROP CONSTRAINT DF__AccTotalT__Updat__000AF8CF
GO
ALTER TABLE dbo.AccTotalTemp
	DROP CONSTRAINT DF__AccTotalT__Updat__00FF1D08
GO
CREATE TABLE dbo.Tmp_AccTotalTemp
	(
	ID bigint NOT NULL,
	Code nvarchar(20) NOT NULL,
	Title nvarchar(100) NOT NULL,
	Type int NOT NULL,
	CreditType int NOT NULL,
	Description nvarchar(2000) NULL,
	CommitteRef bigint NULL,
	Credit decimal(19, 2) NULL,
	Debit decimal(19, 2) NULL,
	UpdateDate datetime NOT NULL,
	Updater bigint NULL,
	AttachPath nvarchar(1000) NULL,
	TitleNoSpace nvarchar(500) NULL
	)  ON [PRIMARY]
GO
ALTER TABLE dbo.Tmp_AccTotalTemp ADD CONSTRAINT
	DF__AccTotalT__Updat__000AF8CF DEFAULT (getdate()) FOR UpdateDate
GO
ALTER TABLE dbo.Tmp_AccTotalTemp ADD CONSTRAINT
	DF__AccTotalT__Updat__00FF1D08 DEFAULT ((0)) FOR Updater
GO
IF EXISTS(SELECT * FROM dbo.AccTotalTemp)
	 EXEC('INSERT INTO dbo.Tmp_AccTotalTemp (ID, Code, Title, Type, CreditType, Description, CommitteRef, Credit, Debit, UpdateDate, Updater, AttachPath, TitleNoSpace)
		SELECT ID, CONVERT(nvarchar(20), Code), Title, Type, CreditType, Description, CommitteRef, Credit, Debit, UpdateDate, Updater, AttachPath, TitleNoSpace FROM dbo.AccTotalTemp WITH (HOLDLOCK TABLOCKX)')
GO
DROP TABLE dbo.AccTotalTemp
GO
EXECUTE sp_rename N'dbo.Tmp_AccTotalTemp', N'AccTotalTemp', 'OBJECT' 
GO
create      TRIGGER dbo.AccTotalTemp_Delete ON dbo.AccTotalTemp instead of DELETE 
	AS
		
	return
GO
create      TRIGGER dbo.AccTotalTemp_Update ON dbo.AccTotalTemp instead of UPDATE 
	AS

  	return
GO
COMMIT
