Andrew Backes
Andrew Backes

Reputation: 1904

Database Design - Questions, Answers, Tags

I have been reviewing the questions and answers here: Recommended SQL database design for tags or tagging , and I understand the general design of the database, but how does it work? For instance, say I have the design setup like this:

Table:Questions
Columns: QuestionID, Title, Content

Table: Tags
Columns: TagID, Title

Table: QuestionTag
Columns: QuestionID, TagID

Now when a user creates a new question, would I insert that question into the Questions table with the QuestionID set to auto increment? Then do the same for the Tags?

But then how do I match the QuestionID to the TagID in the QuestionTag table if I don't necessarily know what the ID is upon insertion?

Upvotes: 0

Views: 338

Answers (1)

hjpotter92
hjpotter92

Reputation: 80629

if it's mysql, the last ID can be traced using MYSQL_INSERT_ID()

Upvotes: 1

Related Questions