How could I optimize my 2 queries. They execute very slow in my database. Any help is appreciated.
INSERT INTO InventoryDetails(InventoryID, AttributeKeyID, LSSMIN)
select '194572', 1, LSS.AttributeKey from TransactionLogs TL INNER JOIN LSSInventory LSS ON LSS.SAPSONumber = TL.SAP Where TL.SAP = '5001044323'
INSERT INTO StockMovement(InventoryDetailID, MovementCode, DateCreated,CompanyID,StatusID)
SELECT InventoryDetailID, 'WHRD', GETDATE(),'41',4 FROM InventoryDetails WHERE InventoryID = '194572'
There are two queries. Both are slow ? Try to execute separately.
And inside query, the select part it's slow?
If yes, do you have the right indexes defined on it?
This tables are heap tables or they have a clustered index on it?
At the first look, index on SAPSONumber column (with including AttributeKey) and on SAP column
For the second query, on InventoryID - probably this one already exists