I have a table called Products which has many columns.
It is a temporary table used for reporting purpose. The data will be processed to this table concurrently by multiple user requests.(seperate Stored procedure to make DML operations to this table)
Table Structure: Create table Products (instance uniqueidentifier, inserted datetime, col1, col2,...)
Inserted column will be populated with GETDATE() to have when the data are inserted. And instance column have the newid() value. one user request will have one unique id; may have million rows. The below are the queries which will be executed concurrently, which causing the deadlock. Please advise me
Query1: "Set transaction isolation readuncommitted Delete P from Products (Nolock) where instance = 'XXXX-xxx-xxx-xx'"
Query2: "Set transaction isolation readuncommitted Delete P from Products (Nolock) where inserted<=DATEADD(hh, -10, getdate())"
Note: The nonclustered index is created on instance column.
PLEASE ADVISE me which lock I can use in this scenario.
Note I couldnt able to primary key as it is consuming time when I insert 10 million rows to the table (this for one transaction; there are 20 concurrent transations). The report should be generated sooner. And my procedure has multiple 35 DML statments, there are around 15 DELETE statements for instance column with other columns( DElete from table where instance = @instance and col1 = @col1)