Table Variable with Identity Column

  • Is there a way to reset the Identity value of a cloumn in a table variable ? DBCC CHECKIDENT gives an error. Or know the last identity value.

    TIA.

     

  • check books online

    DBCC CHECKIDENT ('table_name', NORESEED)  just for reporting

    or

    DBCC CHECKIDENT ('table_name', RESEED) reporting and correction !

     

    What error is checkident giving ?

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • SET NOCOUNT ON

    DECLARE @tbl TABLE (RowID INT IDENTITY, descr varchar(10) )

    insert into @tbl

    SELECT 'a'

    UNION

    select 'b'

    UNION

    select 'c'

    UNION

    select 'd'

    UNION

    select 'e'

    SELECT * FROM @tbl

    DBCC CHECKIDENT('@tbl',NORESEED)

    Error : Could not find a table or object named '@tbl'. Check sysobjects.

  • DBCC CHECKIDENT doesn't work with a table variable.  This works fine:

    SET NOCOUNT ON

    Create TABLE #tbl (RowID INT IDENTITY, descr varchar(10) )

    insert into #tbl

    SELECT 'a'

    UNION

    select 'b'

    UNION

    select 'c'

    UNION

    select 'd'

    UNION

    select 'e'

    SELECT * FROM #tbl

    DBCC CHECKIDENT('#tbl',NORESEED)

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply