/* 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.AccDocHeaderTemp
	DROP CONSTRAINT DF__AccDocHea__UserN__1EF99443
GO
ALTER TABLE dbo.AccDocHeaderTemp
	DROP CONSTRAINT DF__AccDocHea__DocVa__1FEDB87C
GO
ALTER TABLE dbo.AccDocHeaderTemp
	DROP CONSTRAINT DF__AccDocHea__IsPer__20E1DCB5
GO
ALTER TABLE dbo.AccDocHeaderTemp
	DROP CONSTRAINT DF__AccDocHea__Updat__21D600EE
GO
ALTER TABLE dbo.AccDocHeaderTemp
	DROP CONSTRAINT DF__AccDocHea__Updat__22CA2527
GO
CREATE TABLE dbo.Tmp_AccDocHeaderTemp
	(
	ID bigint NOT NULL,
	Number bigint NOT NULL,
	UserNumber bigint NOT NULL,
	DocDate datetime NOT NULL,
	DocValue decimal(28, 5) NOT NULL,
	Description nvarchar(3000) NULL,
	Flags int NULL,
	IsPermanent bit NOT NULL,
	UpdateDate datetime NOT NULL,
	Updater bigint NULL,
	DocDatePer char(10) NULL,
	TempNumber bigint NULL,
	TempDate datetime NULL
	)  ON [PRIMARY]
GO
ALTER TABLE dbo.Tmp_AccDocHeaderTemp ADD CONSTRAINT
	DF__AccDocHea__UserN__1EF99443 DEFAULT ((0)) FOR UserNumber
GO
ALTER TABLE dbo.Tmp_AccDocHeaderTemp ADD CONSTRAINT
	DF__AccDocHea__DocVa__1FEDB87C DEFAULT ((0)) FOR DocValue
GO
ALTER TABLE dbo.Tmp_AccDocHeaderTemp ADD CONSTRAINT
	DF__AccDocHea__IsPer__20E1DCB5 DEFAULT ((1)) FOR IsPermanent
GO
ALTER TABLE dbo.Tmp_AccDocHeaderTemp ADD CONSTRAINT
	DF__AccDocHea__Updat__21D600EE DEFAULT (getdate()) FOR UpdateDate
GO
ALTER TABLE dbo.Tmp_AccDocHeaderTemp ADD CONSTRAINT
	DF__AccDocHea__Updat__22CA2527 DEFAULT ((0)) FOR Updater
GO
IF EXISTS(SELECT * FROM dbo.AccDocHeaderTemp)
	 EXEC('INSERT INTO dbo.Tmp_AccDocHeaderTemp (ID, Number, UserNumber, DocDate, DocValue, Description, Flags, IsPermanent, UpdateDate, Updater, DocDatePer, TempNumber, TempDate)
		SELECT ID, Number, UserNumber, DocDate, DocValue, Description, Flags, IsPermanent, UpdateDate, Updater, DocDatePer, TempNumber, TempDate FROM dbo.AccDocHeaderTemp WITH (HOLDLOCK TABLOCKX)')
GO
DROP TABLE dbo.AccDocHeaderTemp
GO
EXECUTE sp_rename N'dbo.Tmp_AccDocHeaderTemp', N'AccDocHeaderTemp', 'OBJECT' 
GO
create       TRIGGER dbo.AccDocHeaderTemp_Update ON dbo.AccDocHeaderTemp instead of UPDATE
	AS

  	return
GO
create     TRIGGER dbo.AccDocHeaderTemp_Delete ON dbo.AccDocHeaderTemp instead of DELETE 
	AS
		
	return
GO
COMMIT
