I am creating a table for comments and one of the fields is user_id. Well both a regular user and an administrator will be able to post a comment so I’m not sure how I would do that.
Users table has a primary key of user_id
Admins table has a primary key of admin_id
So how would I do that?
If you can redesign to have a single table (
login?) with an isAdmin flag, I’d do that.If you can’t, then have a process that causes every entry in the admin table to create a related entry in the user table. The admin table can then have a user_id field to relate the two together.
In this way every admin has a user, and all comments can be made using that user_id.
I would strongly avoid having comments keyed against both user_id and admin_id, with one of them being kept NULL. It will make queries untidy, obstruct you from enforcing constraints, and tie you to he messy two-key method if you encounter a similar need anywhere else.