Jump to content

What is the practicality of using a global unique id across tables


emehrkay

Recommended Posts

I have many tables - users, notes, news, etc - each with their own unique id to connect to one another (the usual stuff). I want to add a commenting system to the service. So if someone wants to comment on a news article or a picture etc, it is all contained within one table system.

 

I thought that I would add an 'object' table that is the global unique id master. So if I were to add an user, they would get a user_id and object_id, and likewise for just about anything else that gets inserted into one of the database tables.

 

I figured this would be the cure for the commenting system, you have a comment_id and then you connect it to an object_id. and when the page is generated, a check against the commenting system and object_id would display comments...

 

Does this make sense? Would there be a better way to handle this? If I were to go this route, how large could that object table get - it would be handing out object_id's for N tables?

 

Thanks

Another way you can do it is have your main object table and have that dictate what your sub-table id's are...then you really have 1 unique id to worry about

 

objects:

id    type

1    user

2    note

3    news

4    user

5    comment

 

users:

id    name

1    test1

4    test2

 

notes:

id    title

2    this is a test

 

and so on...

 

...hope that makes sense :) It seems like this would keep you a little more organized and not worrying about more then 1 id.

Archived

This topic is now archived and is closed to further replies.

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