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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:20:15+00:00 2026-06-02T16:20:15+00:00

i have two tables, one ‘master’ and one ‘child’ table. Each table has a

  • 0

i have two tables, one ‘master’ and one ‘child’ table.
Each table has a field named ‘ProductNo’, which is defined as PRIMARY KEY and UNIQUE.
Is it possible to define the field ‘ProductNo’ in the table ‘child’ and the same field in table ‘master’ as PRIMARY + UNIQUE together?

master:
ID | ProductNo

child:
ID | MasterID (FK on master.ID) | ProductNo

Relation >> 1 (master) : n (child) 


example data:
master: 
1 | 1234
2 | 4567

child:
100 | 1 | 3333
101 | 1 | 4444
102 | 2 | 5555
103 | 1 | 1234 <----- NOT ALLOWED! PRODUCT NO ALREADY EXISTING IN TABLE `MASTER`
104 | 2 | 1234 <----- NOT ALLOWED! PRODUCT NO ALREADY EXISTING IN TABLE `MASTER`

It is needed to check on inserting/updating table ‘child’ if ‘ProductNo’ already exists in table ‘master’.

How can I define it?
Or am I needed to create a trigger for this?

TIA Matt

  • 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-02T16:20:16+00:00Added an answer on June 2, 2026 at 4:20 pm

    no, there is no such thing as composite PKs among tables.

    Just for data consistency, if the Ids are the same, you should add a FK from child to the master.

    To solve your problem, a trigger with a check like this:

    if exists (select 1 from master where prodcutId=new_productId)
    

    would be a good idea

    EDIT:

    actually the best idea is to have only one table called product with a ID and a masterID field with a relation to itself. The way you have today Im pretty sure that you have a lot of duplicate data and you are stuck with 2 levels on hierarchy.

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

Sidebar

Related Questions

I have two tables, one is a table of forum threads. It has a
I have two tables, each one has a primary ID column as key. I
I have two tables with one_to_one relation between them Table one: User - has
I have two tables one named Person , which contains columns ID and Name
I have two tables : one table it matchs and the other is teams.
I have two tables. One (Widgets) has a list of widgets (ID, widget_name, color,
I have two tables: one has a datetime column, the other has a date
I have two tables: one table (okay, it's a view), vComputer, lists many computers
I have two tables (one for quarter one, one for quarter two), each of
I have two tables one called permissions and one called roles which are related

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.