• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 355
  • Last Modified:

repopulate primary key after linq to sql delete

Hi There experts,
I'm new to linq. I've got a delete function working in my windows form app using c# linq to sql to remove a row from my database. It works fine, I was just wondering if there was an easy way to reorder the primary key of the table the record was deleted from after the delete. by which i mean, currently if i have 3 records and i delete record number 2 then i will be left with a record with an id of 1 and a record with an id of 3. Is there a way to make the id's re-order themselves so in the above scenario when record 2 was deleted record 3 would now have an id of 2?
0
Jazzua
Asked:
Jazzua
1 Solution
 
naspinskiCommented:
This has nothing to do with Linq really, and resides more in SQL.

Since your 'id' is a primary key, it is made automatically, and will *never* increment backwards.  Also, it can not be changes unless you take away the PRIMARY KEY and IDENTITY properties that you assigned to it, change the number, then re-assign those properties to the column - BAD IDEA!

I don't really see the application of this as you could always  programmatically generate the number in the sequence if you needed to.

But, what I would recommend if you *really* think you need this is to make another field as a psuedo-id that is a simple INT and use that one to keep your order.
0
 
JazzuaAuthor Commented:
cheers :)
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now