Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. How to know if a column of type int is Identity using ADO.NET GetSchema()?

How to know if a column of type int is Identity using ADO.NET GetSchema()?

Scheduled Pinned Locked Moved Database
csharpdatabasesql-serversysadmintutorial
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    adgonz
    wrote on last edited by
    #1

    I can't figure it using the data GetSchema() returns. Is there something I don't see? Is there any other way? Thanks! Edit: I'm using SQL Server 2008 and SQLConnection

    D 1 Reply Last reply
    0
    • A adgonz

      I can't figure it using the data GetSchema() returns. Is there something I don't see? Is there any other way? Thanks! Edit: I'm using SQL Server 2008 and SQLConnection

      D Offline
      D Offline
      David Mujica
      wrote on last edited by
      #2

      try linking the sysobjects table to the syscolumns table and find the datatype in the syscolumns table. I'll try to come up with the query later.

      D 1 Reply Last reply
      0
      • D David Mujica

        try linking the sysobjects table to the syscolumns table and find the datatype in the syscolumns table. I'll try to come up with the query later.

        D Offline
        D Offline
        David Mujica
        wrote on last edited by
        #3

        Here is some code I found ... Set the @tblName variable to the name of the table you are trying to find the Identity column and you will get the result. Happy Coding :cool: declare @TblName sysname set @tblName = 'Your table name' -- show identity col name select syscolumns.name from sysobjects inner join syscolumns on sysobjects.id = syscolumns.id where sysobjects.name = @tblName and syscolumns.status = 0x80 -- show identity constraint name select sysobjconstraint.name from sysobjects inner join sysconstraints on sysobjects.id = sysconstraints.id left outer join sysobjects sysobjconstraint on sysconstraints.constid = sysobjconstraint.id where sysobjects.name = @tblName and sysobjconstraint.xtype = 'PK'

        A 1 Reply Last reply
        0
        • D David Mujica

          Here is some code I found ... Set the @tblName variable to the name of the table you are trying to find the Identity column and you will get the result. Happy Coding :cool: declare @TblName sysname set @tblName = 'Your table name' -- show identity col name select syscolumns.name from sysobjects inner join syscolumns on sysobjects.id = syscolumns.id where sysobjects.name = @tblName and syscolumns.status = 0x80 -- show identity constraint name select sysobjconstraint.name from sysobjects inner join sysconstraints on sysobjects.id = sysconstraints.id left outer join sysobjects sysobjconstraint on sysconstraints.constid = sysobjconstraint.id where sysobjects.name = @tblName and sysobjconstraint.xtype = 'PK'

          A Offline
          A Offline
          adgonz
          wrote on last edited by
          #4

          Thanks! I have just found another way: select COLUMNPROPERTY(OBJECT_ID('Table name'), COLUMN_NAME, 'IsIdentity') as IS_IDENTITY from INFORMATION_SCHEMA.COLUMNS I'd prefer to use GetSchema(), but for now I'm using this.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups