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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:41:09+00:00 2026-05-26T10:41:09+00:00

I am attempting to implement an extension table structure for some stats that I

  • 0

I am attempting to implement an “extension” table structure for some stats that I am gathering from multiple sources.

My “parent” table looks something like this:

`test_parent` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `date` date NOT NULL,
  `actions` int(11) unsigned NOT NULL,
  PRIMARY KEY (`id`)
)

My first “child” table looks somethinglike this (eventually I will have a child table for each source):

`test_child` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `test_parent_id` int(11) unsigned NOT NULL,
  `external_id` int(11) NOT NULL,
  `external_actions` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `test_parent_id` (`test_parent_id`)
)
CONSTRAINT `test_child_ibfk_1` FOREIGN KEY (`test_parent_id`) REFERENCES `test_parent` (`id`)

All this will work fine in my implementation (I will be using Java/Hibernate); however, for the first child table I will need a composite unique key for external_id and date. I know that I cannot have a composite unique key across tables. I would rather not have one table to store all of the stats because the actual analytics I am collecting can vary greatly by source. I would be more open to getting rid of the “parent” table.

Is there some other way I can look at this problem? I am hoping to avoid using triggers to enforce uniqueness, if possible.

  • 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-26T10:41:10+00:00Added an answer on May 26, 2026 at 10:41 am

    You need the date in the child table if you want to establish a unique constraint on it with external_id. You can also have date live in the parent table, and reference it via the foreign key. That will allow you to support date differently by other child tables in the future.

    CREATE TABLE `test_parent` (
      `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
      `date` date NOT NULL,
      `actions` int(11) unsigned NOT NULL,
      PRIMARY KEY (`id`, `date`)
    );
    
    CREATE TABLE `test_child` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `test_parent_id` int(11) unsigned NOT NULL,
      `date` date NOT NULL,
      `external_id` int(11) NOT NULL,
      `external_actions` int(11) NOT NULL,
      PRIMARY KEY (`id`),
      UNIQUE KEY `test_parent_id` (`external_id`,`date`),
      CONSTRAINT `test_child_ibfk_1` FOREIGN KEY (`test_parent_id`, `date`) 
        REFERENCES `test_parent` (`id`,`date`)
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to implement some additional statistics gathering in a C# server application
I am attempting to implement some very basic debugger protection to prevent kids from
I'm creating a Validator<T> class. I'm attempting to implement the Linq SelectMany extension methods
I am currently attempting to implement a custom gridview interface to display data from
I'm attempting to implement OpenID with ASP.NET MVC (Yeah, we haven't heard that one
I have a web form that I am attempting to implement dynamic drop down
I'm attempting to implement a repository pattern with my poco objects auto generated from
I am attempting to implement a firefox extension which filters incoming HTTP responses and
I'm attempting to implement a feature where a user can select some text in
I'm attempting to implement a simple Single Sign On scenario where some of the

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.