In my system, I want each user to have an own id sequence for his articles.
So, I have created a database that has a table that depicts a correspondence between users and their articles. Here is the outline of such table:
+------+----------+---------+
| id | article | user_id |
+------+----------+---------+
| 1 |some notes| 1 |
+------+----------+---------+
| 2 |some notes| 1 |
+------+----------+---------+
| 3 |some notes| 2 |
+------+----------+---------+
| 4 |some notes| 2 |
+------+----------+---------+
| 5 |some notes| 3 |
+------+----------+---------+
But I want to generate the ids in this table in the following way:
+------+----------+---------+
| id | article | user_id |
+------+----------+---------+
| 1 |some notes| 1 |
+------+----------+---------+
| 2 |some notes| 1 |
+------+----------+---------+
| 1 |some notes| 2 |
+------+----------+---------+
| 2 |some notes| 2 |
+------+----------+---------+
| 3 |some notes| 2 |
+------+----------+---------+
| 1 |some notes| 3 |
+------+----------+---------+
So, when a new user is being created in the associated user table, an id sequence for his articles will start from 1.
Is there any generally accepted approach to solve this problem?
per_user_idwhenever there is a deletion? That may be a bit of a problem if this is being used for cases where people refer to things by id. For instance, if you have an issue tracking system and you want a different series of ids for each project, this would be a problem. Do you have any advise on how to handle those? – Khaja Minhajuddin Mar 27 '17 at 08:12