Copy data from one table to another

Hello everyone! I know that it is something basic perhaps but I cannot find documentation, in addition to the fact that very recently I started using the tool.
I have the following problem, I have to make a copy of data from a table by means of parameters that I generate from another, to save a history. I understand that I can do it either by after event or by store procedure, could you give me examples of both if possible? I give the example of my case:

table A … (is where I save the movements): id, presid, entid, preperestid, preiodoid.
table B … (is the one that contains the data to be duplicated): id, perid, per_docnro, per_apeynom, presid, entid, preperestid, preiodoid.

As you can see … preside, entid, preperestid, preiodoid are repeated in both because it is for those fields that I make the filters. The particularity is that I must always duplicate the last value received presid, without repeating it … entid, and execute the duplication of the data with the new presid, entid, preperestid, preiodoid … but from the table B … to generate the user.
Thanks a lot!

use

$sql_recopy_t =
"INSERT INTO ILP_doc_werktijdfactor_TEMP

SELECT
st_id,
ev_id,
wtf_factor,
wtf_correctie
FROM
ILP_doc_werktijdfactor
WHERE ev_id = {oude_periode}";

sc_exec_sql($sql_recopy_t);

the events depend on what you wan’t to to do

if you change the value in a record and wan’t to update the other table you use somthinhg like.

// update de rooster temp database met gegevens van de nieuwe periode

// SQL statement parameters
$update_table = ‘ILP_rooster_TEMP’; // Table name
$update_where = “ev_id = {oude_periode}”; // Where clause
$update_fields = array( // Field list, add as many as needed
“wk_datum_gesprek = DATE_ADD(wk_datum_gesprek , INTERVAL $verschil_dagen DAY)”,
“wk_datum_gesprek_e = DATE_ADD(wk_datum_gesprek_e , INTERVAL $verschil_dagen DAY)”,
“ev_id = {nieuwe_periode}”,
);

// Update record
$update_sql = ‘UPDATE ’ . $update_table
. ’ SET ’ . implode(’, ', $update_fields)
. ’ WHERE ’ . $update_where;
sc_exec_sql($update_sql);

This should I run as an after event? Thx!

that is possible. or you can make a button to start the proces

Thanks for helping @rotrax I have been able to perform insert, update and deleted. But I can’t capture the last rendering id that was generated and make a copy of it. As I detail the example at the beginning of the post …

i don’t know what you mean so i can’t help you with that

Basically I could not … This that you passed to me as an example is by event after? Should I create a button to process? I need to insert all the data when creating a new feature in the other table. As I explained in the first post …