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 6789797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:38:51+00:00 2026-05-26T17:38:51+00:00

Let’s say I have a database for storing (numeric) datapoints. Datapoints are grouped together

  • 0

Let’s say I have a database for storing (numeric) datapoints. Datapoints are grouped together into observations. Each datapoint belongs to one or more observations and each observation has one or more datapoints. So, I have three tables:

CREATE TABLE `data` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `time` datetime NOT NULL,
  `value` int(11) NOT NULL,
  PRIMARY KEY (`id`),
) ENGINE=InnoDB ;

CREATE TABLE `obs` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `datetime` datetime NOT NULL,
  `posthoc` tinyint(1) NOT NULL,
  `comments` varchar(500) NOT NULL,
  PRIMARY KEY (`id`),
) ENGINE=InnoDB ;

CREATE TABLE `on_obs_data` (
# linker or bridge table or whatever these are called
  `id_obs` int(11) NOT NULL,
  `id_data` int(11) NOT NULL,
  KEY `id_obs` (`id_obs`),
  KEY `id_data` (`id_data`),
  CONSTRAINT `on_obs_data_ibfk_1` FOREIGN KEY (`id_obs`) REFERENCES `obs` (`id`),
  CONSTRAINT `on_obs_data_ibfk_2` FOREIGN KEY (`id_data`) REFERENCES `data` (`id`)
) ENGINE=InnoDB ;

The problem is, how do I populate these three tables from a single spreadsheet (or as the case may be, a single interim table populated via LOAD DATA LOCAL INFILE)? I can populate data and obs individually with no problems, but on_obs_data needs to know the IDs of the newly created entries in the two tables. None of the information between data and obs overlaps, and the entries in the respective are not guaranteed to be unique other than ids which are generated by the database on insert. The only thing linking a given data entry to a given obs entry is the fact that they were originally on the same row of a spreadsheet.

I’m looking for solutions that can be implemented inside MySQL without relying on client-side scripting.

  • 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-26T17:38:52+00:00Added an answer on May 26, 2026 at 5:38 pm

    I’m surprised there isn’t a clean or well-publicized pattern for this, given that this is critical for referential integrity in a normalized database, but here is what I’ve come up with:

    1. Make sure the data and obs tables have one extra field besides the ones in the example code above. Let’s call it tempID. Make sure this field is permitted to have a NULL value.
    2. When creating the interim table*, make a column of unique IDs.
    3. Insert into data and obs tables fields selected from this table normally and have the ID field from the interim table go into the respective tempID fields of the data and obs tables.
    4. insert into on_obs_data (id_obs,id_data) select obs.id,data.id from obs,data where obs.tempID is not NULL and data.tempID is not NULL and obs.tempID = data.tempID
    5. update obs set tempID = NULL; update data set tempID = NULL;

    * I intentionally said ‘interim table’ rather than ‘temporary table’ because apparently MySQL doesn’t permit temporary tables to have autoincrementing ID fields. ಠ_ಠ

    But something still troubles me– I would think this would be one of the first problems anybody trying to update a normalized database would run into. The kneejerk assumption would be that “MySQL is stupid” or “these MySQL gurus don’t know much” but I’ve learned that when I’m tempted to make that assumption it’s often me overlooking something obvious that everyone else knows. So, MySQL community, have I just reinvented the wheel? Is there some simpler way the rest of you update bridge tables? Or am I using the wrong terminology and nobody could answer this question because nobody understood it?

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

Sidebar

Related Questions

Let's say I'm building a data access layer for an application. Typically I have
Let's say you have a class called Customer, which contains the following fields: UserName
Let's say we have a simple function defined in a pseudo language. List<Numbers> SortNumbers(List<Numbers>
Let's say I have a drive such as C:\ , and I want to
Let's say that we have an ARGB color: Color argb = Color.FromARGB(127, 69, 12,
Let's say I have a dataset in an ASP.NET website (.NET 3.5) with 5
Let's say I have a simple Login servlet that checks the passed name and
Let's say I have this: SolutionSet(const SolutionSet &solutionSet) { this->capacity_ = solutionSet.capacity_; this->solutionsList_ =
Let's say I have saved this kind of data (some text '.date(d).' some text)
Let's say I have some content classes like Page, TabGroup, Tab, etc. Certain of

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.