DBCC CLONEDATABASE's cloned database triggers stack dump when User-Defined Table Type containing Primary Key is referenced
Stack dump consistently triggered when table type has primary key. If the table type does not have primary key the query returns normally.
drop database test
if dbid('testclone') is not null
alter database testclone set offline with rollback immediate
drop database testclone
SELECT @@version -- Microsoft SQL Server 2014 (SP2-CU12) (KB4130489) - 12.0.5589.7 (X64) Jun 9 2018 11:17:15 Copyright (c) Microsoft Corporation Developer Edition (64-bit) on Windows NT 6.3 <X64> (Build 9600: ) (Hypervisor)
CREATE DATABASE test;
CREATE TYPE dbo.tabletype AS TABLE
id INT IDENTITY
PRIMARY KEY (ID)
DBCC clonedatabase(test, test_clone);
DECLARE @x dbo.TABLETYPE; -- runs sucessfully
DECLARE @x dbo.TABLETYPE; -- stack dump-o-rama
--Msg 596, Level 21, State 1, Line 50
--Cannot continue the execution because the session is in the kill state.
--Msg 0, Level 20, State 0, Line 50
--A severe error occurred on the current com
mand. The results, if any, should be discarded.
Access Violation occurred reading address 000000000000000C
Exception Code = c0000005 EXCEPTIONACCESSVIOLATION
Exception Address = 00007FFB3AAF8E65 Module(sqllang+0000000000408E65)
A user request from the session with SPID 289 generated a fatal exception. SQL Server is terminating this session. Contact Product Support Services with the dump produced in the log directory.
Julie Mason commented
This issue is still occurring with user-defined table types. Not only does it cause stack dumps, it takes your availability group offline when it happens.
Any update on this bug?
Dan Carollo commented
Which version of SQL? I haven't seen this error in SQL 2016, SP1 and higher. (I don't currently have a lower instance to test on)
Dan Carollo commented
You will get the SAME error if you create a user-defined table type with a DEFAULT constraint...
1. Original database, create table type with default...
CREATE TYPE typeWithDefault AS TABLE (
a INT NOT NULL,
b INT DEFAULT 0
dbcc clonedatabase ('Test','Test_Clone') WITH VERIFY_CLONEDB
-- Use the Default
declare @a typeWithDefault
insert into @a (a) values (1)
select * from @a;
--ERROR: Msg 0, Level 11, State 0, Line 24
-- A severe error occurred on the current command. The results, if any, should be discarded.