0

I have two tables where once I delete the table based on a single attribute, it would log it in another table. For example if I delete the user based on the id, it would fill it in the log table that the "'user's first name and last name' was deleted from the table"

userid firstname lastname

my sql for the delete is

DELETE FROM cars WHERE userid=1;

But I need to input it in a table called logs

Robotboy
  • 63
  • 8
  • 1
    Use a `BEFORE DELETE` trigger. – Barmar Oct 28 '21 at 00:54
  • What can I write so that it takes the first name and last name then Adds it to the logs table – Robotboy Oct 28 '21 at 02:05
  • I already told you: write a trigger. I'm not going to code it for you. – Barmar Oct 28 '21 at 02:08
  • I mean is there an sql statement that I can do like where select first name from cars where user id =1, and then format it in a VAARCHAR? or is that not possible in mysql – Robotboy Oct 28 '21 at 02:13
  • 1
    `INSERT INTO log SELECT CONCAT(firstname, ' ', lastname, ' was deleted') FROM cars WHERE userid = 1` – Barmar Oct 28 '21 at 02:17
  • Thank you I just didn't know about the CONCAT command. sorry for making it seem like I wanted you to do that code – Robotboy Oct 28 '21 at 02:21
  • Your question is very unclear about what your problem is. Nowhere did you ask how to concatenate strings in MySQL. – Barmar Oct 28 '21 at 02:29

0 Answers0