sql - How to copy data -
i want create stored procedure copy data 3 tables. these structure of 3 tables:
quotes quote_id integer, note varchar(50)
quote_id primary key , auto incremented using trigger
windows win_id integer, quote_id integer
win_id primary key (auto incremented using trigger) , quote_id here fk quotes table
win_links links_id integer, win_id integer, linked_win_id integer, edge_name varchar(30)
links_id primary key (auto incremented using trigger) , both win_id , linked_win_id fk windows table.
i created sp this:
create or alter procedure copy_quote_proc ( p_quote_id integer) declare variable v_last_inserted_quote_id integer; declare variable v_old_win_id integer; begin insert quotes (note) select note quotes quotes.quote_id = :p_quote_id returning quote_id :v_last_inserted_quote_id; select win_id windows (windows.quote_id = :p_quote_id) :v_old_win_id begin insert windows (quote_id) select :v_last_inserted_quote_id windows win_id = :v_old_win_id end
the third table used link windows within 1 quote example win_id = 5 , linked_win_id = 6 record may have same window linked different window example win_id = 5 , linked_win_id = 7 , on.
now how copy third table win_links
point correctly newly copied windows ?
Comments
Post a Comment