/*
   Friday, April 29, 202208:14:06 ب.ظ
*/

/* 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.AccWarehouse
	DROP CONSTRAINT DF_AccWarehouse_UpdateDate
GO
ALTER TABLE dbo.AccWarehouse
	DROP CONSTRAINT DF_AccWarehouse_Updater
GO
ALTER TABLE dbo.AccWarehouse
	DROP CONSTRAINT DF_AccWarehouse_FromFactor
GO
ALTER TABLE dbo.AccWarehouse
	DROP CONSTRAINT DF_AccWarehouse_Flags
GO
CREATE TABLE dbo.Tmp_AccWarehouse
	(
	ID bigint NOT NULL IDENTITY (1, 1),
	InOROut tinyint NOT NULL,
	Number bigint NOT NULL,
	UserNumber bigint NOT NULL,
	Date datetime NOT NULL,
	WarehouseID bigint NOT NULL,
	PersonTotalID bigint NOT NULL,
	PersonControlID bigint NOT NULL,
	PersonDetailID1 bigint NOT NULL,
	PersonDetailID2 bigint NOT NULL,
	Description nvarchar(3000) NULL,
	UpdateDate datetime NOT NULL,
	Updater bigint NOT NULL,
	WarehouseIDTo bigint NULL,
	FormID bigint NULL,
	FromForm int NULL,
	OutID bigint NULL,
	Takhfif decimal(19, 5) NULL,
	HamlAndOther decimal(19, 5) NULL,
	TakhfifDocItemID bigint NULL,
	TakhfifDocHeaderID bigint NULL,
	HamlDocItemID bigint NULL,
	HamlDocHeaderID bigint NULL,
	CostCenter bigint NULL,
	Project bigint NULL,
	Flags bigint NULL
	)  ON [PRIMARY]
GO
ALTER TABLE dbo.Tmp_AccWarehouse ADD CONSTRAINT
	DF_AccWarehouse_UpdateDate DEFAULT (getdate()) FOR UpdateDate
GO
ALTER TABLE dbo.Tmp_AccWarehouse ADD CONSTRAINT
	DF_AccWarehouse_Updater DEFAULT ((0)) FOR Updater
GO
ALTER TABLE dbo.Tmp_AccWarehouse ADD CONSTRAINT
	DF_AccWarehouse_FromFactor DEFAULT ((0)) FOR FromForm
GO
ALTER TABLE dbo.Tmp_AccWarehouse ADD CONSTRAINT
	DF_AccWarehouse_Flags DEFAULT ((0)) FOR Flags
GO
SET IDENTITY_INSERT dbo.Tmp_AccWarehouse ON
GO
IF EXISTS(SELECT * FROM dbo.AccWarehouse)
	 EXEC('INSERT INTO dbo.Tmp_AccWarehouse (ID, InOROut, Number, UserNumber, Date, WarehouseID, PersonTotalID, PersonControlID, PersonDetailID1, PersonDetailID2, Description, UpdateDate, Updater, WarehouseIDTo, FormID, FromForm, OutID, Takhfif, HamlAndOther, TakhfifDocItemID, TakhfifDocHeaderID, HamlDocItemID, HamlDocHeaderID, CostCenter, Project, Flags)
		SELECT ID, InOROut, Number, UserNumber, Date, WarehouseID, PersonTotalID, PersonControlID, PersonDetailID1, PersonDetailID2, Description, UpdateDate, Updater, WarehouseIDTo, FormID, FromForm, OutID, Takhfif, HamlAndOther, TakhfifDocItemID, TakhfifDocHeaderID, HamlDocItemID, HamlDocHeaderID, CostCenter, Project, Flags FROM dbo.AccWarehouse WITH (HOLDLOCK TABLOCKX)')
GO
SET IDENTITY_INSERT dbo.Tmp_AccWarehouse OFF
GO
ALTER TABLE dbo.AccWarehouseDetails
	DROP CONSTRAINT FK_AccWarehouseDetails_AccWarehouse
GO
DROP TABLE dbo.AccWarehouse
GO
EXECUTE sp_rename N'dbo.Tmp_AccWarehouse', N'AccWarehouse', 'OBJECT' 
GO
ALTER TABLE dbo.AccWarehouse ADD CONSTRAINT
	PK_AccWarehouse 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_AccWarehouse_WarehouseID ON dbo.AccWarehouse
	(
	WarehouseID
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
COMMIT
 BEGIN TRANSACTION
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
