Jump to content

auto_increment, multiple columns


robingo

Recommended Posts

A) What I want:

 

I have a table with a field id.

This is my primary key, and it's set as auto_increment.

When someone adds a record, it will generate a unique id, automaticly.

Example: these id's are in the table:

1

2

3

4

 

When I delete the record where id=4, the next record added will get id=5 (and not 4!).

This is how I want it do be.

 

 

B) What I get:

 

I want to do the same thing, but with two columns, id1 and id2.

I've set id1 and id2 as primary key, and id2 set as auto_increment.

This is what happens:

Table:

 

id1 | id2

1  | 1

1  | 2

1  | 3

1  | 4

2  | 1

2  | 2

 

When I delete, for example, the record with id1=1 and id2=4,

the next added record will get:

1  | 4,

but I want it to get:

 

1  | 5.

 

This is basicly what happens in "A)". It "remembers" where it stopped counting,

and it continues, even if a row was deleted!

 

Can anyone help me with this?

I googled a lot but couldn't find a solution...

Thanks a lot!

Link to comment
https://forums.phpfreaks.com/topic/226173-auto_increment-multiple-columns/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.