473,399 Members | 4,254 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Strange FK relationship - how, and is it right?

Hello all,

I have a scenario in which there are three tables, A, B and C. A and B
have PK columns, both are of the same type. C has a FK column, of the
same type as the PK columns of A and B, but the values in it should be
either in the PK column of A or in the PK column of B...

I figured out I could do this by creating a check constraint along with
a user defined function to make sure the master table (either A or B)
has a corresponding row before a row is inserted or updated into C. But
I don't know how to handle deletions from A and B: how to make sure the
corresponding row in C is deleted first. Any help would be greatly
appreciated. Thanks.

Now the more important question: C has 6 columns, and all these columns
are common to both A and B. That is, the common columns of A and B have
been moved to a new table C. Apart from this, there is no purpose or
meaning to having the table C; if it were not for C, A and B would've
had 6 additional columns. I know such factoring is common in the OO
world, but is it right in the RDBMS world? What else should've been
done? Any thoughts/suggestions? Thanks a lot in advance.

- Ramesh

Dec 9 '05 #1
1 1017
i'd do it the other way around:

create table c(c int primary key,
c_type char(1) not null check(c_type in ('A', 'B')),
unique (c, c_type))
go
create table a(
c int not null,
c_type char(1) not null check(c_type = 'A'),
foreign key(c, c_type) references c(c,c_type))
go
create table b(
c int not null,
c_type char(1) not null check(c_type = 'B'),
foreign key(c, c_type) references c(c,c_type))
go
drop table a
drop table b
drop table c

Dec 9 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mike Sutton | last post by:
Please let me know what you think of this scheme I have come up with (not to imply that noone else has before me) for managing relationships. I have created an entities table with Individual and...
8
by: Andante.in.Blue | last post by:
Hello, I have just inherited a legacy Access 97 database. While going through it, I noticed something strange... its Relationships window (the one accessed by Tools --> Relationships) is almost...
2
by: Julia Baresch | last post by:
Hi everyone, My database has 3 data tables with chained one-to-many relationships i.e. Table1 1-->Many ->Table2 1-->Many ->Table3 I added a fourth table to hold supplemental data that also...
2
by: Joseph Macari | last post by:
I recently installed Office2003 on my computer. I had imported (not linked) a couple of tables from an Access 2000mdb into an Access 2003mdb. I had composed various queries and forms with these...
7
by: francophone77 | last post by:
I deleted a relationship in the relationship view, but when I create a query that includes those two tables, the relationship reappears. When I go back to the relationship view there is NO...
9
by: Fijoy George | last post by:
Hi all, I am a bit perplexed by the following behaviour of the 'is' comparator False True My understanding was that every literal is a constructure of an object. Thus, the '2.' in 'x = 2.'...
2
by: access baby | last post by:
I have 5 tables need to create relationship Customer Table CustomerID(auto number)(primary key) Customer Name(text) Customer City(text) Customer St(txt) Customer OrderTable Customer...
11
by: VijaKhara | last post by:
Hi all, I just write a very simple codes in C and vthere is a very strange bug which I cannot figure out why. The first loop is for v, and the second for k. There is no relationship between v...
2
by: Nemo | last post by:
I have done append queries before, though not recently, so I may be doing some very simple error to which I am oblivious. I am using the query window. When the query I wanted to do ran into Key...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.