Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Primary Key begins at 5180 and not '1' - why ???

Status
Not open for further replies.

c0deM0nK424

Programmer
Oct 28, 2007
126
GB
Hi lol, i just populated a table for a database in phpmyadmin - and the table is called 'games_list'.


well, basically i populated it but the primary key begins from 5010 or something odd like that and finishes on 7000 something lol.


so, i guess what im asking for here is - why is it happening ?

i set GAME_ID a field in a table called GAMES_LIST , as PRIMARY KEY and auto-increment.


so whys this happening ?


i want it to begin with 1 and end with 2175 , as there are 2175 games in total.

any help would be greatly appreciated.

sincerest regards

CodeMonk
 
The question would be how did you populate the table?

By default the autoincrement starts at 0 unless you did something to it, or your data source such as a file had the primary keys as those values, or used some base for them that starts at that value.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
its okay i managed to get it starting from 1 all the way to the last record 2175.


phpmyadmin is 'fiddly' imo.


that, or i'm just not well versed on stuff heh


having said that - i opened a CSV file where the seperator thing was a /n not a ' , '

and all my values are appearing nicely.


now i need 'grab at these' values accordingly to the links on this page of my site.

manoj-kumar.co.uk/games
 
A primary key is not "just a unique number". It is good to see it as an address. In any case, it should never have a meaning as data. Never. Like, your address in real life should also not depend on your hair colour or even change when you paint your hair. Can you imagine the mess when everybody who knows you should update their address books when you change hair colour?

It is the same with databases. A primary key should be the identity of the column, regardless of its contents. So deleting a record and inserting one is just that. You did not change the record, you replaced it with another one. Therefore, (autonumber) primary keys are not reused.

You can reset them (using an ALTER TABLE statement for example), but you have to know what you are doing: if there are still any unenforced references to the records you delete, they will "magically" appear when you create new records with the same primary key.

In effect, a primary key should be unique during the lifetime of the system.


+++ Despite being wrong in every important aspect, that is a very good analogy +++
Hex (in Darwin's Watch)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top