-- Tables

-- Alters

ALTER TABLE [STOR].[T_INVENTORY_ELEMENTS_REMAINS] ADD [SpecifiedQuantity] decimal(31, 10) NOT NULL CONSTRAINT [df_SpecifiedQuantity] DEFAULT 0 WITH VALUES
GO
ALTER TABLE [STOR].[T_INVENTORY_ELEMENTS_REMAINS] DROP CONSTRAINT [df_SpecifiedQuantity]
GO
update [STOR].[T_INVENTORY_ELEMENTS_REMAINS] set [SpecifiedQuantity] = Amount
GO

ALTER TABLE [STOR].[T_INVENTORY_ELEMENTS_REMAINS] ADD [SpecifiedPackageType] uniqueidentifier NULL
GO

update ier
set ier.SpecifiedPackageType = ie.PackageTypePrice
from [STOR].[T_INVENTORY_ELEMENTS_REMAINS] ier
join STOR.T_INVENTORY_ELEMENTS ie on ie.InventoryElementsID = ier.InventoryElements


ALTER TABLE [STOR].[T_INVENTORY_ELEMENTS_REMAINS] ADD CONSTRAINT [FK_T_PACKAGE_TYPE_T_INVENTORY_ELEMENTS_REMAINS_SpecifiedPackageType]
FOREIGN KEY([SpecifiedPackageType]) REFERENCES [PHARM].[T_PACKAGE_TYPE] ([PackageTypeID])
GO


ALTER TABLE [STOR].[T_SCANNED_INVENTORY_ELEMENTS] ADD [SpecifiedQuantity] decimal(20, 6) NOT NULL CONSTRAINT [df_SpecifiedQuantity] DEFAULT 0 WITH VALUES
GO
ALTER TABLE [STOR].[T_SCANNED_INVENTORY_ELEMENTS] DROP CONSTRAINT [df_SpecifiedQuantity]
GO
update [STOR].[T_SCANNED_INVENTORY_ELEMENTS] set [SpecifiedQuantity] = Amount
GO

ALTER TABLE [STOR].[T_SCANNED_INVENTORY_ELEMENTS] ADD [SpecifiedPackageType] uniqueidentifier NULL
GO

update ier
set ier.SpecifiedPackageType = ie.PackageTypePrice
from [STOR].[T_SCANNED_INVENTORY_ELEMENTS] ier
join STOR.T_INVENTORY_ELEMENTS ie on ie.InventoryElementsID = ier.InventoryElements

ALTER TABLE [STOR].[T_SCANNED_INVENTORY_ELEMENTS] ADD CONSTRAINT [FK_T_PACKAGE_TYPE_T_SCANNED_INVENTORY_ELEMENTS_SpecifiedPackageType]
FOREIGN KEY([SpecifiedPackageType]) REFERENCES [PHARM].[T_PACKAGE_TYPE] ([PackageTypeID])
GO
