vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Updating Primary auto increment table. (https://vborg.vbsupport.ru/showthread.php?t=75881)

Jolten 02-07-2005 04:34 AM

Updating Primary auto increment table.
 
How can I reset an autoincrement database table to rebuild it's numbers?

Here's the scenario: I have a database table with 118 rows. Due to testing the first 82 rows are gone. So I want to reset the autoincrement field for all rows - 82 so row 83 is numbered 1, 84 = 2, 85 = 3 and so on.

I tried UPDATE autoincrement SET autoincrement = (autoincrement - 82) but that doesn't seem to work. I'm guessing maybe because the autoincrement field is the primary key for the database.

I know I could change these all manually... but can't it be done with one simple query?

Thanks

Zachery 02-07-2005 10:47 AM

Quote:

Originally Posted by Jolten
How can I reset an autoincrement database table to rebuild it's numbers?

Here's the scenario: I have a database table with 118 rows. Due to testing the first 82 rows are gone. So I want to reset the autoincrement field for all rows - 82 so row 83 is numbered 1, 84 = 2, 85 = 3 and so on.

I tried UPDATE autoincrement SET autoincrement = (autoincrement - 82) but that doesn't seem to work. I'm guessing maybe because the autoincrement field is the primary key for the database.

I know I could change these all manually... but can't it be done with one simple query?

Thanks

I don't think it can be done (or at least thats what I have been lead to believe)

As far as i know, you would need to drop the table make it again, then reimport your data and make sure the data was imported with the proper id's and not their old numbers ect.

Dean C 02-07-2005 11:43 AM

You could take away the auto_increment. Go and change all the values and then change it back?

Jolten 02-07-2005 01:48 PM

Thanks guys. I'm discovering the same thing. they can be edited manually but a query won't function.

miz 02-07-2005 02:03 PM

here a way

hmm you can a temp table with auto increment and just
read from old and inset into new 1
then delete old table and recreat it and do the progrees again

way 2 :
PHP Code:

$bla select from table name;
$i=0;
while (
$bla2 $DB_site->fetch_array($bla))
{
i++;
$DB_site->query("Upade table Set id='$i' ");


shoudl work
way 2 is better.

Jolten 02-07-2005 02:06 PM

Thanks miz.. I'll try that.


All times are GMT. The time now is 02:01 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.00970 seconds
  • Memory Usage 1,725KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (6)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete