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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:27:11+00:00 2026-06-14T14:27:11+00:00

Say I have the following tables which implement a many to many relationship between

  • 0

Say I have the following tables which implement a many to many relationship between parts and objects, where the link table has a unique key pair (object_id,part_id) such that there are no duplicate rows:

Part table:

part_id | part_name | part_zone
--------+-----------+----------  
0       | part1.0   | top  
1       | part2     | bottom  
2       | part1.1   | top
3       | part3     | top

Object table:

object_id | object_name
----  ----+-----------
0         | object1
1         | object2
2         | object3
3         | object4

Link table:

object_id | part_id
------  --+---------
0         | 0
0         | 1
1         | 1
1         | 2

There is a further constraint in that there should only be one of each part_zone in an object. So if the part_zone column were to be moved to the link table and the key changed to the unique pair (object_id,part_zone) then this would be satisfied. I don’t want to do this however since part_zone should be in the part table. In my head I’m looking to keep the tables as are they are, but use the (object_id,part_zone) unique key where part_zone is pulled from the part table via a join on part_id.

Hopefully my intention is clear, but I’m not too sure this is necessarily the best implementation or I’m using the right terminology for what I’m after.

Thanks in advance to anyone who can offer any insight.

  • 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-06-14T14:27:12+00:00Added an answer on June 14, 2026 at 2:27 pm

    You could add part_zone into Link, with a cascading compound foreign key constraint referencing (part_zone, part_id) in the Part table; that way, you can define a UNIQUE constraint on (object_id, part_zone) as suggested whilst still being able to maintain part_zone from the Part table:

    ALTER TABLE Link ADD part_zone varchar(10);  -- should be same size as in Part
    ALTER TABLE Part ADD INDEX (part_zone, part_id);
    
    UPDATE Link JOIN Part USING (part_id) SET Link.part_zone = Part.part_zone;
    
    ALTER TABLE Link
      ADD FOREIGN KEY (part_zone, part_id) REFERENCES Part (part_zone, part_id)
        ON UPDATE CASCADE,
      ADD UNIQUE INDEX (object_id, part_zone)
    ;
    

    You could even define triggers on INSERT and UPDATE to populate the values in Link so that you need not do it manually:

    CREATE TRIGGER link_insert BEFORE INSERT ON Link FOR EACH ROW
      SET NEW.part_zone = (SELECT part_zone FROM Part WHERE part_id = NEW.part_id);
    
    CREATE TRIGGER link_update BEFORE UPDATE ON Link FOR EACH ROW
      SET NEW.part_zone = (SELECT part_zone FROM Part WHERE part_id = NEW.part_id);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following three tables: Item Code ItemCode (many to many relationship between
let say, I have the following tables: Cities which hasMany Streets which hasMany Houses
Say I have the following tables: GearType : snowboard/helmet/shoes/whatever GearModel : which describes the
Lets say I have the following tables. TABLE L id name 51 joe 52
Let's say I have the following tables: PartyRelationship EffectiveDatedAttributes PartyRelationship contains a varchar column
Let's say I have the following tables tableA seq datea 1 2010-01-01 2 2010-02-01
Let's say I have the following 4 tables (for examples' sake): Owners, Trucks, Boxes,
For example, let's say I have the following two tables: Table1: Id ---- 1
Say for example, I have the following two tables: TableA { _id } TableB
Let's say I have following table like this <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0

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.