I have a table structure
id | col1 | col2 1 | 1 | val1 2 | 2 | val2 3 | 3 | val3 -- 4 | 4 | val4 5 | 5 | val1 6 | 6 | val6
I want to perform a delete action to delete one of the row(say id=3) so my data will become like:
id | col1 | col2 1 | 1 | val1 2 | 2 | val2 4 | 4 | val4 5 | 5 | val1 6 | 6 | val6
But I want it to be like
id | col1 | col2 1 | 1 | val1 2 | 2 | val2 4 | 3 | val4 5 | 4 | val1 6 | 5 | val6
I want my col1 to be always in sequence irrespective of other columns. Any suggestions on how to go about it. Can it be done in one update query only. I am using POSTGRESQL as my database and using C# for coding. I have around 1000 of rows in the database. Please help me out here.
update table set col1 = col1 - 1 where col1 > @col1_value_deletedshould work.col1? If you don't, consider using a view (or simple query) that calculates the continuous sequence of values forcol1on-the-fly.