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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:16:40+00:00 2026-05-23T02:16:40+00:00

I have 3 tables. A base table, call it Table A, and two tables

  • 0

I have 3 tables. A base table, call it Table A, and two tables that reference Table A, Call them Table X and Table Y. Both X and Y have a foreign key contraint that references Table A. The Foreign Key of X and Y is also their own Primary Key.

I’d like to know if it is possible to add a constraint that will only allow one of these tables to contain a recrod that references Table A. So if X has a record that references A then Y can’t have one and if Y has a record that references A then X can’t have one.

Is this possible?

Thanks,

  • 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-23T02:16:41+00:00Added an answer on May 23, 2026 at 2:16 am

    CHECK constraints with UDFs (which is Oded’s answer) don’t scale well and have poor concurrency. See these:

    • Scalar UDFs wrapped in CHECK constraints are very slow and may fail for multirow updates
    • Tony Rogerson

    So:

    • create a new table, say TableA2XY
    • this has the PK of TableA and a char(1) column with a CHECK to allow ony X or Y. And a unique constraint on the PK of A too.
    • tableX and tableY have new char(1) column with a check to allow only X or Y respectively
    • tableX and tableY have their FK to TableA2XY on both columns

    This is the superkey or subtype approach

    • all DRI based
    • no triggers
    • no udfs with table access in CHECK constraints.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a star schema type data base, with fact tables that have many
In my database I have tables that define types for example Table: Publication Types
I have two tables in my db: Customers and Subcontractors. Now it appears that
I have table in data base name train delay, with columns train number(int), DelayTime(int),
If I have a table in MySQL which represents a base class, and I
I have a table called Users ( class User < ActiveRecord::Base ) and a
I have a declarative table defined like this: class Transaction(Base): __tablename__ = transactions id
When I have tables in my database that have PK/FK relationships (int) and when
I have two models: Program < ActiveRecord::Base has_many :events def federal_financing events.sum(&:federal_financing) end def
I have some sprocs that need a temp table. In order not to hardcode

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.