Skip to main content
deleted 8 characters in body; edited tags
Source Link
Colin 't Hart
  • 9.4k
  • 15
  • 36
  • 44

Good morning. RunningRunning SQL Server 2008; Mgmt Studio 2008. I am working with a MS SQL job that we have created for our MS CRM 4.0 implementation. For anyone familiar with CRM, this job purges the aSyncOperationBase table nightly to save on DB size. Here is the job code:

    Begin Transaction T1

Declare @p30Days as DateTime
Declare @p3Years as DateTime

Set @p30Days = DateAdd(d, -30, GetDate())
Set @p3Years = DateAdd(d, -1095, GetDate())

update AsyncOperationBase 
set deletionstatecode=2    
where deletionstatecode = 0 and 
statecode = 3 and 
completedon is not null and 
completedon < @p30Days   
and OperationType <> 10

update AsyncOperationBase 
set deletionstatecode=2    
where deletionstatecode = 0 and 
statecode = 3 and 
completedon is not null and 
completedon < @p3Years   
and OperationType = 10

delete from workflowlogbase    
where AsyncOperationid in (select AsyncOperationid from AsyncOperationBase where deletionstatecode=2)   

update DuplicateRecordBase 
set DeletionStateCode = 2    
where asyncoperationid in    
(select DuplicateRecordBase.asyncoperationid 
    from DuplicateRecordBase    
        left join asyncoperationbase on (DuplicateRecordBase.asyncoperationid=asyncoperationbase.asyncoperationid and    
        asyncoperationbase.deletionstatecode = 0) 
    where asyncoperationbase.asyncoperationid is null)    

update BulkDeleteOperationBase 
set DeletionStateCode = 2    
where asyncoperationid in    
(select BulkDeleteOperationBase.asyncoperationid 
    from BulkDeleteOperationBase    
        left join asyncoperationbase on (BulkDeleteOperationBase.asyncoperationid=asyncoperationbase.asyncoperationid and    
        asyncoperationbase.deletionstatecode = 0) 
    where asyncoperationbase.asyncoperationid is null)    

delete from asyncoperationbase 
where deletionstatecode = 2 and 
completedon < @p30Days  

commit transaction T1

The problem that I recently noticed is that this job, which starts at 4am, runs for at least 4 hours and does not complete. As I tried run the first update statement against 1 record, the SQL process did not complete and became the lead blocker in the process chain. Does anyone have any ideas on what could be causing this behavior? I have looked at the Activity Monitor and there are no other processes which are causing major blockages.

Good morning. Running SQL 2008; Mgmt Studio 2008. I am working with a MS SQL job that we have created for our MS CRM 4.0 implementation. For anyone familiar with CRM, this job purges the aSyncOperationBase table nightly to save on DB size. Here is the job code:

    Begin Transaction T1

Declare @p30Days as DateTime
Declare @p3Years as DateTime

Set @p30Days = DateAdd(d, -30, GetDate())
Set @p3Years = DateAdd(d, -1095, GetDate())

update AsyncOperationBase 
set deletionstatecode=2    
where deletionstatecode = 0 and 
statecode = 3 and 
completedon is not null and 
completedon < @p30Days   
and OperationType <> 10

update AsyncOperationBase 
set deletionstatecode=2    
where deletionstatecode = 0 and 
statecode = 3 and 
completedon is not null and 
completedon < @p3Years   
and OperationType = 10

delete from workflowlogbase    
where AsyncOperationid in (select AsyncOperationid from AsyncOperationBase where deletionstatecode=2)   

update DuplicateRecordBase 
set DeletionStateCode = 2    
where asyncoperationid in    
(select DuplicateRecordBase.asyncoperationid 
    from DuplicateRecordBase    
        left join asyncoperationbase on (DuplicateRecordBase.asyncoperationid=asyncoperationbase.asyncoperationid and    
        asyncoperationbase.deletionstatecode = 0) 
    where asyncoperationbase.asyncoperationid is null)    

update BulkDeleteOperationBase 
set DeletionStateCode = 2    
where asyncoperationid in    
(select BulkDeleteOperationBase.asyncoperationid 
    from BulkDeleteOperationBase    
        left join asyncoperationbase on (BulkDeleteOperationBase.asyncoperationid=asyncoperationbase.asyncoperationid and    
        asyncoperationbase.deletionstatecode = 0) 
    where asyncoperationbase.asyncoperationid is null)    

delete from asyncoperationbase 
where deletionstatecode = 2 and 
completedon < @p30Days  

commit transaction T1

The problem that I recently noticed is that this job, which starts at 4am, runs for at least 4 hours and does not complete. As I tried run the first update statement against 1 record, the SQL process did not complete and became the lead blocker in the process chain. Does anyone have any ideas on what could be causing this behavior? I have looked at the Activity Monitor and there are no other processes which are causing major blockages.

