if exists(select * from sys.indexes i where i.[object_id] = object_id('STOR.T_INVOICE_ITEM', 'U') and i.name = 'IX_T_INVOICE_ITEM_GTINSerialNumber')
	drop index IX_T_INVOICE_ITEM_GTINSerialNumber on STOR.T_INVOICE_ITEM;
go

if exists(select * from sys.indexes i where i.[object_id] = object_id('STOR.T_INVOICE_ITEM', 'U') and i.name = 'IX_T_INVOICE_ITEM_StorageInvoice')
	drop index IX_T_INVOICE_ITEM_StorageInvoice on STOR.T_INVOICE_ITEM;
go

ALTER TABLE STOR.T_INVOICE_ITEM ALTER COLUMN GTINSerialNumber VARCHAR(28) COLLATE Cyrillic_General_CS_AS;


CREATE INDEX IX_T_INVOICE_ITEM_StorageInvoice ON STOR.T_INVOICE_ITEM(StorageInvoice, type_) INCLUDE(QuantityInPackage, Price, TotalApplicationCount, GTINSerialNumber) WITH (FILLFACTOR=100);
CREATE INDEX IX_T_INVOICE_ITEM_GTINSerialNumber ON STOR.T_INVOICE_ITEM(GTINSerialNumber, type_) INCLUDE (StorageInvoice, SupplierContractAbr, Barcode, TotalApplicationCount, BillOfGoods) WITH (FILLFACTOR=100);