DEV Community

Discussion on: How to generate random IDs that are not individually unique, but unique across 2 fields (columns) in a MySQL database table?

Collapse
kp profile image
KP Author

@vasilvestre thank you for your response. Adding a unique constraint to a combination of columns in MySQL is useful. But how do you generate a unique ID for one of those fields (commentID in this case) during insert, such that userId + commentID is unique? Is there a way to do this in MySQL?