Re-set recordnum

2 posts by 2 authors in: Forums > CMS Builder
Last Post: October 14, 2011   (RSS)

Re: [steve_e] Re-set recordnum

By Jason - October 14, 2011

Hi Steve,

Yes, there is a way to do this, but it does require you to manually manipulate your database using SQL. This is not recommended unless you are comfortable with SQL, and even then, you should always make a backup of your database before hand.

Also, this process requires multiple SQL queries, and would have to be repeated EVERY time you deleted a record. An alternative would be to use a small text box as a "tutorial_number" you can set the field to be required and to be unique so that you don't end up with duplicates.

If you do want to go ahead with the SQL, here is what you would do. First, get the mySql console plugin here:
http://www.interactivetools.com/add-ons/detail.php?MySQL-Console-1011

Next, after making your backup, we need to update our records to use different num values.

In this example, we're assuming that we have "tutorial 3" and that it has a record num of 4 instead of 3. Here is what the SQL would look like:
Update cms_tutorials SET num = 3 WHERE num = 4;

You need to repeat this process for all records you want to re-number.

After that you need to set what the next record number should be. Assume that your largest record number is 5, so we want to set the next number to be six. We would use this SQL statement:

ALTER TABLE cms_tutorials AUTO_INCREMENT = 6

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/