我能够重现这一点。死锁图很奇怪:
<deadlock-list>
<deadlock victim="process47f948">
<process-list>
<process id="process47f948" taskpriority="0" logused="0" waitresource="METADATA: database_id = 2 USER_TYPE(user_type_id = 257)" waittime="3607" ownerId="14873" transactionname="@myPK" lasttranstarted="2013-11-06T13:23:12.177" XDES="0x80f6d950" lockMode="Sch-S" schedulerid="1" kpid="2672" status="suspended" spid="54" sbid="0" ecid="0" priority="0" trancount="1" lastbatchstarted="2013-11-06T13:23:12.167" lastbatchcompleted="2013-11-06T13:23:12.163" clientapp="Microsoft SQL Server Management Studio - Query" hostname="xxxxx" hostpid="5276" loginname="xxxxx\xxxxx" isolationlevel="read committed (2)" xactid="14867" currentdb="2" lockTimeout="4294967295" clientoption1="671090784" clientoption2="390200">
<executionStack>
<frame procname="adhoc" line="2" sqlhandle="0x010002002d9fe3155066b380000000000000000000000000">
declare @myPK dbo.IntIntSet; </frame>
</executionStack>
<inputbuf>
declare @myPK dbo.IntIntSet;
</inputbuf>
</process>
</process-list>
<resource-list>
<metadatalock subresource="USER_TYPE" classid="user_type_id = 257" dbid="2" id="lock8009cc00" mode="Sch-M">
<owner-list>
<owner id="process47f948" mode="Sch-M" />
</owner-list>
<waiter-list>
<waiter id="process47f948" mode="Sch-S" requestType="wait" />
</waiter-list>
</metadatalock>
</resource-list>
</deadlock>
</deadlock-list>
在我看来,它像个错误,我建议您为此打开一个连接项。
为了解决您眼前的问题,您可以使用tSQLt.NewConnection
(我假设您正在使用tSQLt)
use tempdb
begin tran
go
EXEC tSQLt.NewConnection '
CREATE TYPE dbo.IntIntSet AS TABLE(
Value0 Int NOT NULL,
Value1 Int NOT NULL
)
';
go
declare @myPK dbo.IntIntSet;
go
rollback
我仍然不知道从何处动态创建表类型的需求来自何处,并且我认为您的测试过于复杂。如果您想讨论给我发电子邮件。