Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.