Eggie
Jan 20 2008, 09:24 AM
| | i am creating a game and i set when someone registers than he gets id...in "extra" i have set it to be "auto_increment" but whenever new player signs up he gets number bigger than 210...(my first id was 211,next was 212,third was 213,fourth got 214) how to set it to go from 1 to infinite? thnx |
Reply
turbopowerdmaxsteel
Jan 20 2008, 10:16 AM
You must have manually inserted the 211 ID. If you can afford to empty the table and re-enter the values the problem can be solved. In your insert query, leave the value for the AUTO_INCREMENT field to blank. For example, say you have a table with two fields ID (the auto number) and name (a varchar). Use the following query to insert a record with IDs starting from 1. CODE INSERT INTO MyTable VALUES('', "Partho") You can set the initial number to a greater number but you can't get it back down (or so I think) unless you empty/re-create the table. Use the following query to start the numbers from 200. CODE INSERT INTO MyTable VALUES('200', "Partho") From the next time, you can just use the previous query to continue with numbers 201, 202 and so on.
Reply
faulty.lee
Jan 20 2008, 11:14 AM
If you had inserted some record before, and deleted them, the auto increment number will still remain from the last one that you inserted, e.g. 210 in this case, so the next data you insert will start from 211. For this you need to reset the auto_increment counter. Assuming you're using MySQL CODE ALTER TABLE your_table AUTO_INCREMENT = 0 Then your next inserted data will start with 0, then 1, 2, 3 ..... Hope that's what you're looking for Good Luck PS: For your information, the auto_increment is made to remain as last even though you've deleted your record, for the purpose of data integrity. It was done so that even you've deleted your old record, anything that refers to that ID won't accidentally belongs to another row of data. For example, you have your first row with ID=1, and another table that refer to this ID. That 2nd table referring to ID 1, and contain a bad comment for it. Later you deleted that row from the first table, and reset the auto_increment to 1, and insert another data. This time the new row, also has an ID=1, but the bad comment is automatically referred to it although it wasn't your intention to do so. You might not see the problem, maybe for now, but when you database grow bigger and bigger, it will get worse, and very hard to debug.
Reply
Eggie
Jan 20 2008, 11:27 AM
CODE ALTER TABLE table_name AUTO_INCREMENT = 1; that is what i need but thanks anyway that sets your auto_increment value to 1!
Reply
Eggie
Jan 20 2008, 11:29 AM
faulty.lee... i didn't even see your post...after i saw turbopowerdmaxsteel's post i leaved it here on the post and haven't refreshed...and i posted it thanx anyways
Reply
faulty.lee
Jan 20 2008, 12:40 PM
It's OK. In fact I would be happy if you can figure it out yourself. That shows your enthusiasm on what you wanted to do.
Reply
Eggie
Jan 20 2008, 12:51 PM
QUOTE(faulty.lee @ Jan 20 2008, 01:40 PM)  It's OK. In fact I would be happy if you can figure it out yourself. That shows your enthusiasm on what you wanted to do. well..i didnt figure it out myself...i googled it ..thats how i figured it
Reply
sparkx
Jan 20 2008, 03:32 PM
The fact that you even Googled it puts you in front of about half the programmer wanabies on this forum as it is. On my website I do the following to increment things: -Run While. If a constant added variable is equal to the ID it repeats the while. If failed found first "skipped" number. -If no skipped number + 1 to the last number. -Double Check if number exists (useless unless two entries and being inserted at the exact same time). -Insert entry. You probably wont understand what I just said until you get better at programming, but that’s how I check. I don't know if the code you found included skipped number or not but that is always nice to have unless you want deleted ID's to stay deleted. I made up this method and am not exactly sure how secure it is but it may be a good idea to do if you really get serious about your game. Good Luck, Sparkx
Reply
Eggie
Jan 20 2008, 03:37 PM
good code but i dont want that a guy who registers 210th get id 2 so that code is better in my case
Reply
TavoxPeru
Jan 21 2008, 05:18 AM
Another way to reset your auto increment id field is by truncate the table so the ID of your first new inserted record will get as Id the value 1, TRUNCATE TABLE is a data manipulation statement that empties completely a table and also resets any auto_increment counter of the table, sounds like this is similar to perform a DELETE FROM TABLE statement, but it is not absolutely true, because it depends on the version of your database, also, if you perform the DELETE statement this will not reset the auto_increment counter of the table, so, if you insert a record to your table after this the auto_increment counter will be setting up with the next value. But be carefull with this method, if you have data on your table and you want to preserve it, well, what i generally do in this case is to first delete the primary index of the table, then i delete the auto_increment field, after that i generate an sql file of the table by exporting it, then i proceed to delete the table and finally i import the generated sql file. Sounds like there are too much tasks to perform a simple task like this, well, if you use MySql and phpMyAdmin it is very easy and simple, you simply go to the export tab of your table, select the options you need and press a button. There are a lot of options that you can select here, for this case the options i select are: - Export: Sql.
- Structure: Add DROP TABLE, Add IF NOT EXISTS, Enclose table and field names with backquotes.
- DATA: Complete inserts, Extended inserts.
- Export type: INSERT
- Save as file: This is optional because it depends on the size of the table, if the table have few records -less than 100- i do not use it.
Then, phpMyAdmin proceeds to generate the sql code, if i dont use the last option, it shows up the code on a textarea field, where i simply select all the generated sql code and copy it to the clipboard, or, in the other case, save the file to disk. After that, if i use the Save as file option i go to the Import tab, open the FILE input control, browse my disk and select the just generated sql file, finally press the GO button. In the other case, i only need to go to the SQL tab of the table, and simply paste the just generated sql code inside the textarea field and finaly press the GO button. Best regards,
Reply
Recent Queries:--
hsqldb autoincrement query - 147.68 hr back. (1)
-
auto_increment derby - 211.70 hr back. (1)
-
derby auto_increment - 338.35 hr back. (1)
Similar Topics
Keywords : database, auto, increment
- Some Useful Database Links.
(7)
Database Access On Remote Server W/jsp
(0) Hello: I am new to JAVA and server-side applications and have a dumb question. I have set up
Tomcat on my machine and created a JSP program to query an Access database using a DSN-Less
connection. If I publish the page to a webserver and include the .MDB file will it work? I'm
not sure exactly what needs to be packaged with my Java application to make it work. Since I
don't have a remote server that supports .jsp I cannot really test it. I'm assuming that
JDBC driver would be bundled with my site but not sure. Thanks!....
Space Needed For Database
(10) Iam assuming the information in the databases i will create will be stored in the 500 MB space i
get, but since 500MB isn't enough iam wondering if you guys can tell me how much bytes the
following take: Varchar(x),Tinyint,Text,date,smallint,mediumint,bigint,float.... And the rest
present when you add/edit a row in a table. Also what are the ranges of tinyint,smallint,mediumint
and big int....
Mysql Database Entry By Excel Sheets
(2) Hello .. I would like to ask if i can use use Microsoft excel files in order to make entries to
mysql database. Thanks....
Mysql Database Management
(1) Hi i am new, I have a problem in understanding the query decomposition in D-DB. Can anyone help me
to understand the first question of the exercise 25.21 of Elmasri-Navath 4th edition? Consider the
following relations: BOOKS (Book#, Primary_author, Topic, Total_stock, $price) BOOKSTORE
(Store#, City, State, Zip, Inventory_value) STOCK (Store#, Book#, Qty) Consider a distributed
database for a bookstore chain called National Books with 3 sites called EAST, MIDDLE, and WEST.
Consider that BOOKS are fragmented by $price amounts into: B1:BOOK1:up to $20.....
Accessing Ms Access Database From A Centralized Location?
(5) Hi I am a manager at a trading/wholesaling company (and have no programming background). I
customized the Northwind sample access database to make invoices and keep accounts for my company.
We now opening another office at a distant location. So, the order entry will be done at two
points(we plan to use the same Access database). I am not able to figure out how to access the same
MS Access database from two different location(as LAN can't be used). Moreover, we can't
afford to pay huge sums to the software developers. Can intranet or uploading the database t....
Integrate Access Database Onto Intranet Site
Looking to integrate access database into my intranet site (5) Hey guys, im new here and am looking for answers /tongue.gif" style="vertical-align:middle"
emoid=":P" border="0" alt="tongue.gif" /> Firstly, i have designed a database using M$ access,
it consists of multiple forms which i plan to host on an intranet website, i need to be able to add
records directly from the form on the intranet website aswell as being able to edit/review current
entries on forms in the database. My question is, how would i go about integrating these forms onto
the intranet website? i plan on keeping the database and the intranet site on the s....
Database
prblem with it (1) i have free script but it is working fine on a lot of sites i tried to use it to my web site ....i
edit its config.php right and but my database name and my user name and password every thing right
and when i try to install it it gives me this error can`t connect to database please choose
file from this mobile.sql can any body help plz coz i tried huderd of times and no thing happend....
Connecting To A Remote Database
(9) I wondered if anyone here can help. I have a database on a remote server (A). I want to access it
through a php script on a different server C. I have allowed access on (A) in Cpanel - mysql dbases
- Remote Access by putting the IP address of server C The host of server (A) has also whitelisted
the IP of server C. Though I am having trouble connecting from server C which is with a different
webhost. any ideas how to get round this? I have though of SSH forwarding, but I think this can
only be used to connect a client - e.g. my pc to the remote server A. I do not ha....
Auto_increment Jumping About
not sequential numbers (3) Hello, I've been having very strange problems with AUTO_INCREMENT. It will be sequential for
the first 4 or so inserts and display them fine. After 3 or 4 or 5 inserts the FileID, which has the
AUTO_INCREMENT applied to it, will then jump to a seemingly random number like 72, 49207, and so on.
My SQL for the table in question is: CREATE TABLE `IPR` ( `FileID` int(11) NOT
NULL auto_increment, `Filename` varchar(40) NOT NULL, `ContentType` varchar(15)
NOT NULL, `Description` varchar(150) NOT NULL, `Status` ch....
My Sql Database Help?
(3) Ok, i am new at web design, i dont know too much about it... I was working on a website for about
a month this is what i got, My Web , like i said, i dont know much.. i used FrontPage and did all
of that, my current host is AFMU which uses MySQL, but the way it is set up I dont know how to
acquire the URL of the database or any information i dont know what it means at all.. i just want to
do a simple login feature, i mean this is my first website and i am learning so I think it would be
a great feature to add in and learn. i can create data bases from there but do n....
Database Size?
So how big is everybody's MySQL database? (10) Well I know that MySQL databases can get rather big, so I was just wondering how big everybodies
databases were? Do you have really big ones, or are they relatively small? Also what do you store in
them? (just text, or binary data as well)....
How Many Concurrent Users For Oracle Database?
This is to analyse and get perfect result for How many concurrent use (1) Hi friends, How many concurrent users can practically access the oracle database?
they say tht the figure is hundreds of thousands users...is there any exact figure? or does the
number of concurrent users depend on any other factors as wel? I think depend on parameter
1.session 2.processes session Specific connection of a user to an Oracle instance through a user
process. A session lasts from the time the user connects until the time the user disconnects or
exits the database application. Multiple sessions can be created and exist concurrently for ....
Database Programming In Vba 6.0
(1) hi , i need some sample program in database.thanks....
Need Info On Database Programming Courses
Oracle Database Programming (2) I know Database Programming on MS-ACCESS, now i am planning to go for some other Database
Programming courses, People told me to go for Oracle or VisualAge. Can anyone told me to start with
which one and how long is the course period and which one is easy and is it similar to ms access or
somthig different.....
Permission Problem With Mysql Database Creation
Please Help! (8) I seem to have a problem with accessing my database with proper permissions. I have set the my
database correctly giving my db username all priviliges yet i seem to be unable to even log on with
this username with a denied access error. Any ideas on resolving this?....
Is It A Good Practice To Store Image Or Other Binary Files Directly In A Mysql Database
(4) Hello to all of you beautifull people out there, I am new to MySQL, i just wanted to know if its a
good practice to directly store images and other binary files in a MySQL database. Any one with
help? Thanks....
What Is Maximum Capacity Of Astahost MySQL Database?
(11) I'm sorry about this topic. I'm a new user and my english is not very good. I want to learn
the max capacity of mysql db.....
Using pbpBB2 And Mediawiki Common Database
(3) I want to host phpbb2 forum and one wiki software (not sure whcih one at this point). Can someone
help me how to use a common or shared database for both these applications? The user data, login
could be common on both databases. Any inputs are appreciated. Thanks ....
What Is A Database How Do I Use One?
: Information about Databases and how to get use them efficiently (7) Hello All Let's start off by talking about what a database is and how it would be efficient
in using it. It wasn't until about a year and half ago now that I was first introduced to this
new age of Database. I discovered a lot of neat things and even learned about databases the very
long way. A database is exactly how it sounds its data that has a base. The base being the place
where you store all your data. If you have ever been to a library perhaps you have used the Index to
search for an author, this is a database of authors. Ever seen a rolodex on someo....
What U Recomend
database (1) hello all, first of all, want to thanks all the people how contribuite to make this service real,
now my question, i have a Lineage II online server, and i can`t make run mysql database with it,
the only thing i do its copy and paste, but that give me to many error when i try to impor some sql
files, mysql its the only db program that i know, and no so much, can someone tell me if are
someother db program for a "noob" like me?? Thanks in advance.....
MySQL Output Database Question
(18) I am new to MySql and have just created a database after using a script. My problem is not the
script, but what it says about putting it into the output file. I cant figure out the right terms
to put it in, I keep getting errors. I try using; SELECT*FROM 'database name' WHERE
'location' but it isnt working. I'm lost with this stuff, I really am. Can someone
please help me out?....
Database Program With GUI
(14) I am looking for a program to create SQL databases through a GUI to simplify it, the only things i
can seem to find are command prompt things and i can't work with them. I like MS access and
would like something similar to that if possible. I am working with windows at the moment can anyone
recommend a program i can use (preferably free) Many thanks....
The Best Database
What do you think is the best database? (48) Ive been planning to create a online application which requires tons of stuff from database. Ive
been using interbase, at first it was good but after a month i find it not user friendly at all...
Its to hard to code in php.. Can any of you guys give me a good database which is easy to use?....
Mirror My MySQL Database To Another Mysql Server
(4) Hi..I want to ask if its possible to automatically mirror my mysql databases into another mysql
server?or create a small php script to do this? The reason is because, we all know that database is
very improtant if we have dynamic website. I have my forum hosted and i want to automatically
mirror this or backup into another mysql server(free). Like in freesql.org. So that im not afraid
that i forgot to backup my database..also i have one central backup database. Thanks for the
help..Im looking forward for this posibility.....
Need Advice On Creating Online Music Database
ps - dont know anything about databases! (6) I need to create a database of around 1000 music albums that I can put on my site, with the ability
to search the database according to several different criteria. Being a complete and total NOOB to
the world of databases, can anyone point me in the direction of some software that will let me
create a good-looking and functional database, but that isn't too complicated for me to
use?! Sounds like a tall order I know, be grateful if anyone can help though. Thanks!
Topic edited to reflect content better. ....
The Best Database
databases (41) te best database for my is sql server yukon for you?....
Embedded Database
Embedded Data base at client side, (7) Hi, Now its the era of Embedded databases, no more db servers, no more host,Because with embedded
db you can get all those options, what you are used to get with DB Servers. Some of Embedded DB Are
1) Cloudscape From IBM (NOW Derby from ASF) 2) HSQLDB (OpenSource) and many more Feel the power of
EDB Cheers Arunkumar.H.G....
phpBB Database Transfer
Anyone here knows how to? (10) Hello, i'm a newbie in using phpBB and I still lack knowledge in mySQL database. How do I
transfer the datas(users,configs, all of them) contained in my current forum to another one in
phpBB? I hope someone can help, a short but detailed tutorial would be good. Example is, if I want
to move to a new host and I want to transfer all the accounts on my old forum to the new one. Thanks
in advance, hope anyone here knows how to.....
Stop AUTO_INCREMENT From Jumping
(13) One of my MySQL tables has an ID column - it's a primary key with auto_increment. And it works.
If I add six rows they number 1 to 6 nicely. But if I delete rows 4 to 6 then add a new row, it
becomes row 7. And if I delete that it becomes row 8. How can I make it so the next auto_increment
is the smallest possible? (i.e. 1,2,3,4,5,6 - I delete 4-6 and the next row inserted becomes 4)....
Looking for database, auto, increment
|
|
Searching Video's for database, auto, increment
|
advertisement
|
|