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

  • Home
  • SEARCH
  • 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 685373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:54:57+00:00 2026-05-14T01:54:57+00:00

I have a table with two child tables. For each record in the parent

  • 0

I have a table with two child tables. For each record in the parent table, I want one and only one record in one of the child tables — not one in each, not none. How to I define that?

Here’s the backstory. Feel free to criticize this implementation, but please answer the question above, because this isn’t the only time I’ve encountered it:

I have a database that holds data pertaining to user surveys. It was originally designed with one authentication method for starting a survey. Since then, requirements have changed, and now there are two different ways someone could sign on to start a survey.

Originally I captured the authentication token in a column in the survey table. Since requirements changed, there are three other bits of data that I want to capture in authentication. So for each record in the survey table, I’m either going to have one token, or a set of three. All four of these are of different types, so my thought was, instead of having four columns where either one is going to be null, or three are going to be null ( or even worse, a bad mashup of either of those scenarios ), I would have two child tables, one for holding the single authentication token, the other for holding the three. Problem is, I don’t know offhand how to define that in DDL.

I’m using MySQL, so maybe there’s a feature that MySQL doesn’t implement that lets me do this.

  • 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-14T01:54:57+00:00Added an answer on May 14, 2026 at 1:54 am

    There are multiple ways you can implement this

    Boolean Flag Logic

    You can have a boolean flag in ParentTable called ChildTableDataInserted and you can update this to TRUE if row is inserted in any one table. Only insert into a child row if the ChildTableDataInserted is False. This of-course is dependent on all inserts using the stored procedures that you create and can easily be violated, but overhead on the database is small.

    Triggers

    Put a BEFORE INSERT on the data insert to both of the child tables, and if your fault condition is met, you can raise an error for the insert.

    I personally avoid triggers unless I have absolutely no other option and this seems like a good place to implement triggers.

    Read more on triggers here

    http://dev.mysql.com/doc/refman/5.0/en/create-trigger.html

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

Sidebar

Related Questions

Lets say I have two tables - child and parent with many-to-one relation. What
I have two tables, one parent Point and one child PointValue, connected by a
I have two tables and I want to have change event on one table.
I have two tables like Parent-Child. In Parent table, there are 7211 records. In
I have two tables with a parent/child relationship. I want to update the parent
I have a table that holds only two columns - a ListID and PersonID.
I have two tables that I want to fetch data from. Lets call them
I have two tables parent and child (related as such on PK/FK GUID) Child
I have two tables in an MS SQL Server 2005 database, parent and child,
I have a database table that holds parent and child records much like a

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.