/*
   سه شنبه, 14 بهمن 140403:02:52 ب.ظ
   User: 
   Server: TEST2\SQL19
   Database: ShayestehACC 1403
   Application: 
*/

/* 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.AccWarehouseDetails
	DROP CONSTRAINT FK_AccWarehouseDetails_AccWarehouse
GO
ALTER TABLE dbo.AccWarehouse SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
select Has_Perms_By_Name(N'dbo.AccWarehouse', 'Object', 'ALTER') as ALT_Per, Has_Perms_By_Name(N'dbo.AccWarehouse', 'Object', 'VIEW DEFINITION') as View_def_Per, Has_Perms_By_Name(N'dbo.AccWarehouse', 'Object', 'CONTROL') as Contr_Per BEGIN TRANSACTION
GO
ALTER TABLE dbo.AccWarehouseDetails
	DROP CONSTRAINT DF_AccWarehouseDetails_Status
GO
CREATE TABLE dbo.Tmp_AccWarehouseDetails
	(
	ID bigint NOT NULL IDENTITY (1, 1),
	WarehouseID 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(28, 5) NOT NULL,
	DocItemID bigint NOT 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,
	SerialFrom nchar(20) NULL,
	SerialTo nchar(20) NULL,
	Oft float(53) NULL,
	Routobat float(53) NULL,
	OftPayeh float(53) NULL,
	RoutobatPayeh float(53) NULL,
	RequestPayeh decimal(19, 5) NULL,
	Time int NULL,
	Description nvarchar(1000) NULL,
	UserNumber char(10) NULL,
	Haml decimal(19, 5) NULL,
	Takhfif decimal(19, 5) NULL,
	PrdDate datetime NULL,
	ExpDate datetime NULL,
	WarehouseNo bigint NULL,
	SFKeshti nvarchar(100) NULL,
	SFMojavez nchar(30) NULL,
	SFBarbari nvarchar(100) NULL,
	SFMabda nvarchar(100) NULL,
	SFCommision float(53) NULL,
	SFAnbarStart datetime NULL,
	SFAnbarEnd1 datetime NULL,
	SFAnbarEnd2 datetime NULL,
	SFAfzayeshType int NULL,
	SFAfzayesh1 decimal(19, 5) NULL,
	SFAfzayesh2 decimal(19, 5) NULL,
	SFSarak float(53) NULL,
	SFTonaj decimal(19, 5) NULL,
	VRequest decimal(19, 5) NULL,
	VDate datetime NULL,
	VUpdater bigint NULL,
	Maliat decimal(19, 5) NULL,
	Avarez decimal(19, 5) NULL
	)  ON [PRIMARY]
GO
ALTER TABLE dbo.Tmp_AccWarehouseDetails SET (LOCK_ESCALATION = TABLE)
GO
ALTER TABLE dbo.Tmp_AccWarehouseDetails ADD CONSTRAINT
	DF_AccWarehouseDetails_Status DEFAULT ((0)) FOR Status
GO
SET IDENTITY_INSERT dbo.Tmp_AccWarehouseDetails ON
GO
IF EXISTS(SELECT * FROM dbo.AccWarehouseDetails)
	 EXEC('INSERT INTO dbo.Tmp_AccWarehouseDetails (ID, WarehouseID, OrderTotalID, OrderControlID, OrderDetailID1, OrderDetailID2, Request, RequestUnit, NetPrice, TotalPrice, DocItemID, DocHeaderID, Status, OtherTotalID, OtherControlID, OtherDetailID1, OtherDetailID2, Value2, Unit2, SerialFrom, SerialTo, Oft, Routobat, OftPayeh, RoutobatPayeh, RequestPayeh, Time, Description, UserNumber, Haml, Takhfif, PrdDate, ExpDate, WarehouseNo, SFKeshti, SFMojavez, SFBarbari, SFMabda, SFCommision, SFAnbarStart, SFAnbarEnd1, SFAnbarEnd2, SFAfzayeshType, SFAfzayesh1, SFAfzayesh2, SFSarak, SFTonaj, VRequest, VDate, VUpdater, Maliat, Avarez)
		SELECT ID, WarehouseID, OrderTotalID, OrderControlID, OrderDetailID1, OrderDetailID2, Request, RequestUnit, NetPrice, TotalPrice, DocItemID, DocHeaderID, Status, OtherTotalID, OtherControlID, OtherDetailID1, OtherDetailID2, Value2, Unit2, SerialFrom, SerialTo, Oft, Routobat, OftPayeh, RoutobatPayeh, RequestPayeh, Time, Description, UserNumber, Haml, Takhfif, PrdDate, ExpDate, WarehouseNo, SFKeshti, SFMojavez, SFBarbari, SFMabda, SFCommision, SFAnbarStart, SFAnbarEnd1, SFAnbarEnd2, SFAfzayeshType, SFAfzayesh1, SFAfzayesh2, SFSarak, SFTonaj, VRequest, VDate, VUpdater, Maliat, Avarez FROM dbo.AccWarehouseDetails WITH (HOLDLOCK TABLOCKX)')
GO
SET IDENTITY_INSERT dbo.Tmp_AccWarehouseDetails OFF
GO
DROP TABLE dbo.AccWarehouseDetails
GO
EXECUTE sp_rename N'dbo.Tmp_AccWarehouseDetails', N'AccWarehouseDetails', 'OBJECT' 
GO
ALTER TABLE dbo.AccWarehouseDetails ADD CONSTRAINT
	PK_AccWarehouseDetails PRIMARY KEY CLUSTERED 
	(
	ID
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

GO
CREATE NONCLUSTERED INDEX IX_AccWarehouseDetails_WarehouseID ON dbo.AccWarehouseDetails
	(
	WarehouseID
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX IX_AccWarehouseDetails_DocID ON dbo.AccWarehouseDetails
	(
	DocItemID
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX IX_AccWarehouseDetails_HeaderID ON dbo.AccWarehouseDetails
	(
	DocHeaderID
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
ALTER TABLE dbo.AccWarehouseDetails ADD CONSTRAINT
	FK_AccWarehouseDetails_AccWarehouse FOREIGN KEY
	(
	WarehouseID
	) REFERENCES dbo.AccWarehouse
	(
	ID
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
COMMIT
select Has_Perms_By_Name(N'dbo.AccWarehouseDetails', 'Object', 'ALTER') as ALT_Per, Has_Perms_By_Name(N'dbo.AccWarehouseDetails', 'Object', 'VIEW DEFINITION') as View_def_Per, Has_Perms_By_Name(N'dbo.AccWarehouseDetails', 'Object', 'CONTROL') as Contr_Per 