I would like to enable users of my application to define a number of (say) email addresses. Then I would like to give them the ability to rearrange these addresses, so the primary address is on top, secondary next, etc.
Let’s suppose I have a UserEmailAddresses table in a database that links a user (UserId) and an email address (EmailAddressId).
1) What data type (int, float, etc) should I use for the field that will hold the sequence in which these email addresses will be sorted by?
2) What query would be efficient at changing these sequence numbers when the user rearranges their positions? Must it modify multiple records?
(I’m using C# and Linq, but psuedo-code welcome).
You will need to add an integer field that stores the sort order of the email addresses.
As new email addresses are added they get assigned the next sort order id. If an address needs to be sorted above an existing address I would use an update statement to update all email addresses with sort order ids greater than the desired sort order index then update the reordered email address to have the desired sort order index.