Jump to content

How can entries from several tables have unique ID in DB?


Red 09

Recommended Posts

My current solution is a table i call index (the parent?), wich holds a field for unique id and a reference to a unique entry in another table (the child?).

 

Does mySQL have a built-in better way to \"share\" id sequences? Example: I make an entry into TableA and it gets id 1, the next two entries are in TableB and gets id 2 and 3, I add one more entry to TableA again and this gets id 4... and so on.

Link to comment
Share on other sites

Hi.

 

The only way I know of that you could do that is that you do it manually. Search for the highest id in all of your tables, then increase by one and add a new entry.

 

This is an odd thing to do though. I always try to keep my id\'s from 1 to infinity (actually, 65536) in all tables, no matter what. What are you trying to do? There might be a better solution.

 

Source

Link to comment
Share on other sites

if i understood ur question correctly,

 

U can return the max sequence number by

 


Select max(unique_id) from table;

 

Where unique_id is a column that stores sequence numbers..

 

Then u can use that number and increment it by 1 and insert it into the database.

 

-hope it helps

Link to comment
Share on other sites

Thanks for the replies.

 

What I\'m trying to do is to make a intranet site that holds different kinds of data (articles, calenders, contact lists, image galleries, etc) in different tables.

 

I have a crude system with main categories and sub categories. the reason I want to have unique id\'s is so I can mix entries from different tables in the sub categories.

 

Example: Category B, has a sub category K. Inside sub categroy K I want to place 3 articles, and 1 contact list. I want to be able to sort these by alphabet or date as if they were all entries from the same table.

 

I\'m not sure I understood what nabeel21 meant, but I\'ll look into it. I\'ll probably figure it out somehow, but I\'m not sure if It would be the best solution :) I want to give the users full ability to create categories, subcategories and put entries in these from the different tables I mentioned (articles, etc..).

Link to comment
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.