User ID Column Naming – Recommended User ID Column Names

naming convention

I use user IDs a lot in tables, and I would like to find out when naming these columns, what's the best way to go about naming them. Should you be specific to what the user ID is, or should you keep using the same column name(s) to keep it consistent?

So for example:

Column names for subscriptions

user_subscriber_id = the user ID that made the subscription.

user_subscribed_to_id = the user ID that was subscribed to.

Column names for comments

sender_id = the user ID that made the comment.

reply_to_id = the user ID of the comment replied to.

Or should I always use user_id, and in the case where there needs to be 2 user IDs in a table (like above), use user_id and secondary_user_id, where the user_id should always be the user that does an action, and secondary_user_id should always be the user ID of the receiver, so:

Column names for subscriptions

user_id = the user ID that made the subscription.

secondary_user_id = the user ID that was subscribed to.

Column names for comments

user_id = the user ID that made the comment.

secondary_user_id = the user ID of the comment replied to.

Best Answer

Community wiki answer:

I think naming the column as fieldtype_fielddescription, i.e. user_id_additional_info, is more safe.

For example, not user_subscribed_to_id = the user ID that was subscribed to, but user_id_subscribed_to.

It allows, for example, to select the fields packet from information_schema if needed, using a simple LIKE 'user_id_*' pattern.