Note that there are some explanatory texts on larger screens.

plurals
  1. POCopying a subset of data to an empty database with the same schema
    primarykey
    data
    text
    <p>I would like to export part of a database full of data to an empty database. Both databases has the same schema. I want to maintain referential integrity.</p> <p>To simplify my cases it is like this:</p> <p>MainTable has the following fields:<br> 1) MainID integer PK<br> 2) Description varchar(50)<br> 3) ForeignKey integer FK to MainID of SecondaryTable</p> <p>SecondaryTable has the following fields:<br> 4) MainID integer PK (referenced by (3))<br> 5) AnotherDescription varchar(50)</p> <p>The goal I'm trying to accomplish is "export all records from MainTable using a WHERE condition", for example all records where MainID &lt; 100.</p> <p>To do it manually I shuold first export all data from SecondaryTable contained in this select:</p> <pre><code>select * from SecondaryTable ST outer join PrimaryTable PT on ST.MainID=PT.MainID </code></pre> <p>then export the needed records from MainTable:</p> <pre><code>select * from MainTable where MainID &lt; 100. </code></pre> <p>This is manual, ok. Of course my case is much much much omre complex, I have 200+ tables, so donig it manually is painful/impossible, I have many cascading FKs.</p> <p>Is there a way to force the copy of main table only "enforcing referntial integrity".</p> <p>so that my query is something like:</p> <pre><code>select * from MainTable where MainID &lt; 100 WITH "COPYING ALL FK sources" </code></pre> <p>In this cases also the field (5) will be copied.</p> <p>======================================================</p> <p>Is there a syntax or a tool (also a not free one, but it must do what I need, not only a subset of the features like "db compare with no options") to do this?</p> <p>Table per table I'd like to insert conditions (like MainID &lt;100 is only for MainTable, but I have also other tables).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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