Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4074888
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:13:43+00:00 2026-05-20T17:13:43+00:00

I have a SQLite database that makes use of foreign keys, some of which

  • 0

I have a SQLite database that makes use of foreign keys, some of which will be autoincremented values. The “core” data the system represents is for example a car. The foreign keys are linking to information about wheels and tyres for example, and I wish to export n cars from one database and import into another.

I want to do this by writing a set of sql statements (i.e a bunch of insert statements) that can be loaded by the importing database, but the key values in the dumped data will not necessarily match up with the existing data (maybe there are duplicates in some of the key values).

What is the best way to deal with this? Is there an easy or recommended way to write the import script so that dependencies on exported key values are removed?

In the example below, a carindex will name a car.
CarPartColours links a single part and with a colour definition. There will be multiple rows in CarPartColours with the same CarID.
I wish to export all the relevant rows from carpartcolours, carindex, parts and colours when the user selects a single row in carindex, and import into another database. The colour definitions in that database may be duplicates (another different issue) or have the same key values as those in the origin db.

 CREATE TABLE carindex (
  ID    integer PRIMARY KEY NOT NULL,
  Name  varchar(50)
);

CREATE TABLE carpartcolours (
  ID        integer PRIMARY KEY AUTOINCREMENT NOT NULL,
  CarID     integer,
  PartID    integer,
  ColourID  integer,
  /* Foreign keys */
  FOREIGN KEY (CarID)
    REFERENCES carindex(ID)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION, 
  FOREIGN KEY (PartID)
    REFERENCES parts(ID)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION, 
  FOREIGN KEY (ColourID)
    REFERENCES colours(ID)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION
);

CREATE TABLE colours (
  ID    integer PRIMARY KEY AUTOINCREMENT NOT NULL,
  Name  varchar(50),
  R     real,
  G     real,
  B     real
);

CREATE TABLE parts (
  ID            integer PRIMARY KEY AUTOINCREMENT NOT NULL,
  Name          varchar(50),
  Value         real,
  Manufacturer  varchar(50)
);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T17:13:43+00:00Added an answer on May 20, 2026 at 5:13 pm

    @Mike I posted a previous answer, and I was on a totally wrong train of thought before, so I’m starting fresh. My apologies.

    I would say that you need to make sure you look into database master slave replication, as that’s what you’re trying to do. You want to replicate the data from the slave to the master. Since you’re not going to know which was inserted where when, then you need to look for a collision free key (or try for something collision free). So because you may generate a record in any one database and you may migrate that record to any other database, then you want to generate a UUID style key, and use that in place of a INT AUTOINCREMENT.

    This is the only way to do cross database data replication.

    Otherwise, you just want to insert into carpartcolours last.

    Sorry for the delay in answering your question …

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app that must get data from the Sqlite database in order
I have a datalogging application (c#/.net) that logs data to a SQLite database. This
I have a Core Data app that will end up being an iPhone/iPad universal
I'm developing an iPhone application that makes heavy use of Core Data, primarily for
I have few activities that make use of sqlite database, there is use of
I'm creating my first android app that will make use of SQlite. I have
I have basically finished developing an android app that makes use of SQLite databases
Background I have a couple of projects that use a SQLite DB for data.
I have created an application that makes use of database. Can I use SQL
I have a SQLite database that contains a huge set of log messages. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.