0

How can I tidy up an auto increment field in a table from within a module, so that a table like this (the 'id' field being auto incrementing):

id title
1  foo
3  bar
7  fee

becomes:

id title
1  foo
2  bar
3  fee

Is there a function, like serial_field_tidy or something?

1

You should never do that since the IDs are important for addressing to that specific row in other tables. You would never know which modules are also indexed this row with its id. So if you change the ID of a row, you will encounter unexpected things in your installation.

|improve this answer|||||
  • Okay, thanks, as a general rule, but this table is from my own schema and I know it is not used by any other modules so it wouldn't cause a problem. – dbj44 Oct 8 '13 at 20:27
  • 1
    I mean no offence, but if the design of your app relies in some way on sequential identifiers in a database table, there's something not quite right. A function like serial_field_tidy doesn't exist because it's considered bad practice to attempt to do what you're trying to do. The logic isn't terribly difficult (you could probably do it in a single SQL statement), but I'd recommend examining the requirement that's led you to this conclusion before you go ahead with it – Clive Oct 8 '13 at 21:35
  • No offence taken, it's a fair point. – dbj44 Oct 8 '13 at 22:05
0

There's another option more easy, with views you can show a field with global usage (I'm not sure the name of this option) and print his row number or his row number plus 1st ID

But like other people told you, avoid change IDs

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.