/* 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.AccDocItemTemp
	DROP CONSTRAINT DF__AccDocIte__Credi__1758727B
GO
ALTER TABLE dbo.AccDocItemTemp
	DROP CONSTRAINT DF__AccDocIte__Debit__184C96B4
GO
ALTER TABLE dbo.AccDocItemTemp
	DROP CONSTRAINT DF__AccDocIte__ShowO__1940BAED
GO
ALTER TABLE dbo.AccDocItemTemp
	DROP CONSTRAINT DF__AccDocIte__Relat__1A34DF26
GO
ALTER TABLE dbo.AccDocItemTemp
	DROP CONSTRAINT DF__AccDocIte__Updat__1B29035F
GO
ALTER TABLE dbo.AccDocItemTemp
	DROP CONSTRAINT DF__AccDocIte__Updat__1C1D2798
GO
ALTER TABLE dbo.AccDocItemTemp
	DROP CONSTRAINT DF_AccDocItemTemp_RelationTable
GO
ALTER TABLE dbo.AccDocItemTemp
	DROP CONSTRAINT DF_AccDocItemTemp_RelationTableID
GO
ALTER TABLE dbo.AccDocItemTemp
	DROP CONSTRAINT DF_AccDocItemTemp_Confirmed
GO
CREATE TABLE dbo.Tmp_AccDocItemTemp
	(
	ID bigint NOT NULL,
	HeaderID bigint NOT NULL,
	TotalID bigint NOT NULL,
	ControlID bigint NULL,
	DetailID1 bigint NULL,
	DetailID2 bigint NULL,
	Credit decimal(28, 5) NOT NULL,
	Debit decimal(28, 5) NOT NULL,
	Description nvarchar(3000) NULL,
	ShowOrder int NOT NULL,
	RelationID int NOT NULL,
	UpdateDate datetime NOT NULL,
	Updater bigint NULL,
	RelationTable int NOT NULL,
	RelationTableID bigint NOT NULL,
	Confirmed bit NULL,
	FormData nvarchar(MAX) NULL,
	CostCenter bigint NULL,
	Project bigint NULL
	)  ON [PRIMARY]
	 TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE dbo.Tmp_AccDocItemTemp ADD CONSTRAINT
	DF__AccDocIte__Credi__1758727B DEFAULT ((0)) FOR Credit
GO
ALTER TABLE dbo.Tmp_AccDocItemTemp ADD CONSTRAINT
	DF__AccDocIte__Debit__184C96B4 DEFAULT ((0)) FOR Debit
GO
ALTER TABLE dbo.Tmp_AccDocItemTemp ADD CONSTRAINT
	DF__AccDocIte__ShowO__1940BAED DEFAULT ((1)) FOR ShowOrder
GO
ALTER TABLE dbo.Tmp_AccDocItemTemp ADD CONSTRAINT
	DF__AccDocIte__Relat__1A34DF26 DEFAULT ((0)) FOR RelationID
GO
ALTER TABLE dbo.Tmp_AccDocItemTemp ADD CONSTRAINT
	DF__AccDocIte__Updat__1B29035F DEFAULT (getdate()) FOR UpdateDate
GO
ALTER TABLE dbo.Tmp_AccDocItemTemp ADD CONSTRAINT
	DF__AccDocIte__Updat__1C1D2798 DEFAULT ((0)) FOR Updater
GO
ALTER TABLE dbo.Tmp_AccDocItemTemp ADD CONSTRAINT
	DF_AccDocItemTemp_RelationTable DEFAULT ((0)) FOR RelationTable
GO
ALTER TABLE dbo.Tmp_AccDocItemTemp ADD CONSTRAINT
	DF_AccDocItemTemp_RelationTableID DEFAULT ((0)) FOR RelationTableID
GO
ALTER TABLE dbo.Tmp_AccDocItemTemp ADD CONSTRAINT
	DF_AccDocItemTemp_Confirmed DEFAULT ((0)) FOR Confirmed
GO
IF EXISTS(SELECT * FROM dbo.AccDocItemTemp)
	 EXEC('INSERT INTO dbo.Tmp_AccDocItemTemp (ID, HeaderID, TotalID, ControlID, DetailID1, DetailID2, Credit, Debit, Description, ShowOrder, RelationID, UpdateDate, Updater, RelationTable, RelationTableID, Confirmed, FormData, CostCenter, Project)
		SELECT ID, HeaderID, TotalID, ControlID, DetailID1, DetailID2, Credit, Debit, Description, ShowOrder, RelationID, UpdateDate, Updater, RelationTable, RelationTableID, Confirmed, FormData, CostCenter, Project FROM dbo.AccDocItemTemp WITH (HOLDLOCK TABLOCKX)')
GO
DROP TABLE dbo.AccDocItemTemp
GO
EXECUTE sp_rename N'dbo.Tmp_AccDocItemTemp', N'AccDocItemTemp', 'OBJECT' 
GO
create       TRIGGER AccDocItemTemp_Update ON dbo.AccDocItemTemp instead of UPDATE
	AS

  	return
GO
create     TRIGGER AccDocItemTemp_Delete ON dbo.AccDocItemTemp instead of DELETE 
	AS
		
	return
GO
COMMIT
