VIVEKANANDHAN_PERIASAMY
asked on
DELETE IS NOT HAPPENING
We need to delete around 30 millions from each table based on conditions,We also have a stored procedure but it's taking hours or getting hung at sometimes.How can we make sure the data is getting deleted from the table.
I tried checking with below query ,but all remains 0 except memory_usage which is constant at 2
select logical_reads,cpu_time,mem ory_usage, row_count, reads,writ es from sys.dm_exec_sessions
where login_name ='vivek'
and session_id=61
I tried checking with below query ,but all remains 0 except memory_usage which is constant at 2
select logical_reads,cpu_time,mem
where login_name ='vivek'
and session_id=61
Use sp_who2 and look at the blocking columns to see if another spid is blocking your delete from running.
you can check the locking info, using sp_Lock or using the following query
SELECT L.request_session_id AS SPID,
DB_NAME(L.resource_databas e_id) AS DatabaseName,
O.Name AS LockedObjectName,
P.object_id AS LockedObjectId,
L.resource_type AS LockedResource,
L.request_mode AS LockType,
ST.text AS SqlStatementText,
ES.login_name AS LoginName,
ES.host_name AS HostName,
TST.is_user_transaction as IsUserTransaction,
AT.name as TransactionName,
CN.auth_scheme as AuthenticationMethod
FROM sys.dm_tran_locks L
JOIN sys.partitions P ON P.hobt_id = L.resource_associated_enti ty_id
JOIN sys.objects O ON O.object_id = P.object_id
JOIN sys.dm_exec_sessions ES ON ES.session_id = L.request_session_id
JOIN sys.dm_tran_session_transa ctions TST ON ES.session_id = TST.session_id
JOIN sys.dm_tran_active_transac tions AT ON TST.transaction_id = AT.transaction_id
JOIN sys.dm_exec_connections CN ON CN.session_id = ES.session_id
CROSS APPLY sys.dm_exec_sql_text(CN.mo st_recent_ sql_handle ) AS ST
WHERE resource_database_id = db_id()
ORDER BY L.request_session_id
SELECT L.request_session_id AS SPID,
DB_NAME(L.resource_databas
O.Name AS LockedObjectName,
P.object_id AS LockedObjectId,
L.resource_type AS LockedResource,
L.request_mode AS LockType,
ST.text AS SqlStatementText,
ES.login_name AS LoginName,
ES.host_name AS HostName,
TST.is_user_transaction as IsUserTransaction,
AT.name as TransactionName,
CN.auth_scheme as AuthenticationMethod
FROM sys.dm_tran_locks L
JOIN sys.partitions P ON P.hobt_id = L.resource_associated_enti
JOIN sys.objects O ON O.object_id = P.object_id
JOIN sys.dm_exec_sessions ES ON ES.session_id = L.request_session_id
JOIN sys.dm_tran_session_transa
JOIN sys.dm_tran_active_transac
JOIN sys.dm_exec_connections CN ON CN.session_id = ES.session_id
CROSS APPLY sys.dm_exec_sql_text(CN.mo
WHERE resource_database_id = db_id()
ORDER BY L.request_session_id
ASKER
there is no statement is getting blocked.
Would you expect other activity on the server? I'm thinking go to the OS and use Resource Monitor to check for cpu or disk activity. I've done that a few times in the past when I wondered if something was actually happening.
you can do one thing set trigger or make an entry in your own transaction log table with id of deleted record...
so you can keep track of how many records get deleted
as you said its millions of records you can delete entries from that table after each 1000 records..
although you delete 1000 records you can easily track record using id of deleted record.
you can also refer below link for more details...
http://raresql.com/2011/10/22/how-to-recover-deleted-data-from-sql-sever/
so you can keep track of how many records get deleted
as you said its millions of records you can delete entries from that table after each 1000 records..
although you delete 1000 records you can easily track record using id of deleted record.
you can also refer below link for more details...
http://raresql.com/2011/10/22/how-to-recover-deleted-data-from-sql-sever/
I suggest you not to delete all records in a single operation, but to split your query into multiple operations.
This is how I delete records from a table, based on a date field:
I hope this can help.
Regards.
This is how I delete records from a table, based on a date field:
while exists (select 1 from MyTable where MyDate < '20101200')
delete top(10000) from MyTable
where MyDate < '20101200'
This works for me.I hope this can help.
Regards.
I suggest you can use trigger and log table having row_created_date column to find exactly how many records are deleted & at what time , can also split you delete query as suggested by jonnidip.
I hope this works.
I hope this works.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i found the reason om my own way