I am writing an audit platform and I can see myself falling into the same trap I usually do.
The Answers table:
SitePeriodID
QuestionID
Answer
CommentID
The Comments table:
SitePeriodID
QuestionID
CommentID
Comment
All questions have answers, but not all questions have comments. Specifically, a user only needs to enter a comment if they select a certain answer. I want to keep answers and comments separate, as I may in the future implement the ability to retrieve all the comments for an area separately from the answers. If it was all on one table I'd have to look through many thousands of rows for the questions that have comments that also match the Site and Period.
So, what I would typically do is something like this, at the point of storing data. At this point, the SitePeriodID would be known:
Insert into comments (CommentID, Comment) Values (NULL, Comment)
commentid = Get from comments where SitePeriodID = X and QuestionID = Y
Insert into answers (SitePeriodID, QuestionID, Answer, CommentID) Values (SitePeriodID, QuestionID, Answer, commentid['CommentID'])
What I've basically done is stored something in a database only to call it again immediately.
I'm fairly sure what I've got here is an XY problem where I'm overthinking my database set up, but I wanted to know if there was a way to avoid the above problem.