I am currently working on a website that needs a comment system. Since this site is brand new and the database structure has not yet been established, I would like to offer some recommendations on how to best handle the comment system, such as:
- Comments should be placed on anything. Include items in future tables.
- Comments should be quick (and easy?) Requests.
I know that this is just not so much, so here is the idea: every university has colleges, every college has buildings, and each building has rooms. Each user should be able to comment on any of these four elements (and future ones that we can add later), but I would like to avoid creating a comment table for each element.
The solution I came up with seems to work, but I'm open to other ideas as well. My solution is to use the UUID as a primary key for each position (university, college, building, room), and as a reference identifier in the comments table - UUID. Although I donβt think that I can create a system of foreign keys to bind everything, I believe that nothing will break, because only available products can have comments, so the item may either not have comments, or if it is deleted, then comments simply never will be refunded.
University: UniversityID - CHAR(36) //UUID() & primary key ... Comments: CommentID - CHAR(36) //UUID() & primary key CommentItemID - CHAR(36) //UUID of item & indexed CommentUserID - INTEGER CommentBody - TEXT
And then the following queries will appear:
SELECT * FROM University, Comments WHERE UniversityID = CommentItemID;
So what do you all think? Will this system scale with large amounts of data, or is there a better one (perhaps a better option or template)?
I thank you in advance.
Edit 1: I changed the definition of the comment to include the primary key and indexed column to solve the problems raised so far. Thus, the system may also have comments on comments (not sure how this will confuse this in practical code, but it has a certain mathematical completeness that I like). I wanted the system to be as similar as possible, although until I accepted the answer.
In both answers so far, Sebastian Goode and Brian M. have proposed a double primary key of two integers, which are something like ItemID and TableID. My only hesitation in this method is that I would either have to have a new table listing the table identifiers and their required row table names, or enter global variables in my code that references them. If there is no other method that I am missing, this seems like extra code that can be avoided for me.
What do you all think?