0

I start build my first local database (Service-Based Database) here Write line to Service-Based Database with textbox, need your help with setup, so I want to set my auto increment in my Properties Identity Specification which is True now, or use some sorting method, thus if any row is removed, second one (next after deleted) must take index of deleted line, and of course same step back for all subsequent rows, and also important, if I have to use any sorting, to keep original order of lines as it was inserted.

For example:

  1. line 1
  2. line 2
  3. line 3
  4. line 4

If line2 is deleted this result:

  1. line 1
  2. line 3
  3. line 4

If all lines deleted, and then inserted new index becomes 1. new first line and not 5. new first line as it now.

Community
  • 1
  • 1
  • 2
    I would advise against this in real word applications. The numbers are your unique key and should be maintained. I have a test db where the auto int key is up to 20000 but the table has maybe 3 bits of data due to me just blasting way records. – Dheebs Aug 25 '16 at 22:51
  • I guess you could use triggers for this, but depending on the load on your db, it could be very bad for performance. Also, altering an auto-increment identity field seems odd. Why not create a new column which is not auto-increment/identity, and if you want your table to be sorted physically by this column, you may add a clustered index on the column. Using a regular index and then doing the sorting in your query will also work. – Svein Terje Gaup Aug 26 '16 at 06:04

0 Answers0