0

What if I want to insert data inbetween the row 5 and 6

same as the question

3rd May 2017, 6:00 PM
Azhagiri Narayanan
Azhagiri Narayanan - avatar
3 Answers
+ 3
If you meen only PK - you must drop primary key, and do this field as all other, not key. Update values for all row, where pk was > 5, +5.Insert yours new row, with this field value 5, 6. And do this field PK again.
3rd May 2017, 7:50 PM
shaldem
shaldem - avatar
+ 2
It can be done, but is very discouraged. Changing primary keys of entries could affect not only your table but the whole database. Querying such an altered db could suddenly bring unexpected relations. Jeth is right - SQL gives you so many ways of handling the data that the only thing you have to provide on your own is its consistency and at least one unique key per table. Ordering of the data should not be the matter of storage, but of displaying view.
3rd May 2017, 7:00 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
0
You mean you have int primary key column with values 5 and 6 and you want to insert something between? You can't. You must reassign keys for all rows manually then or delete a row and insert a new one instead of it, assigning same id in process. Why you would want to do this at all? SQL give you enough instruments to filter and sort data, you do not have to worry about manual arrangement of data in table if your database configured properly.
3rd May 2017, 6:29 PM
Jeth
Jeth - avatar