
/* 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.AccFactorDetail
	DROP CONSTRAINT DF_AccFactorDetail_Status
GO
ALTER TABLE dbo.AccFactorDetail
	DROP CONSTRAINT DF_AccFactorDetail_UpdateDate
GO
ALTER TABLE dbo.AccFactorDetail
	DROP CONSTRAINT DF_AccFactorDetail_Updater
GO
CREATE TABLE dbo.Tmp_AccFactorDetail
	(
	ID bigint NOT NULL IDENTITY (1, 1),
	FactorID bigint NOT NULL,
	OrderTotalID bigint NOT NULL,
	OrderControlID bigint NOT NULL,
	OrderDetailID1 bigint NOT NULL,
	OrderDetailID2 bigint NOT NULL,
	Request decimal(19, 5) NOT NULL,
	RequestUnit bigint NOT NULL,
	NetPrice decimal(19, 5) NOT NULL,
	TotalPrice decimal(19, 5) NOT NULL,
	DocItemID bigint NOT NULL,
	DocItemRelationID int NULL,
	DocHeaderID bigint NULL,
	Status int NULL,
	OtherTotalID bigint NULL,
	OtherControlID bigint NULL,
	OtherDetailID1 bigint NULL,
	OtherDetailID2 bigint NULL,
	Value2 decimal(19, 5) NULL,
	Unit2 bigint NULL,
	UpdateDate datetime NOT NULL,
	Updater bigint NOT NULL,
	Discont decimal(19, 5) NULL,
	Maliat decimal(19, 5) NULL,
	Avarez decimal(19, 5) NULL,
	Heigh decimal(18, 5) NULL,
	Lenght decimal(18, 5) NULL,
	Width decimal(18, 5) NULL,
	ZowjInUnit decimal(18, 5) NULL,
	Pakaging int NULL,
	Oft float(53) NULL,
	WarehouseNo bigint NULL,
	SumInFactor bit NULL,
	OrderID bigint NULL
	)  ON [PRIMARY]
GO
ALTER TABLE dbo.Tmp_AccFactorDetail ADD CONSTRAINT
	DF_AccFactorDetail_Status DEFAULT ((0)) FOR Status
GO
ALTER TABLE dbo.Tmp_AccFactorDetail ADD CONSTRAINT
	DF_AccFactorDetail_UpdateDate DEFAULT (getdate()) FOR UpdateDate
GO
ALTER TABLE dbo.Tmp_AccFactorDetail ADD CONSTRAINT
	DF_AccFactorDetail_Updater DEFAULT ((0)) FOR Updater
GO
SET IDENTITY_INSERT dbo.Tmp_AccFactorDetail ON
GO
IF EXISTS(SELECT * FROM dbo.AccFactorDetail)
	 EXEC('INSERT INTO dbo.Tmp_AccFactorDetail (ID, FactorID, OrderTotalID, OrderControlID, OrderDetailID1, OrderDetailID2, Request, RequestUnit, NetPrice, TotalPrice, DocItemID, DocItemRelationID, DocHeaderID, Status, OtherTotalID, OtherControlID, OtherDetailID1, OtherDetailID2, Value2, Unit2, UpdateDate, Updater, Discont, Maliat, Avarez, Heigh, Lenght, Width, ZowjInUnit, Pakaging, Oft, WarehouseNo, SumInFactor, OrderID)
		SELECT ID, FactorID, OrderTotalID, OrderControlID, OrderDetailID1, OrderDetailID2, Request, RequestUnit, NetPrice, TotalPrice, DocItemID, DocItemRelationID, DocHeaderID, Status, OtherTotalID, OtherControlID, OtherDetailID1, OtherDetailID2, Value2, Unit2, UpdateDate, Updater, Discont, Maliat, Avarez, Heigh, Lenght, Width, ZowjInUnit, Pakaging, Oft, WarehouseNo, SumInFactor, OrderID FROM dbo.AccFactorDetail WITH (HOLDLOCK TABLOCKX)')
GO
SET IDENTITY_INSERT dbo.Tmp_AccFactorDetail OFF
GO
DROP TABLE dbo.AccFactorDetail
GO
EXECUTE sp_rename N'dbo.Tmp_AccFactorDetail', N'AccFactorDetail', 'OBJECT' 
GO
ALTER TABLE dbo.AccFactorDetail ADD CONSTRAINT
	PK_AccFactorDetail PRIMARY KEY CLUSTERED 
	(
	ID
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

GO
COMMIT