Running SQL Server 2008; Mgmt Studio 2008. I am working with a MS SQL job that we have created for our MS CRM 4.0 implementation. For anyone familiar with CRM, this job purges the aSyncOperationBase table nightly to save on DB size. Here is the job code:

    Begin Transaction T1

Declare @p30Days as DateTime
Declare @p3Years as DateTime

Set @p30Days = DateAdd(d, -30, GetDate())
Set @p3Years = DateAdd(d, -1095, GetDate())

update AsyncOperationBase 
set deletionstatecode=2    
where deletionstatecode = 0 and 
statecode = 3 and 
completedon is not null and 
completedon < @p30Days   
and OperationType <> 10

update AsyncOperationBase 
set deletionstatecode=2    
where deletionstatecode = 0 and 
statecode = 3 and 
completedon is not null and 
completedon < @p3Years   
and OperationType = 10

delete from workflowlogbase    
where AsyncOperationid in (select AsyncOperationid from AsyncOperationBase where deletionstatecode=2)   

update DuplicateRecordBase 
set DeletionStateCode = 2    
where asyncoperationid in    
(select DuplicateRecordBase.asyncoperationid 
    from DuplicateRecordBase    
        left join asyncoperationbase on (DuplicateRecordBase.asyncoperationid=asyncoperationbase.asyncoperationid and    
        asyncoperationbase.deletionstatecode = 0) 
    where asyncoperationbase.asyncoperationid is null)    

update BulkDeleteOperationBase 
set DeletionStateCode = 2    
where asyncoperationid in    
(select BulkDeleteOperationBase.asyncoperationid 
    from BulkDeleteOperationBase    
        left join asyncoperationbase on (BulkDeleteOperationBase.asyncoperationid=asyncoperationbase.asyncoperationid and    
        asyncoperationbase.deletionstatecode = 0) 
    where asyncoperationbase.asyncoperationid is null)    

delete from asyncoperationbase 
where deletionstatecode = 2 and 
completedon < @p30Days  

commit transaction T1

The problem that I recently noticed is that this job, which starts at 4am, runs for at least 4 hours and does not complete. As I tried run the first update statement against 1 record, the SQL process did not complete and became the lead blocker in the process chain. Does anyone have any ideas on what could be causing this behavior? I have looked at the Activity Monitor and there are no other processes which are causing major blockages.

edited title
Link
RolandoMySQLDBA
  • 184.4k
  • 33
  • 323
  • 531

Why doesdid my updateUPDATE statement not complete?

Tweeted twitter.com/#!/StackDBAs/status/83859547554455554
Source Link

Why does my update statement not complete?

Good morning. Running SQL 2008; Mgmt Studio 2008. I am working with a MS SQL job that we have created for our MS CRM 4.0 implementation. For anyone familiar with CRM, this job purges the aSyncOperationBase table nightly to save on DB size. Here is the job code:

    Begin Transaction T1

Declare @p30Days as DateTime
Declare @p3Years as DateTime

Set @p30Days = DateAdd(d, -30, GetDate())
Set @p3Years = DateAdd(d, -1095, GetDate())

update AsyncOperationBase 
set deletionstatecode=2    
where deletionstatecode = 0 and 
statecode = 3 and 
completedon is not null and 
completedon < @p30Days   
and OperationType <> 10

update AsyncOperationBase 
set deletionstatecode=2    
where deletionstatecode = 0 and 
statecode = 3 and 
completedon is not null and 
completedon < @p3Years   
and OperationType = 10

delete from workflowlogbase    
where AsyncOperationid in (select AsyncOperationid from AsyncOperationBase where deletionstatecode=2)   

update DuplicateRecordBase 
set DeletionStateCode = 2    
where asyncoperationid in    
(select DuplicateRecordBase.asyncoperationid 
    from DuplicateRecordBase    
        left join asyncoperationbase on (DuplicateRecordBase.asyncoperationid=asyncoperationbase.asyncoperationid and    
        asyncoperationbase.deletionstatecode = 0) 
    where asyncoperationbase.asyncoperationid is null)    

update BulkDeleteOperationBase 
set DeletionStateCode = 2    
where asyncoperationid in    
(select BulkDeleteOperationBase.asyncoperationid 
    from BulkDeleteOperationBase    
        left join asyncoperationbase on (BulkDeleteOperationBase.asyncoperationid=asyncoperationbase.asyncoperationid and    
        asyncoperationbase.deletionstatecode = 0) 
    where asyncoperationbase.asyncoperationid is null)    

delete from asyncoperationbase 
where deletionstatecode = 2 and 
completedon < @p30Days  

commit transaction T1

The problem that I recently noticed is that this job, which starts at 4am, runs for at least 4 hours and does not complete. As I tried run the first update statement against 1 record, the SQL process did not complete and became the lead blocker in the process chain. Does anyone have any ideas on what could be causing this behavior? I have looked at the Activity Monitor and there are no other processes which are causing major blockages.