Identity Column In Table

  • Can any one please point me in the right direction.

    I need some T-Sql that will tell me if a given table contains an identity column

    Thanks

    Edited by - andyd on 12/03/2002 09:04:32 AM

  • Hi, this will give all tables with an identity column: -

    select distinct o.name

    from sysobjects o

    inner join syscolumns c on o.id = c.id

    where

    o.xtype = 'U'

    and c.status = 0x80

    Regards,

    Andy Jones

    .

  • Or if looking at a particular table this is shorter.

    SELECT * FROM syscolumns where [id] = object_id('tbl_paging') and colstat & 1 = 1

    Or the better thing to use is the system sp but you get extra data to.

    sp_help tbl_paging

  • My favorite response for these "how do I" questions is always the same: Look for a system stored procedure that does it, then go take it apart. 99.9% of the time, you iwll be able to find out how to do it and as often as not, you'll learn something else cool too.

    In this case, I'd start with sp_help.

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

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