P
P
postLaravel2017-04-09 22:19:23
MySQL
postLaravel, 2017-04-09 22:19:23

How to add a row to a table given an id from another table?

there are two tables: task(task) with fields id, title, coment, status, user_id and
table user with fields id, name, surname, spec, email, password user from user table? Accordingly, the user_id field from the task table should take the value id from the user table.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
toxa82, 2017-04-09
@postLaravel

It will be a normal INSERT, only you yourself must substitute the required user_id in the data. Data integrity check can be done using the foreign keys of the table, then the database will not allow creating a record with a non-existent user_id in the user table

E
entermix, 2017-04-09
@entermix

Just like any other requests to insert information:
Where {USER_ID} is the user ID from the user table
https://dev.mysql.com/doc/en/insert.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question