/* 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.AccChequeOutItemInfoTemp
	DROP CONSTRAINT DF_AccChequeOutItemInfoTemp_Cashed
GO
ALTER TABLE dbo.AccChequeOutItemInfoTemp
	DROP CONSTRAINT DF__AccCheque__Updat__1C0818FF
GO
ALTER TABLE dbo.AccChequeOutItemInfoTemp
	DROP CONSTRAINT DF__AccCheque__Updat__1CFC3D38
GO
CREATE TABLE dbo.Tmp_AccChequeOutItemInfoTemp
	(
	ID bigint NOT NULL,
	ChequeOutID bigint NOT NULL,
	ChequeInfoID bigint NOT NULL,
	TotalID bigint NOT NULL,
	ControlID bigint NOT NULL,
	DetailID1 bigint NOT NULL,
	DetailID2 bigint NOT NULL,
	ChequeNo bigint NOT NULL,
	ChequeDate datetime NOT NULL,
	ChequeValue decimal(28, 5) NOT NULL,
	CashDocItemID bigint NULL,
	CashDocItemRelationID int NULL,
	Status int NOT NULL,
	CashDate datetime NULL,
	UpdateDate datetime NOT NULL,
	Updater bigint NOT NULL,
	PrintCount int NULL,
	Flags int NULL,
	ReturnDate datetime NULL,
	ReturnDocItemID bigint NULL,
	ReturnItemRelationID int NULL,
	ForType int NULL,
	ForID bigint NULL
	)  ON [PRIMARY]
GO
ALTER TABLE dbo.Tmp_AccChequeOutItemInfoTemp ADD CONSTRAINT
	DF_AccChequeOutItemInfoTemp_Cashed DEFAULT ((0)) FOR Status
GO
ALTER TABLE dbo.Tmp_AccChequeOutItemInfoTemp ADD CONSTRAINT
	DF__AccCheque__Updat__1C0818FF DEFAULT (getdate()) FOR UpdateDate
GO
ALTER TABLE dbo.Tmp_AccChequeOutItemInfoTemp ADD CONSTRAINT
	DF__AccCheque__Updat__1CFC3D38 DEFAULT ((0)) FOR Updater
GO
IF EXISTS(SELECT * FROM dbo.AccChequeOutItemInfoTemp)
	 EXEC('INSERT INTO dbo.Tmp_AccChequeOutItemInfoTemp (ID, ChequeOutID, ChequeInfoID, TotalID, ControlID, DetailID1, DetailID2, ChequeNo, ChequeDate, ChequeValue, CashDocItemID, CashDocItemRelationID, Status, CashDate, UpdateDate, Updater, PrintCount, Flags, ReturnDate, ReturnDocItemID, ReturnItemRelationID, ForType, ForID)
		SELECT ID, ChequeOutID, ChequeInfoID, TotalID, ControlID, DetailID1, DetailID2, ChequeNo, ChequeDate, ChequeValue, CashDocItemID, CashDocItemRelationID, Status, CashDate, UpdateDate, Updater, PrintCount, Flags, ReturnDate, ReturnDocItemID, ReturnItemRelationID, ForType, ForID FROM dbo.AccChequeOutItemInfoTemp WITH (HOLDLOCK TABLOCKX)')
GO
DROP TABLE dbo.AccChequeOutItemInfoTemp
GO
EXECUTE sp_rename N'dbo.Tmp_AccChequeOutItemInfoTemp', N'AccChequeOutItemInfoTemp', 'OBJECT' 
GO
create  TRIGGER AccChequeOutItemInfoTemp_LastUpdate ON dbo.AccChequeOutItemInfoTemp instead of UPDATE 
	AS

  	return
GO
create  TRIGGER dbo.AccChequeOutItemInfoTemp_Delete ON dbo.AccChequeOutItemInfoTemp instead of DELETE 
	AS
		
	return
GO
COMMIT
