• ako58 (10/19/2012)


    Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (X64) Apr 2 2010 15:48:46 Copyright (c) Microsoft Corporation Enterprise Edition (64-bit) on Windows NT 6.0 <X64> (Build 6002: Service Pack 2)

    DECLARE @t TABLE (id INT IDENTITY,

    id1 INT CHECK (id>id1))

    Msg 8141, Level 16, State 0, Line 1

    Column CHECK constraint for column 'id1' references another column, table '@t'.

    you need to declare the check constraint separately

    DECLARE @t TABLE (id INT IDENTITY,

    id1 INT, CHECK (id>id1))

    The error you got applies to normal and temporary tables aswell, so it is not a limitation on table variables. the following will also fail with the same error message.

    create TABLE t(id INT IDENTITY,

    id1 INT CHECK (id>id1))

    create TABLE #t(id INT IDENTITY,

    id1 INT CHECK (id>id1))