473,773 Members | 2,277 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1584
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)

tblPlaceRelatio n
* PlaceRelationId Autonumber
MilesApart Double

tblPlaceRelatio nLink
* PlaceRelationId Long
* PlaceId Long
LinkNum Byte

Now, also create a unique index on tblPlaceRelatio nLink comprising
PlaceRelationId and LinkNum, and make a constraint on LinkNum only allowing
values 1 or 2. The code that creates the 2 tblPlaceRelatio nLink 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.*, tblPlaceRelatio n.MilesApart
FROM ((( tblPlace AS PLACE1
INNER JOIN tblPlaceRelatio n AS PLACE_REL_LINK1
ON PLACE1.PlaceId = PLACE_REL_LINK1 .PlaceId
) INNER JOIN tblPlaceRelatio n AS PLACE_REL_LINK2
ON PLACE_REL_LINK1 .PlaceRelationI d =
PLACE_REL_LINK2 .PlaceRelationI d
) INNER JOIN tblPlace AS PLACE2
ON PLACE_REL_LINK2 .PlaceId = PLACE2.PlaceId
) INNER JOIN tblPlaceRelatio n
ON PLACE_REL_LINK1 .PlaceRelationI d =
tblPlaceRelatio n.PlaceRelation Id
WHERE PLACE1.PlaceId=[startfromplacei d] 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*********@ya hoo.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
45866
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 on what you are using the pair for. For instance if I am using coordinates in two dimensional space then I like to use x and y. So I might as well define my own struct with x and y members in it and create a constructor so
1
2974
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 consequences thereof. Some documented facts that I am aware of include
3
14023
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: dictionary.insert(std::make_pair<Key, Value>(k,v));
2
2164
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 targetNamespace="http://www.egemin.com/Epia/StringResources" xmlns:xs="http://www.w3.org/2001/XMLSchema"
1
1565
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 Uniqueness that guarantees to the attribute Identifier his uniqueness. That I don’t know the depth of levels I have to put in the xpath attribute of the selector something like this TOC/descendant::Tree/Data, but this is not allow. How I can...
4
3451
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
2588
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 orders in all batches ever submitted by that affiliate. I'm trying to figure out the most efficient way to check the uniqueness of the order ID. Order data is being submitted to Zen Cart, and also stored in custom tables. I have created a unique...
1
1622
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 template template <class T> class A
10
3790
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
0
9621
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9914
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8937
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7463
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4012
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.