/* 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.AccSellFactorTrucksTemp
	DROP CONSTRAINT DF_AccSellFactorTrucksTemp_UpdateDate
GO
ALTER TABLE dbo.AccSellFactorTrucksTemp
	DROP CONSTRAINT DF_AccSellFactorTrucksTemp_Updater
GO
CREATE TABLE dbo.Tmp_AccSellFactorTrucksTemp
	(
	ID bigint NOT NULL,
	SellFactorID bigint NOT NULL,
	Date datetime NULL,
	TruckNo nvarchar(25) NOT NULL,
	Weigh decimal(18, 5) NULL,
	Unit bigint NULL,
	DocItemID bigint NULL,
	DocItemRelationID int NULL,
	DocHeaderID bigint NULL,
	Status int NULL,
	Flags int NULL,
	BarName nvarchar(25) NULL,
	Description nvarchar(100) NULL,
	ReportDate datetime NULL,
	Pack int NULL,
	TruckTel nvarchar(200) NULL,
	HamlTotalID bigint NULL,
	HamlControlID bigint NULL,
	HamlDetailID1 bigint NULL,
	HamlDetailID2 bigint NULL,
	HamlPrice decimal(19, 2) NULL,
	ChaperTotalID bigint NULL,
	ChaperControlID bigint NULL,
	ChaperDetailID1 bigint NULL,
	ChaperDetailID2 bigint NULL,
	ChaperPrice decimal(19, 2) NULL,
	ShipID bigint NULL,
	UpdateDate datetime NULL,
	Updater bigint NULL,
	InsertDate datetime NULL,
	Inserter bigint NULL,
	CancelDate datetime NULL,
	Canceler bigint NULL,
	FactorID bigint NULL,
	BSK nchar(20) NULL,
	WareOutID bigint NULL,
	WareInID bigint NULL,
	TruckName nvarchar(100) NULL,
	BarnameSerial nvarchar(25) NULL,
	TaghirMaghsad bit NULL,
	BarnameAvval nvarchar(25) NULL,
	BarnameSerialAvval nvarchar(25) NULL,
	DestinationAvval nvarchar(100) NULL,
	CottageAvval char(10) NULL,
	NumberAvval bigint NULL,
	BKharidId bigint NULL,
	BTakhsisId bigint NULL,
	ShomNameh nvarchar(50) NULL,
	TarikhNameh datetime NULL,
	companyCode nvarchar(50) NULL,
	wH1 decimal(18, 5) NULL,
	Wh2 decimal(18, 5) NULL,
	Kra1 nvarchar(50) NULL,
	Kra2 nvarchar(50) NULL,
	ka_E_Code nvarchar(50) NULL,
	tarGetName nvarchar(500) NULL,
	barExp nvarchar(50) NULL,
	mbkhaal nvarchar(50) NULL,
	ghErtebat nvarchar(500) NULL,
	kaGrp nvarchar(50) NULL,
	receiverShKharid nvarchar(50) NULL,
	receiverShTakhsis nvarchar(50) NULL,
	billLadingPlaceCode nvarchar(50) NULL,
	billLadingPlaceName nvarchar(50) NULL,
	n52 nvarchar(50) NULL,
	billofLadingCoutageCode nvarchar(50) NULL
	)  ON [PRIMARY]
GO
ALTER TABLE dbo.Tmp_AccSellFactorTrucksTemp SET (LOCK_ESCALATION = TABLE)
GO
ALTER TABLE dbo.Tmp_AccSellFactorTrucksTemp ADD CONSTRAINT
	DF_AccSellFactorTrucksTemp_UpdateDate DEFAULT (getdate()) FOR UpdateDate
GO
ALTER TABLE dbo.Tmp_AccSellFactorTrucksTemp ADD CONSTRAINT
	DF_AccSellFactorTrucksTemp_Updater DEFAULT ((0)) FOR Updater
GO
IF EXISTS(SELECT * FROM dbo.AccSellFactorTrucksTemp)
	 EXEC('INSERT INTO dbo.Tmp_AccSellFactorTrucksTemp (ID, SellFactorID, Date, TruckNo, Weigh, Unit, DocItemID, DocItemRelationID, DocHeaderID, Status, Flags, BarName, Description, ReportDate, Pack, TruckTel, HamlTotalID, HamlControlID, HamlDetailID1, HamlDetailID2, HamlPrice, ChaperTotalID, ChaperControlID, ChaperDetailID1, ChaperDetailID2, ChaperPrice, ShipID, UpdateDate, Updater, InsertDate, Inserter, CancelDate, Canceler, FactorID, BSK, WareOutID, WareInID, TruckName, BarnameSerial, TaghirMaghsad, BarnameAvval, BarnameSerialAvval, DestinationAvval, CottageAvval, NumberAvval, BKharidId, BTakhsisId, ShomNameh, TarikhNameh, companyCode, wH1, Wh2, Kra1, Kra2, ka_E_Code, tarGetName, barExp, mbkhaal, ghErtebat, kaGrp, receiverShKharid, receiverShTakhsis, billLadingPlaceCode, billLadingPlaceName, n52, billofLadingCoutageCode)
		SELECT ID, SellFactorID, Date, TruckNo, Weigh, Unit, DocItemID, DocItemRelationID, DocHeaderID, Status, Flags, BarName, Description, ReportDate, Pack, TruckTel, HamlTotalID, HamlControlID, HamlDetailID1, HamlDetailID2, HamlPrice, ChaperTotalID, ChaperControlID, ChaperDetailID1, ChaperDetailID2, ChaperPrice, ShipID, UpdateDate, Updater, InsertDate, Inserter, CancelDate, Canceler, FactorID, BSK, WareOutID, WareInID, TruckName, BarnameSerial, TaghirMaghsad, BarnameAvval, BarnameSerialAvval, DestinationAvval, CottageAvval, NumberAvval, BKharidId, BTakhsisId, ShomNameh, TarikhNameh, companyCode, wH1, Wh2, Kra1, Kra2, ka_E_Code, tarGetName, barExp, mbkhaal, ghErtebat, kaGrp, receiverShKharid, receiverShTakhsis, billLadingPlaceCode, billLadingPlaceName, n52, billofLadingCoutageCode FROM dbo.AccSellFactorTrucksTemp WITH (HOLDLOCK TABLOCKX)')
GO
DROP TABLE dbo.AccSellFactorTrucksTemp
GO
EXECUTE sp_rename N'dbo.Tmp_AccSellFactorTrucksTemp', N'AccSellFactorTrucksTemp', 'OBJECT' 
GO
COMMIT
select Has_Perms_By_Name(N'dbo.AccSellFactorTrucksTemp', 'Object', 'ALTER') as ALT_Per, Has_Perms_By_Name(N'dbo.AccSellFactorTrucksTemp', 'Object', 'VIEW DEFINITION') as View_def_Per, Has_Perms_By_Name(N'dbo.AccSellFactorTrucksTemp', 'Object', 'CONTROL') as Contr_Per 