Answer the question
In order to leave comments, you need to log in
Inserting data using just added data?
How to organize the initial data for the user?
For example, there is a table tags (id, user_id, tag) into which we insert data (1,1, "food"). There is a second table post(id, user_id, tag_id, text). How to get the id of the inserted tag in order to add a record to the post table, provided that many records are inserted into the table with tags at once?
Answer the question
In order to leave comments, you need to log in
you want to insert id tags from the tags table into the Post table?
1. Are you sure that there should be tags (id, user_id, tag), and not two tables:
tags (id, tag)
user_tag (user_id, tag_id)
Since users and tags are many-to-many and therefore an intermediate user_tag table is needed .
2.
How to get the id of the inserted tag in order to add a record to the post table, provided that many records are inserted into the table with tags at once?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question