Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a 'Project' table with columns project_id and project_name and another table 'Task' with coloumns Task_id and task_name.



i want task_id format of project_id + Auto Increment


for example:

project table

project_id project_name
------------------------
1 abc
2 xyz
3 tre

Task Table

Task_id task_name project_id
------------------------------
11 ererer 1
12 asdklasl 1
21 akldjalkdj 2
22 Zdasdad 2
23 ZDmzxm 2
31 dzdldxz 3

for every new project auto increment has to start with 1.
Posted

1 solution

In my opinion this would be a bad idea. This logic wuold introduce unnecessary complexity to the databsae design and to the programming, how the data base is used. What would be the benefit of this?

For example consider what happens if you have projects 1 and 11 and they have tasks 11 and 1 correspodingly. Both these tasks would have a key value of 111. How to handle this situation...

I would suggest using pure surrogate keys. You can always join the tables when querying and fetch all the relevant data from each table.
 
Share this answer
 
Comments
Member 11042471 17-Jul-15 7:10am    
could you suggest any best solution for this?
Wendelius 17-Jul-15 7:14am    
I already did: Use surrogate keys. Have a look at https://en.wikipedia.org/wiki/Surrogate_key[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900