/* 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.AccChequeInTemp
	DROP CONSTRAINT DF_AccChequeInTemp_Cashed
GO
ALTER TABLE dbo.AccChequeInTemp
	DROP CONSTRAINT DF__AccCheque__Updat__51700577
GO
ALTER TABLE dbo.AccChequeInTemp
	DROP CONSTRAINT DF__AccCheque__Updat__526429B0
GO
CREATE TABLE dbo.Tmp_AccChequeInTemp
	(
	ID bigint NOT NULL,
	DebitTotalID bigint NOT NULL,
	DebitControlID bigint NOT NULL,
	DebitDetailID1 bigint NOT NULL,
	DebitDetailID2 bigint NOT NULL,
	CreditTotalID bigint NOT NULL,
	CreditControlID bigint NOT NULL,
	CreditDetailID1 bigint NOT NULL,
	CreditDetailID2 bigint NOT NULL,
	OwnerTotalID bigint NULL,
	OwnerControlID bigint NULL,
	OwnerDetailID1 bigint NULL,
	OwnerDetailID2 bigint NULL,
	DocItemID bigint NULL,
	DocItemRelationID int NULL,
	BankName nvarchar(100) NOT NULL,
	BankBranch nvarchar(100) NOT NULL,
	ChequeNo bigint NOT NULL,
	ChequeDate datetime NOT NULL,
	ChequeValue decimal(28, 5) NOT NULL,
	Description nvarchar(3000) NULL,
	Status int NOT NULL,
	CashDate datetime NOT NULL,
	CashDocItemID bigint NULL,
	CashItemRelationID int NULL,
	UpdateDate datetime NOT NULL,
	Updater bigint NOT NULL,
	PrintCount int NULL,
	Flags int NULL,
	ReturnDate datetime NULL,
	ReturnDocItemID bigint NULL,
	ReturnItemRelationID int NULL,
	ValueDivStatus int NULL,
	Account nvarchar(20) NULL,
	CostCenter bigint NULL,
	Project bigint NULL
	)  ON [PRIMARY]
GO
ALTER TABLE dbo.Tmp_AccChequeInTemp ADD CONSTRAINT
	DF_AccChequeInTemp_Cashed DEFAULT ((0)) FOR Status
GO
ALTER TABLE dbo.Tmp_AccChequeInTemp ADD CONSTRAINT
	DF__AccCheque__Updat__51700577 DEFAULT (getdate()) FOR UpdateDate
GO
ALTER TABLE dbo.Tmp_AccChequeInTemp ADD CONSTRAINT
	DF__AccCheque__Updat__526429B0 DEFAULT ((0)) FOR Updater
GO
IF EXISTS(SELECT * FROM dbo.AccChequeInTemp)
	 EXEC('INSERT INTO dbo.Tmp_AccChequeInTemp (ID, DebitTotalID, DebitControlID, DebitDetailID1, DebitDetailID2, CreditTotalID, CreditControlID, CreditDetailID1, CreditDetailID2, OwnerTotalID, OwnerControlID, OwnerDetailID1, OwnerDetailID2, DocItemID, DocItemRelationID, BankName, BankBranch, ChequeNo, ChequeDate, ChequeValue, Description, Status, CashDate, CashDocItemID, CashItemRelationID, UpdateDate, Updater, PrintCount, Flags, ReturnDate, ReturnDocItemID, ReturnItemRelationID, ValueDivStatus, Account, CostCenter, Project)
		SELECT ID, DebitTotalID, DebitControlID, DebitDetailID1, DebitDetailID2, CreditTotalID, CreditControlID, CreditDetailID1, CreditDetailID2, OwnerTotalID, OwnerControlID, OwnerDetailID1, OwnerDetailID2, DocItemID, DocItemRelationID, BankName, BankBranch, ChequeNo, ChequeDate, ChequeValue, Description, Status, CashDate, CashDocItemID, CashItemRelationID, UpdateDate, Updater, PrintCount, Flags, ReturnDate, ReturnDocItemID, ReturnItemRelationID, ValueDivStatus, Account, CostCenter, Project FROM dbo.AccChequeInTemp WITH (HOLDLOCK TABLOCKX)')
GO
DROP TABLE dbo.AccChequeInTemp
GO
EXECUTE sp_rename N'dbo.Tmp_AccChequeInTemp', N'AccChequeInTemp', 'OBJECT' 
GO
create  TRIGGER dbo.AccChequeInTemp_Delete ON dbo.AccChequeInTemp instead of DELETE 
	AS
		
	return
GO
create  TRIGGER AccChequeInTemp_LastUpdate ON dbo.AccChequeInTemp instead of UPDATE 
	AS

  	return
GO
COMMIT
