FIX: You may encounter a deadlock scenario when you use table variables in SQL Server 2005 or in SQL Server 2008

Article translations Article translations
Article ID: 960283 - View products that this article applies to.
Bug #: 50003816 (SQL Hotfix)

Microsoft distributes Microsoft SQL Server 2005 or SQL Server 2008 fixes as one downloadable file. Because the fixes are cumulative, each new release contains all the hotfixes and all the security fixes that were included with the previous SQL Server 2005 or SQL Server 2008 fix release.
Expand all | Collapse all

On This Page

SYMPTOMS

In Microsoft SQL Server 2005 or in Microsoft SQL Server 2008, you may encounter a deadlock scenario when you run a query that resembles the following:
INSERT <table variable> EXEC <stored procedure>

RESOLUTION

Cumulative update information

SQL Server 2005 Service Pack 2

Important You must use this fix if you are running SQL Server 2005 Service Pack 2.

The fix for this issue was first released in Cumulative Update 11 for SQL Server 2005 Service Pack 2. For more information about this cumulative update package, click the following article number to view the article in the Microsoft Knowledge Base:
958735 Cumulative update package 11 for SQL Server 2005 Service Pack 2
Note Because the builds are cumulative, each new fix release contains all the hotfixes and all the security fixes that were included with the previous SQL Server 2005 fix release. Microsoft recommends that you consider applying the most recent fix release that contains this hotfix. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
937137 The SQL Server 2005 builds that were released after SQL Server 2005 Service Pack 2 was released
Microsoft SQL Server 2005 hotfixes are created for specific SQL Server service packs. You must apply a SQL Server 2005 Service Pack 2 hotfix to an installation of SQL Server 2005 Service Pack 2. By default, any hotfix that is provided in a SQL Server service pack is included in the next SQL Server service pack.

SQL Server 2005 Service Pack 3

Important You must use this fix if you are running SQL Server 2005 Service Pack 3.

The fix for this issue was also later released in Cumulative Update 1 for SQL Server 2005 Service Pack 3. For more information about this cumulative update package, click the following article number to view the article in the Microsoft Knowledge Base:
959195 Cumulative update package 1 for SQL Server 2005 Service Pack 3
Note Because the builds are cumulative, each new fix release contains all the hotfixes and all the security fixes that were included with the previous SQL Server 2005 fix release. Microsoft recommends that you consider applying the most recent fix release that contains this hotfix. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
960598 The SQL Server 2005 builds that were released after SQL Server 2005 Service Pack 3 was released
Microsoft SQL Server 2005 hotfixes are created for specific SQL Server service packs. You must apply a SQL Server 2005 Service Pack 3 hotfix to an installation of SQL Server 2005 Service Pack 3. By default, any hotfix that is provided in a SQL Server service pack is included in the next SQL Server service pack.

SQL Server 2008

The fix for this issue was first released in Cumulative Update 3. For more information about how to obtain this cumulative update package for SQL Server 2008, click the following article number to view the article in the Microsoft Knowledge Base:
960484 Cumulative update package 3 for SQL Server 2008
Note Because the builds are cumulative, each new fix release contains all the hotfixes and all the security fixes that were included with the previous SQL Server 2008 fix release. We recommend that you consider applying the most recent fix release that contains this hotfix. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
956909 The SQL Server 2008 builds that were released after SQL Server 2008 was released

WORKAROUND

To work around this problem, use temporary table instead of table variable.

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.

MORE INFORMATION

When this problem occurs, the events resemble the following are logged in SQL Server error log:
<Date Time> spid4s      Deadlock encountered .... Printing deadlock information
<Date Time> spid4s      Wait-for graph
<Date Time> spid4s      
<Date Time> spid4s      Node:1

