/* 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.AccControlTemp
	DROP CONSTRAINT DF__AccContro__Updat__49AEE81E
GO
ALTER TABLE dbo.AccControlTemp
	DROP CONSTRAINT DF__AccContro__Updat__4AA30C57
GO
ALTER TABLE dbo.AccControlTemp
	DROP CONSTRAINT DF__AccContro__Activ__4B973090
GO
CREATE TABLE dbo.Tmp_AccControlTemp
	(
	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,
	Credit decimal(19, 2) NULL,
	Debit decimal(19, 2) NULL,
	UpdateDate datetime NOT NULL,
	Updater bigint NULL,
	Active bit NULL,
	AttachPath nvarchar(1000) NULL,
	TitleNoSpace nvarchar(500) NULL
	)  ON [PRIMARY]
GO
ALTER TABLE dbo.Tmp_AccControlTemp ADD CONSTRAINT
	DF__AccContro__Updat__49AEE81E DEFAULT (getdate()) FOR UpdateDate
GO
ALTER TABLE dbo.Tmp_AccControlTemp ADD CONSTRAINT
	DF__AccContro__Updat__4AA30C57 DEFAULT ((0)) FOR Updater
GO
ALTER TABLE dbo.Tmp_AccControlTemp ADD CONSTRAINT
	DF__AccContro__Activ__4B973090 DEFAULT ((1)) FOR Active
GO
IF EXISTS(SELECT * FROM dbo.AccControlTemp)
	 EXEC('INSERT INTO dbo.Tmp_AccControlTemp (ID, Code, Title, Type, CreditType, Description, Credit, Debit, UpdateDate, Updater, Active, AttachPath, TitleNoSpace)
		SELECT ID, CONVERT(nvarchar(20), Code), Title, Type, CreditType, Description, Credit, Debit, UpdateDate, Updater, Active, AttachPath, TitleNoSpace FROM dbo.AccControlTemp WITH (HOLDLOCK TABLOCKX)')
GO
DROP TABLE dbo.AccControlTemp
GO
EXECUTE sp_rename N'dbo.Tmp_AccControlTemp', N'AccControlTemp', 'OBJECT' 
GO
create      TRIGGER dbo.AccControlTemp_LastUpdate ON dbo.AccControlTemp instead of UPDATE 
	AS

  	return
GO
create      TRIGGER dbo.AccControlTemp_Delete ON dbo.AccControlTemp instead of DELETE 
	AS
		
	return
GO
COMMIT
