473,383 Members | 1,717 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,383 software developers and data experts.

Uniqueness of pair

MDS
All,

I am endeavouring to implement an "Also in the area" feature to an
Access 97 DB.

Within the table, there are two columns drawn from the same domain -
let's call them Place A and Place B. Place A and Place B form the
composite primary key.

When the user enters "Place A" is in the area of "Place B," it should
not be necessary to insert a second record stating "Place B" is in the
area of "Place A" as this can be infered from the first statement.

Therefore, the initial A/B entry should also reflect the uniqueness of
A/B as, in effect, an unordered pair.

Can this be implemented in Access? If so, how?

Thanks for your help in this,
Mark


Nov 13 '05 #1
1 1564
That's actually not a trivial problem in database design.

Because I like to show off, I'll first present the complicated answer that is
most "right" in the clever sense of the word, though rarely the most practical
answer. This answer is in terms of places and vicinities.

tblPlace
* PlaceId Autonumber
PlaceName Text(45)

tblPlaceRelation
* PlaceRelationId Autonumber
MilesApart Double

tblPlaceRelationLink
* PlaceRelationId Long
* PlaceId Long
LinkNum Byte

Now, also create a unique index on tblPlaceRelationLink comprising
PlaceRelationId and LinkNum, and make a constraint on LinkNum only allowing
values 1 or 2. The code that creates the 2 tblPlaceRelationLink records for a
relation must assign LinkNum 1 to one record, and 2 to the other (it doesn't
matter which is which).

Notice that, if it weren't for the LinkNum value, there would be no difference
between the relationships between "Place A" to "Place B" and "Place B" to
"Place A", and the only purpose of LinkNum is so its rules enforce that only 2
places can be associated in a single relation. You can query all the
vicinity-relatives of a place using a query something like the following:

SELECT PLACE2.*, tblPlaceRelation.MilesApart
FROM ((( tblPlace AS PLACE1
INNER JOIN tblPlaceRelation AS PLACE_REL_LINK1
ON PLACE1.PlaceId = PLACE_REL_LINK1.PlaceId
) INNER JOIN tblPlaceRelation AS PLACE_REL_LINK2
ON PLACE_REL_LINK1.PlaceRelationId =
PLACE_REL_LINK2.PlaceRelationId
) INNER JOIN tblPlace AS PLACE2
ON PLACE_REL_LINK2.PlaceId = PLACE2.PlaceId
) INNER JOIN tblPlaceRelation
ON PLACE_REL_LINK1.PlaceRelationId =
tblPlaceRelation.PlaceRelationId
WHERE PLACE1.PlaceId=[startfromplaceid] AND
PLACE2.PlaceId <> PLACE1.PlaceId

Yup - it's kinda ugly. Also, this schema has no way of enforcing that all the
records comprising a 2-way relationship are created, so it's possible to have
1/2 a relationship defined if a code error occurs. Each possible alternative
schema has its own kind of ugliness, though.

Now, a suggestion that might actually be useful <g>:

One of the more practical alternatives is to use a simple junction table, but
always create a matching entry going in the opposite direction to any relation
created. The application code (or possibly a trigger if you're using a server
database) must keep any data about the relation (such as distance in this
case) in sync between the 2 complimentary junction records or have some
hueristic to decide which of the 2 records is treated as the official junction
data container.

On Tue, 5 Apr 2005 23:09:33 +0200, "MDS" <md*********@yahoo.co.uk> wrote:
All,

I am endeavouring to implement an "Also in the area" feature to an
Access 97 DB.

Within the table, there are two columns drawn from the same domain -
let's call them Place A and Place B. Place A and Place B form the
composite primary key.

When the user enters "Place A" is in the area of "Place B," it should
not be necessary to insert a second record stating "Place B" is in the
area of "Place A" as this can be infered from the first statement.

Therefore, the initial A/B entry should also reflect the uniqueness of
A/B as, in effect, an unordered pair.

Can this be implemented in Access? If so, how?

Thanks for your help in this,
Mark


Nov 13 '05 #2

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

Similar topics

14
by: Neil Zanella | last post by:
Hello, I would like to ask how come the design of C++ includes std::pair. First of all I don't think many programmers would use it. For starters, what the first and second members are depends...
1
by: Puvendran Selvaratnam | last post by:
Hi, First of all my apologies if you have seen this mail already but I am re-sending as there were some initial problems. This query is related to defining indexes to be unique or not and...
3
by: JustSomeGuy | last post by:
in the stl map class I see the use of a function pair and make_pair. What is the difference between pair and make_pair? dictionary.insert(std::pair<Key, Value>(k,v)); works as well as: ...
2
by: Dirk Declercq | last post by:
Hi, Is it possible in Xml to enfore the uniqueness of an element based on his attribute value. Say I have this schema : <?xml version="1.0" encoding="UTF-8"?> <xs:schema...
1
by: Mr. Almenares | last post by:
Hello: I’m trying to do a schema with recurrent structure for a Book like a Node can have many Nodes inside or One leave. So, the leaves have an attribute that is Identifier. My goal is define...
4
by: Florent Garcin | last post by:
Hello! I would like to use the map structure with a key of Pair<string, string> and an int as the value. Pair is defined as: template <class T1, class T2> class Pair {
5
by: Alan Little | last post by:
I have affiliates submitting batches of anywhere from 10 to several hundred orders. Each order in the batch must include an order ID, originated by the affiliate, which must be unique across all...
1
by: ctoo | last post by:
The following compiles and works with g++ 3.4.4 and Borland C++ Builder 6 update#4: #include <iostream> #include <vector> #include <utility> // declaration and definition for primary class...
10
by: Alex Vinokur | last post by:
Hi, Is it possible to do C++-casting from const pair<const unsigned char*, size_t>* to const pair<unsigned char*, size_t>* ? Alex Vinokur
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.