<Date Time> spid4s      OBJECT: 2:416629173:0          CleanCnt:3 Mode:Sch-S Flags: 0x0
<Date Time> spid4s       Grant List 1:
<Date Time> spid4s         Owner:0x05617D00 Mode: Sch-S    Flg:0x0 Ref:1 Life:00000000 SPID:56 ECID:0 XactLockInfo: 0x158308D4
<Date Time> spid4s         SPID: 56 ECID: 0 Statement Type: INSERT Line #: 64
<Date Time> spid4s         Input Buf: RPC Event: Proc [Database Id = 28 Object Id = 160719625]
<Date Time> spid4s       Requested By: 
<Date Time> spid4s         ResType:LockOwner Stype:'OR'Xdes:0x1B907648 Mode: Sch-M SPID:56 BatchID:0 ECID:0 TaskProxy:(0x4B938364) Value:0x561f060 Cost:(N/A)
<Date Time> spid4s      Deadlock monitor failed to resolve this deadlock.
Server may require restart to recover from this condition
<Date Time> spid4s      Using 'dbghelp.dll' version '4.0.5'
<Date Time> spid14s     deadlock-list
<Date Time> spid14s      deadlock victim=process0
<Date Time> spid14s       process-list
<Date Time> spid14s        process id=process9285c8 waitresource=OBJECT: 2:416629173:0  waittime=12593 ownerId=1746104 transactionname=droptemp lasttranstarted=<Date Time> XDES=0x1b907648 lockMode=Sch-M schedulerid=2 kpid=8652 status=suspended spid=56 sbid=0 ecid=0 priority=0 transcount=1 lastbatchstarted=<Date Time> lastbatchcompleted=<Date Time> clientapp=WstClient hostname=PTONEBOX02 hostpid=21660 loginname=NT AUTHORITY\NETWORK SERVICE isolationlevel=read committed (2) xactid=1745726 currentdb=28 lockTimeout=4294967295 clientoption1=673316896 clientoption2=128056
<Date Time> spid14s         executionStack
<Date Time> spid14s          frame procname=Group.dbo.psp_GroupEntityChangesGet line=64 stmtstart=4052 stmtend=4830 sqlhandle=0x03001c0009639409d6a1a100289b00000100000000000000
<Date Time> spid14s     INSERT @t_Rowset
<Date Time> spid14s             EXEC @i_ReturnCode = @vc_ProcName
<Date Time> spid14s                  @i_ReleaseVersion = @i_ReleaseVersion
<Date Time> spid14s                 ,@bi_ScopeID = @bi_ScopeID
<Date Time> spid14s                 ,@dt_StartDatetime = @dt_StartDatetime
<Date Time> spid14s                 ,@dt_EndDatetime = @dt_EndDatetime
<Date Time> spid14s                 ,@f_ReturnAll = @f_ReturnAll
<Date Time> spid14s                 ,@i_MaxRows = @i_MaxRows
<Date Time> spid14s                 ,@f_MoreRows = @f_MoreRows OUTPUT     
<Date Time> spid14s         inputbuf
<Date Time> spid14s     Proc [Database Id = 28 Object Id = 160719625]    
<Date Time> spid14s       resource-list
<Date Time> spid14s        objectlock lockPartition=0 objid=416629173 subresource=FULL dbid=2 objectname=tempdb.dbo.#18D541B5 id=lock13849a80 mode=Sch-S associatedObjectId=416629173
<Date Time> spid14s         owner-list
<Date Time> spid14s          owner id=process9285c8 mode=Sch-S
<Date Time> spid14s         waiter-list
<Date Time> spid14s          waiter id=process9285c8 mode=Sch-M requestType=wait
<Date Time> spid4s      **Dump thread - spid = 4, PSS = 0x059DA7D8, EC = 0x059DA7E0
<Date Time> spid4s      ***Stack Dump being sent to <drive>:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\<dumpname>.txt
<Date Time> spid4s      * *******************************************************************************
<Date Time> spid4s      *
<Date Time> spid4s      * BEGIN STACK DUMP:
<Date Time> spid4s      *   <Date Time> spid 4
<Date Time> spid4s      *
<Date Time> spid4s      * Unresolved deadlock
<Date Time> spid4s      *
<Date Time> spid4s      *  
<Date Time> spid4s      * *******************************************************************************

SQL Server 2005

For more information about what files are changed, and for information about any prerequisites to apply the cumulative update package that contains the hotfix that is described in this Microsoft Knowledge Base article, click the following article number to view the article in the Microsoft Knowledge Base:
958735 Cumulative update package 11 for SQL Server 2005 Service Pack 2

SQL Server 2008

For more information about what files are changed, and for information about any prerequisites to apply the cumulative update package that contains the hotfix that is described in this Microsoft Knowledge Base article, click the following article number to view the article in the Microsoft Knowledge Base:
960484 Cumulative update package 3 for SQL Server 2008

REFERENCES

For more information about the list of builds that are available after SQL Server Service Pack 2, click the following article number to view the article in the Microsoft Knowledge Base:
937137 The SQL Server 2005 builds that were released after SQL Server 2005 Service Pack 2 was released
For more information about the Incremental Servicing Model for SQL Server, click the following article number to view the article in the Microsoft Knowledge Base:
935897 An Incremental Servicing Model is available from the SQL Server team to deliver hotfixes for reported problems
For more information about how to obtain SQL Server 2005 Service Pack 2, click the following article number to view the article in the Microsoft Knowledge Base:
913089 How to obtain the latest service pack for SQL Server 2005
For more information about the new features and the improvements in SQL Server 2005 Service Pack 2, visit the following Microsoft Web site:
http://go.microsoft.com/fwlink/?LinkId=71711
For more information about the naming schema for SQL Server updates, click the following article number to view the article in the Microsoft Knowledge Base:
822499 New naming schema for Microsoft SQL Server software update packages
For more information about software update terminology, click the following article number to view the article in the Microsoft Knowledge Base:
824684 Description of the standard terminology that is used to describe Microsoft software updates

Properties

Article ID: 960283 - Last Review: January 19, 2009 - Revision: 3.0
APPLIES TO
  • Microsoft SQL Server 2005 Standard Edition
  • Microsoft SQL Server 2005 Enterprise Edition
  • Microsoft SQL Server 2005 Developer Edition
  • Microsoft SQL Server 2005 Standard X64 Edition
  • Microsoft SQL Server 2005 Enterprise X64 Edition
  • Microsoft SQL Server 2005 Enterprise Edition for Itanium-based Systems
  • Microsoft SQL Server 2005 Standard Edition for Itanium-based Systems
  • Microsoft SQL Server 2005 Workgroup Edition
  • Microsoft SQL Server 2008 Standard
  • Microsoft SQL Server 2008 Enterprise
  • Microsoft SQL Server 2008 Developer
  • Microsoft SQL Server 2008 Workgroup
Keywords: 
kbsurveynew kbhotfixrollup kbfix kbqfe kbexpertiseadvanced KB960283

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com