Databases :: MySql :: AUTO_INCREMENT with Specific Number |
|||
| By: Squibi |
Date: 03/10/2003 00:00:00 |
Points: 20 | Status: Answered Quality : Excellent |
|
Auto_increment for example i have product_no is as primary key and i would like to auto incremant that values automatically prod_no INT(13) PRIMARY KEY AUTO_INCREMENT but i would like to increase my number from 100, my product number should start from 100 how can i do? 100 101 102 .. .. regards |
|||
| By: VGR | Date: 03/10/2003 17:59:00 | Type : Comment |
|
| alter table yourtable auto_increment=100; then create your records... |
|||
| By: Squibi | Date: 03/10/2003 18:12:00 | Type : Comment |
|
| yha i tried it when i start to insert rows it does start with 100 for exapmple i have customer as table and it has two cols custno and custname custno is autoincrementing =100 now i hv inserted values INSERT INTO customer VALUES (' ', 'john'); or what should i put in the autoincremented field plz help me |
|||
| By: VGR | Date: 03/10/2003 18:26:00 | Type : Comment |
|
| 0 |
|||
| By: VGR | Date: 03/10/2003 18:29:00 | Type : Comment |
|
| mysql> select * from thetable; +--------+---------+-------+ | theKey | Name | Value | +--------+---------+-------+ | 1 | Alpha | 0 | | 2 | Alpha | 0 | | 3 | Alpha | 1 | | 4 | Beta | 0 | | 5 | Charlie | 1 | +--------+---------+-------+ 5 rows in set (0.13 sec) mysql> alter table thetable auto_increment=100; mysql> insert into thetable values(0,'new1',0); mysql> insert into thetable values(0,'new2',1); mysql> select * from thetable; +--------+---------+-------+ | theKey | Name | Value | +--------+---------+-------+ | 1 | Alpha | 0 | | 2 | Alpha | 0 | | 3 | Alpha | 1 | | 4 | Beta | 0 | | 5 | Charlie | 1 | | 100 | new1 | 0 | | 101 | new2 | 1 | +--------+---------+-------+ 7 rows in set (0.00 sec) mysql> |
|||
| By: VGR | Date: 03/10/2003 18:29:00 | Type : Comment |
|
| it's an INTEGER column, after all :D |
|||
| By: Squibi | Date: 04/10/2003 22:23:00 | Type : Comment |
|
| My column is not incremeting automaticly, for ur above table i did INSERT INTO thetable values(0,'new1','1'); INSERT INTO thetable values(0,'new2','1'); but it doesnot works instead of incrementing frm 100 value becomes '0' and second time it says duplicates error coz zero will be repeated twice after its P.K Is there any mistake i hv commited! |
|||
| By: VGR | Date: 04/10/2003 22:35:00 | Type : Answer |
|
| the table was created with the first (thekey) being unique auto_increment not null, ie like a PRI KEY. do this : alter table thetable modify theKey integer unique auto_increment; if it fails, it means you've already duplicates. "truncate table" and insert again |
|||
| By: Squibi | Date: 04/10/2003 22:55:00 | Type : Comment |
|
| Thanx |
|||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








