By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,034 Members | 1,777 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,034 IT Pros & Developers. It's quick & easy.

Auto increment

P: 23
Greetings to all,

this is my query for creating table..

Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE `books` (
  2. `serial_num` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT ,
  3. `bk_name` VARCHAR( 200 ) NOT NULL ,
  4. `qty` INT( 10 ) NOT NULL ,
  5. `author` VARCHAR( 25 ) NOT NULL ,
  6. PRIMARY KEY ( `serial_num` )
this is my table structure...

Expand|Select|Wrap|Line Numbers
  1. +------------+------------------+------+-----+---------+----------------+
  2. | Field      | Type             | Null | Key | Default | Extra          |
  3. +------------+------------------+------+-----+---------+----------------+
  4. | serial_num | int(10) unsigned |      | PRI | NULL    | auto_increment |
  5. | bk_name    | varchar(200)     |      |     |         |                |
  6. | qty        | int(10)          |      |     | 0       |                |
  7. | author     | varchar(25)      |      |     |         |                |
  8. +------------+------------------+------+-----+---------+----------------+
  9.  
if i delete any row in this table..then the auto increment does not works properly...for e.g. if i delete 2nd row means.. then the serial number for books are 1,3,4,5..how to insert new row with serial number 2 ? how to resolve this? please help me..


_______________________
If not now,then never....

Regards,
Viji nellaiappan
Mar 4 '09 #1
Share this Question
Share on Google+
3 Replies


10K+
P: 13,264
Why is it important for you to insert at id 2? Why not let it auto increment and insert 6 instead?
Mar 4 '09 #2

P: 23
@r035198x
while displaying record one by one using serial number it shows error for 2nd row..so i want to insert a record in that id..


______________
If not now,then never....


Regards,
Viji nellaiappan.
Mar 4 '09 #3

10K+
P: 13,264
How are you displaying the records by using serial number? You should be making sure that it works even if there is no record with id 2 in there. In general if you set a column to auto_increment, you should not be concerned about what values that column takes. It should all be managed by MySQL. If you want a column whose values you can cntrol, then define another column for that in the table and leave the auto_increment one to MySQL's amusement.
Mar 4 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.