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. SQL Server Identity field

SQL Server Identity field

Scheduled Pinned Locked Moved Database
databasesql-serversysadmintutorial
3 Posts 3 Posters 12 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.
  • K Offline
    K Offline
    Kostas Stefanou
    wrote on last edited by
    #1

    I have a table with a field defined as the primary key and as auto incremented. Does anyone have an idea on how to insert data into the table overriding the auto increment property, so that I can insert my vaalues for this field as well. I want to know if there is a way to do this using ADO and the Open and AddNew methods.:confused: Kostas Stefanou

    A 1 Reply Last reply
    0
    • K Kostas Stefanou

      I have a table with a field defined as the primary key and as auto incremented. Does anyone have an idea on how to insert data into the table overriding the auto increment property, so that I can insert my vaalues for this field as well. I want to know if there is a way to do this using ADO and the Open and AddNew methods.:confused: Kostas Stefanou

      A Offline
      A Offline
      Anders Molin
      wrote on last edited by
      #2

      You can use something like SET IDENTITY_INSERT T1 ON INSERT INTO T1 (column_1,column_2) VALUES (-99,'Explicit identity value') - Anders

      L 1 Reply Last reply
      0
      • A Anders Molin

        You can use something like SET IDENTITY_INSERT T1 ON INSERT INTO T1 (column_1,column_2) VALUES (-99,'Explicit identity value') - Anders

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        At any time, only one table in a session can have the IDENTITY_INSERT property set to ON. If a table already has this property set to ON, and a SET IDENTITY_INSERT ON statement is issued for another table, Microsoft® SQL Server™ returns an error message that states SET IDENTITY_INSERT is already ON and reports the table it is set ON for. If the value inserted is larger than the current identity value for the table, SQL Server automatically uses the new inserted value as the current identity value. The setting of SET IDENTITY_INSERT is set at execute or run time and not at parse time. :|

        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