'PK on temp table failing

I have a trigger which declares a table variable.

DECLARE @TREarn_aaa table
  (
    aaaID bigint NOT NULL PRIMARY KEY,
    Bbb decimal (18, 8) NULL,
    Ccc decimal (18, 8) NULL,
    Ddd decimal (18, 8) NULL,
    Eee decimal (18, 8) NULL
  );

On a rare occurrence, My table variable creation failed with following error -

System.data.sqlclient.sqlexception (0x80131904): the CURRENT TRANSACTION cannot be committed
AND
cannot support operations that write TO the log FILE. roll back the TRANSACTION. the CURRENT TRANSACTION cannot be committed
AND
cannot support operations that write TO the log FILE. roll back the TRANSACTION. **there IS already an object named** 'PK__#TREarn___70C9A75541DA7FD5' IN the DATABASE. could NOT CREATE CONSTRAINT

It failed as this name was already in use. Considering this is a table variable without naming PK, it should not happen.

Is it something like a known issue or I am missing something?

EDIT -

After @larnu comment I found a temporary table hidden in flow

CREATE TABLE #TREarn_aaa(aaaID bigint NOT NULL PRIMARY KEY,...);

However, the question still remains the same in context of temp table. Why did I get duplicate name? Is it an accident and can it be written off?

Unfortunately, I can't get version info as this came on customer DB on which I do not have access.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source