Search

sys.default_constraints empty for temporary tables in tempdb by siggemannen

Closed
as Fixed Help for as Fixed

8
0
Sign in
to vote
Type: Bug
ID: 765777
Opened: 10/2/2012 11:56:30 AM
Access Restriction: Public
0
Workaround(s)
3
User(s) can reproduce this bug
In SQL Server 2012, If i create a temporary table with a column default, it isn't reflected in sys.default_constraints table anymore.

This is because sys.default_constraints View works with object_id > 0 but all temporary tables have object_id < 0 in SQL Server 2012.

Perhaps a fix of view definition could be:

CREATE VIEW sys.default_constraints AS
    SELECT name, object_id, principal_id, schema_id, parent_object_id,
        type, type_desc, create_date, modify_date,
        is_ms_shipped, is_published, is_schema_published,
        property AS parent_column_id,
        object_definition(object_id) AS definition,
        is_system_named
    FROM sys.objects$
    WHERE type = 'D ' AND parent_object_id <> 0
Details (expand)

Product Language

English

Version

SQL Server 2012 - Developer Edition

Category

SQL Engine

Operating System

Windows 7 (all editions)

Operating System Language

US English

Steps to Reproduce

Run following script:

IF OBJECT_ID('tempdb..#t_test') is not null
    DROP TABLE #t_test
GO
CREATE TABLE #t_test (i INT NOT NULL DEFAULT 1, z INT)

SELECT    COUNT(*)
FROM    tempdb.sys.default_constraints
WHERE    parent_object_id= OBJECT_ID('tempdb..#t_test')

Actual Results

-----------
0

(1 row(s) affected)

Expected Results

-----------
1

(1 row(s) affected)

Platform

X64

Virtualization

Hyper-V (On-Premise)
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 2/26/2013 at 7:15 PM
Hi, Thank you for your feedback. We have investigated the issue and the fix will be available in the next release of SQL Server. Thanks & Regards, Pooja Harjani - Program Manager - SQL Server
Sign in to post a workaround.