Part of the basic idea of relational databases in general, is that records don't have an "inherent" order in the database itself1.
Ordering is normally imposed on the result of a query. In this case, we can decide on what column(s) specify the order in which we want items displayed, and order the result accordingly.
For example, we might want to be able to produce reports of orders by either the date/time of each order (i.e., display them in the order in which they were placed):
select ID, value, date /* , ... */ from Orders
order by ship_date
... or the date/time the order was shipped,
select ID, value, date /* , ... */ from Orders
order by ship_date
... or perhaps descending order by size (so we can quickly see the biggest orders, regardless of when they happened).
select ID, value, date /* , ... */ from Orders
order by value desc
You can, of course, add an order_by
column (by another name if you prefer) when/if you really want the orders to be displayed in an order that's entirely arbitrary (or at least based on criteria that aren't stored in the database). In this case, when want to reorder, you have a couple of choices. One is to simply not tell the database that this column contains unique values. Another is to simply avoid duplication. For your example, you started with records numbered 1 and 2. To reverse them, you can change the numbers to 4 and 3 respectively.
To carry this out programmatically, you find the largest value currently in the column2, then use one greater than that as the base value when reordered. You might also want to check the minimum value currently in use. If it's greater than the number of records, you can re-start numbering from 0.
1. Though MS SQL does have a concept of a "clustered index", which directly relates to the order in which records are stored--this is basically an optimization though.
2. You'll typically index this column, so this operation we can expect this operation to be quite fast.