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. Question about the increment

Question about the increment

Scheduled Pinned Locked Moved Database
question
4 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.
  • E Offline
    E Offline
    Exceter
    wrote on last edited by
    #1

    Hi, Simple question : I have a table and one column is ID (int identity(1,1) not null). Say I have 5 rows: [u]ID Name Color [/u] 1 Bob White 2 Jane Black 3 Lucy Red 4 Gang Brown 5 Dub Yellow If I delete the row 3, the remaining ID's are 1, ,2, 4, 5. Is it possible to make the remaining after the deletion row 3 1, 2, 3, 4? that is the above ID's to decrement. __________________ Best regards, Exceter.

    H A 2 Replies Last reply
    0
    • E Exceter

      Hi, Simple question : I have a table and one column is ID (int identity(1,1) not null). Say I have 5 rows: [u]ID Name Color [/u] 1 Bob White 2 Jane Black 3 Lucy Red 4 Gang Brown 5 Dub Yellow If I delete the row 3, the remaining ID's are 1, ,2, 4, 5. Is it possible to make the remaining after the deletion row 3 1, 2, 3, 4? that is the above ID's to decrement. __________________ Best regards, Exceter.

      H Offline
      H Offline
      Hesham Amin
      wrote on last edited by
      #2

      you can make a delete trigger on this table and update recordes with ID > deletedID

      E 1 Reply Last reply
      0
      • H Hesham Amin

        you can make a delete trigger on this table and update recordes with ID > deletedID

        E Offline
        E Offline
        Exceter
        wrote on last edited by
        #3

        Sir, Sorry for a such question, but I am new in SQL. Could you show how that trigger is written? Respectfully exceter.

        1 Reply Last reply
        0
        • E Exceter

          Hi, Simple question : I have a table and one column is ID (int identity(1,1) not null). Say I have 5 rows: [u]ID Name Color [/u] 1 Bob White 2 Jane Black 3 Lucy Red 4 Gang Brown 5 Dub Yellow If I delete the row 3, the remaining ID's are 1, ,2, 4, 5. Is it possible to make the remaining after the deletion row 3 1, 2, 3, 4? that is the above ID's to decrement. __________________ Best regards, Exceter.

          A Offline
          A Offline
          Arjan Einbu
          wrote on last edited by
          #4

          Why would you want to do this? If your ID column is referenced from somewhere else, you will have to update all those tables too. Let the hole be! Especially if you're using IDENTITY. (It can be done, but will be some work, as you first will have to temporarily SET IDENTITY INSERT ON for your table. Insert row 4 in row 3's place, delete row4, insert row 5 in row 4's place. (Which you offcourse will do in a loop.)) If you really really need this functionality, it is better NOT to use the IDENTITY column, since that will allow you to use an UPDATE statement instead. (Possibly in a trigger or a stored proc...)

          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