Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Another SQL Question
Message
De
12/07/2005 11:22:36
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01031642
Message ID:
01031708
Vues:
11
Consider you manage multiple banks in a central database.

Banks: BankID, ...
Customers: CustomerID, ...

A person might be a customer of more than one bank and a bank has multiple customers. This constitute a many-to-many relationship and you create an intermediate 'link' table:

BankCustomer: BankID,CustomerID

With your phones this would be true if a phone number might be shared by multiple contacts (yes, why not all or some members of a family might be customers of some shop and you own a chain of shops). I suggest simply to hold:
PhoneContact: PhoneID,ContactID

If it's a strict one-to-many match then you don't need the intermediate table (PhoneContact).
Cetin


>>However I suggest you to rethink about this design. Instead of holding multiple link
>>info in a single table having them in separate files is better IMHO (and if it's not
>>for supporting many-to-many completely remove links for these 2 tables).
>
>Not sure I understand. Could you elaborate a bit more?
>
>
>
>
>
>
>
>>>I have a Contacts table. I also have a Phones table. They are related
>>>through a Links table. I would like to pull the client record, and have
>>>all the phone numbers on the client record.
>>>
>>>Anyone?
>>>
>>>
>>>The relationships:
>>>
>>>Contacts
>>>   |
>>>   -< Links
>>>       |
>>>       -< Phones
>>>
>>>
>>>
>>>The structures:
>>>
>>>Contacts
>>>RecordId  FName   LName
>>>-----------------------------------------------------
>>>00000001  Joe     Smith
>>>
>>>Links
>>>RecordId  ParentId  DataId    Key
>>>-----------------------------------------------------
>>>AAAAAAAA  00000001  ZZZZZZZZ  "phone"
>>>AAAAAAAA  00000001  QQQQQQQQ  "phone"
>>>AAAAAAAA  00000001  FFFFFFFF  "phone"
>>>
>>>
>>>Phones
>>>RecordId  Caption         Phone       Last
>>>-----------------------------------------------------
>>>ZZZZZZZZ  Home            8005551212  .T.
>>>QQQQQQQQ  Business        8001212555  .T.
>>>FFFFFFFF  Cell            8885544877  .T.
>>>
>>
>>
>>select Contacts.*, Phones.Caption, Phones.Phone ;
>>  from Contacts ;
>>  left join links on Contacts.RecordId = Links.ParentID ;
>>       and Links.Key == 'phone' ;
>>  left join Phones on Links.DataID = Phones.RecordID
>>
>>However I suggest you to rethink about this design. Instead of holding multiple link info in a single table having them in separate files is better IMHO (and if it's not for supporting many-to-many completely remove links for these 2 tables).
>>Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform