Jump to content


Photo

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


  • Please log in to reply
3 replies to this topic

#1 Red 09

Red 09
  • Members
  • Pip
  • Newbie
  • 5 posts
  • LocationNorway

Posted 19 September 2003 - 08:37 AM

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.
- Red -

#2 s0urce

s0urce
  • Members
  • Pip
  • Newbie
  • 6 posts

Posted 19 September 2003 - 10:55 AM

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
s0urce

#3 nabeel21

nabeel21
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 19 September 2003 - 11:55 AM

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

#4 Red 09

Red 09
  • Members
  • Pip
  • Newbie
  • 5 posts
  • LocationNorway

Posted 22 September 2003 - 09:36 PM

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..).
- Red -




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users