visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Databases :: MySql :: AUTO_INCREMENT with Specific Number


By: Squibi U.S.A.  Date: 03/10/2003 00:00:00  English  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 English  Type : Comment
alter table yourtable auto_increment=100;

then create your records...
By: Squibi Date: 03/10/2003 18:12:00 English  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 English  Type : Comment
0
By: VGR Date: 03/10/2003 18:29:00 English  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 English  Type : Comment
it's an INTEGER column, after all :D
By: Squibi Date: 04/10/2003 22:23:00 English  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 English  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 English  Type : Comment
Thanx

Do register to be able to answer

EContact
browser fav
page generated in 348.166230 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page