SQL Column Values

I recently imported excel arch into sql database. Imported values ​​are as follows:

name     age   adress       date
carl     12    something    2015-11-10
lisa     51    something2   2+15-10-09
steven   32    something3   2014-12-29

Then I added an auto-increment column called id, resulting in:

id    name    age   adress       date
1     carl    12    something    2015-11-10
2     lisa    51    something2   2+15-10-09
3     steven  32    something3   2014-12-29

My problem is that I need to change identifiers. Because if I now need to insert a new row, this will cause the date column to not match the id column. It will look like this:

id    name    age   adress       date
1     carl    12    something    2015-11-10
2     lisa    51    something2   2015-10-09
3     steven  32    something3   2014-12-29
4     neil    25    something4   2016-01-12

I was looking for methods to create a new id column, the reverse. Or modify an existing column. The problem is that I did not succeed.

+4
source share
1 answer

Create a new empty table with autoincremt and insert the rows in reverse order

INSERT into new_table
 select '',name,age address,`date`
  FROM org_table
  ORDER BY id DESC;
+2
source

Source: https://habr.com/ru/post/1623867/


All Articles