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. General Programming
  3. C#
  4. solution for primary key

solution for primary key

Scheduled Pinned Locked Moved C#
helptutorialquestion
3 Posts 3 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.
  • S Offline
    S Offline
    sajid salim khan
    wrote on last edited by
    #1

    The problem is that i have a primary key whose dbtype is Bigint i dont want to keep auto to generate the primary key in sql2000 table by code and return that value. Then when entering next record increment must be made to the previous number and inserted as a primary key next question is if i delete any resord then how to sort the primary keys in ascending order sas

    E M 2 Replies Last reply
    0
    • S sajid salim khan

      The problem is that i have a primary key whose dbtype is Bigint i dont want to keep auto to generate the primary key in sql2000 table by code and return that value. Then when entering next record increment must be made to the previous number and inserted as a primary key next question is if i delete any resord then how to sort the primary keys in ascending order sas

      E Offline
      E Offline
      Ennis Ray Lynch Jr
      wrote on last edited by
      #2

      @@Identity will give you the last identity from an insert statement. and SCOPE_Idendity() will give you the last value in an insert in your current scope. Primary Keys are stored by the database in ascending order, usually, so they will always be sorted. I think what you be asking is for sequential primary keys by changing the identity_seed on a deletion. This is possible with the undocumented SQL 2000 system stored procedures but it is not recommended by MS.

      Need a C# Consultant? I'm available.
      Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway

      1 Reply Last reply
      0
      • S sajid salim khan

        The problem is that i have a primary key whose dbtype is Bigint i dont want to keep auto to generate the primary key in sql2000 table by code and return that value. Then when entering next record increment must be made to the previous number and inserted as a primary key next question is if i delete any resord then how to sort the primary keys in ascending order sas

        M Offline
        M Offline
        Mark Churchill
        wrote on last edited by
        #3

        You should create another column to satisfy your requirements of a contiguous numbering system. A primary key identifies the record and shouldn't change. I wouldn't want to be dealing with Customer#1234 and then send an update to the database, but it turns out my Customer is now #1233 because someone deleted a record while. Customer#1234 (who is now Customer#1233) would be especially annoyed when his shipment of goods gets sent to the old Customer#1235, who is now Customer#1234. Wow. You can see what I'm getting at already!

        Mark Churchill Director Dunn & Churchill Diamond Binding: Zero to Data Layer in 3 mins

        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