Reputation: 13
In MySQL, I would like to copy data from my users_temp table to my users_final table. The fields are identical.
Here comes my query:
INSERT users_final (username, password, email)
SELECT username, password, email)
FROM users_temp
WHERE id=8
My users_final table also contains a field "stamp_created".
How do I achieve that when I copy my row from users_temp to users_final the field "stamp_created" of the newly created row will contain the current timestamp?
(Of course I do not want to copy the "stamp_created" value from my users_temp table.)
Upvotes: 1
Views: 656
Reputation: 218960
You can get the current date from the NOW()
function. Something like this:
INSERT users_final (username, password, email, stamp_created)
SELECT username, password, email, NOW()
FROM users_temp
WHERE id=8
Upvotes: 2
Reputation: 1298
You can set CURRENT_TIMESTAMP as default value and set as not nullable to stamp_created field in users_final table.
Upvotes: 1