Welcome, Guest. Please login or register.
Did you miss your activation email?
05/23/12, 01:08
Home Help Search Login Register
News: Parsley Flex framework review featuring quiz application, in our Flex frameworks series
Flex SDK 4.5 mobile roadmap: begin with your mobile development
Swiz Flex framework review featuring quiz application
New homepage we release our new Homepage, take a look ...

+  Flash-db
|-+  Server side Scripting and Database Support
| |-+  MySQL, PostgreSQL, MS SQL, Access (Moderators: Flash-db, Musicman, Ronald Wernecke, Jorge Solis, Andries Seutens)
| | |-+  about auto_increment the primary key
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Print
Author Topic: about auto_increment the primary key  (Read 3158 times)
DEAMOTHUL the script keeper
Jr. Programmer
**
Posts: 52


A Flash PHP etc Resource

erwin@primevector.nl
View Profile WWW Email
« on: 07/26/03, 12:44 »

hi, when i have a database, like this:

personID               INTEGER AUTO_INCREMENT PRIMARY KEY    
personName          VARCHAR(50)
personLastName   VARCHAR(50)

suppose i put in 8 persons into this database, then after inserting those 8 persons suppose  i would delete them all again.
When i then start to add new persons again, the personID starts at 8 , but i want it to start at 1 again.

Can somebody tell me what i have to do to reset the auto_increment id  back to its begin point
So lets say i deleted 3 of the persons, the id would be set to 5, and so on.

thanks,

Logged

Flash-db
Administrator
Systems Administrator
*****
Posts: 1867



View Profile WWW
« Reply #1 on: 07/26/03, 13:48 »

Not sure if this would be the best way - I'm sure there's a better solution out there.  But I think you can do something like:

CREATE TABLE sometable (tablecolumnName INT NOT NULL AUTO_INCREMENT PRIMARY KEY) AUTO_INCREMENT = someNumber

You can manually set  AUTO_INCREMENT = someNumber, but I'm not sure if this will be useful in your case?



- also for some reason I thought that auto increment started at the last number in the column before.  so say the auto incremented value of the last row was 5.  I thought it would then start with 6, but it sounds like that's not the case?

Logged

-Jeff.
Ronald Wernecke
Administrator
Systems Administrator
*****
Posts: 6175


View Profile WWW Email
« Reply #2 on: 07/27/03, 06:54 »

The Autoincrementnumber for a column is held in a system table and allways incrementing.
This actualy makes sense, 'cause when a table lives, it usualy mekse no sense to delete all and start again. Usualy you have something in the middle deleted and something new generated.
These autoincrement values are allways long integers, so it is rather impossible that thes values are running out of range for the lifetime of an application.

Renumbering makes non sense, 'cause you usualy use these keys (you can depend on it, that they are unique), are used as foreign keys. Thats actualy the reason for using them.

I beleive there is something like a reset function, but dont know for sure now.
Logged

happy flashing
Cool
Ronald
DEAMOTHUL the script keeper
Jr. Programmer
**
Posts: 52


A Flash PHP etc Resource

erwin@primevector.nl
View Profile WWW Email
« Reply #3 on: 07/27/03, 07:01 »

hi people, i hope there is a way to do it, cause else things will be pretty messed up Wink

i hope there is someone out there that knows how to do it, im sure somebody else has had this problem before.

but thanks 4 the help , greatly appreciated

greetz
Logged

Musicman
Administrator
Systems Administrator
*****
Posts: 2685



View Profile WWW Email
« Reply #4 on: 07/27/03, 11:36 »

Hi,

dont mess with the autoincrement numers .... if you really want all current entries listed as 1, 2, 3 just add those numbers to your listing (and keep the autoincrement ones for any links because they will not change; you would not like somebody to bookmark a page about person #3 and then come back to find out that person #3 is former person #7 Smiley

Musicman
Logged
DEAMOTHUL the script keeper
Jr. Programmer
**
Posts: 52


A Flash PHP etc Resource

erwin@primevector.nl
View Profile WWW Email
« Reply #5 on: 07/27/03, 11:38 »

hi musicman, but when something is deleted from the database the id is messed up.
what can i do about that?

greetz,
Logged

Musicman
Administrator
Systems Administrator
*****
Posts: 2685



View Profile WWW Email
« Reply #6 on: 07/27/03, 11:46 »

Hi,

the id is not messed up, it is just unused (and will never be used again). So in the case of the bookmark, the script should just say: person xxx  left the database

Musicman
Logged
DEAMOTHUL the script keeper
Jr. Programmer
**
Posts: 52


A Flash PHP etc Resource

erwin@primevector.nl
View Profile WWW Email
« Reply #7 on: 07/27/03, 11:48 »

thanks musicman,
so its best not to use the id field in  an ORDER BY method?

greetz,
Logged

Ronald Wernecke
Administrator
Systems Administrator
*****
Posts: 6175


View Profile WWW Email
« Reply #8 on: 07/27/03, 12:13 »

Hi,
this autonumber function delivers you a save method of unique key values for to be used as foreign keys.
So, if you use them right, you mess up relations, if you change them.
Still the order of the keys is the order of how the records have been entered into the database. There are only "holes" in it, which show the deleted records.

If you want another order, you have to create your own field for it.

But if you only want ascending numbering of the current list, you can produce it in the script like line numbers.

I personaly don't see any sense in it, but erverybody as he likes Grin

And if you only have a single table without any relations, you may omit such a field Wink

Logged

happy flashing
Cool
Ronald
DEAMOTHUL the script keeper
Jr. Programmer
**
Posts: 52


A Flash PHP etc Resource

erwin@primevector.nl
View Profile WWW Email
« Reply #9 on: 07/27/03, 12:17 »

Ok thanks,
Logged

Pages: [1] Print 
« previous next »
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!