Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Yes, create a temporary table to hold the values you are copying, then you can keep a reference to the old values. Keep the first query, then do:</p> <p>CREATE TEMPORARY TABLE tmpNetworkNodes( ... schema in here ... )</p> <pre><code>INSERT INTO tmpNetworkNodes SELECT NewKey() as newNetworkKey, // Need to dtore this value in NN newNetworkId, newNodeId() as newNodeId node_id as oldNodeId, DateAdded FROM Networknodes WHERE network_id = network_key; INSERT INTO networknodes ( network_node_id, network_id, node_id, DateAdded, LastModified) SELECT newNetworkKey, newNetworkId, newNodeId, DateAdded, Now() from tmpNetworkNodes INSERT INTO networkconnections( networkconnection_id, start_network_node_id, end_network_node_id, DateAdded) SELECT NewKey(), NWN_start.newNodeId, NWN_end.newNodeId, FROM networkconnection INNER JOIN tmpNetworkNodes AS NWN_start ON networkconnection.start_network_node_id=NWN_start.oldNodeId INNER JOIN tmpNetworknodes AS NWN_end ON networkconnection.end_network_node_id =NWN_end.oldNodeId </code></pre> <p>DROP TEMPORARY TABLE tmpNetworkNodes</p> <p>Because the temporary table only contains the elements for the network you are interested in, the inner joins in the last query will filter out anything from the other networks.</p> <p>I assume you have a function for newNodeId like you do for networkKey(), so none of the columns are identity/autoincrement. I may also have your schema wrong, as it's hard to follow what the relationships are without the full table specs.</p> <p>Hope it helps!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload