key on more table

This is a discussion on key on more table within the MySQL Database forums, part of the Database Forums category; Hi, do you know how can I declare a key on more tables? For example, if I have the table ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-15-2005
myname@yahoo.it
 
Posts: n/a
Default key on more table

Hi,
do you know how can I declare a key on more tables?

For example, if I have the table TABLE1 and the table TABLE2, every one
with a field called key, how can OI declare in mysql that the key is
composed of TABLE1.key AND TABLE2.key?

Thanks a lot
Marco Righi

--
-------
email: thinkmarco@yahoo.it
-------


---
avast! Antivirus: In partenza messaggio pulito.
Virus Database (VPS): 0546-1, 15/11/2005
Controllato il: 15/11/2005 14.06.45
avast! - copyright (c) 1988-2005 ALWIL Software.
http://www.avast.com



Reply With Quote
  #2 (permalink)  
Old 11-15-2005
Jerry Stuckle
 
Posts: n/a
Default Re: key on more table

myname@yahoo.it wrote:
> Hi,
> do you know how can I declare a key on more tables?
>
> For example, if I have the table TABLE1 and the table TABLE2, every one
> with a field called key, how can OI declare in mysql that the key is
> composed of TABLE1.key AND TABLE2.key?
>
> Thanks a lot
> Marco Righi
>


Macro,

You can't. The purpose of a key is to uniquely identify a row in a
single table.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Reply With Quote
  #3 (permalink)  
Old 11-15-2005
Christian Kirsch
 
Posts: n/a
Default Re: key on more table

Jerry Stuckle wrote:
> myname@yahoo.it wrote:
>
>>Hi,
>>do you know how can I declare a key on more tables?
>>
>>For example, if I have the table TABLE1 and the table TABLE2, every one
>>with a field called key, how can OI declare in mysql that the key is
>>composed of TABLE1.key AND TABLE2.key?
>>
>>Thanks a lot
>>Marco Righi
>>

>
>
> Macro,
>
> You can't. The purpose of a key is to uniquely identify a row in a
> single table.
>


s/uniquely//
Reply With Quote
  #4 (permalink)  
Old 11-15-2005
Dikkie Dik
 
Posts: n/a
Default Re: key on more table

myname@yahoo.it wrote:
> Hi,
> do you know how can I declare a key on more tables?
>
> For example, if I have the table TABLE1 and the table TABLE2, every one
> with a field called key, how can OI declare in mysql that the key is
> composed of TABLE1.key AND TABLE2.key?
>
> Thanks a lot
> Marco Righi
>

I don't know what you are trying to accomplish, but if you want a key
that appears as a field in more than one table and is still unique in
all those tables, you can introduce an identity table.

This identity table "generates" the keys with an auto-increment field
(primary key), and it is referrred to by foreign keys in the tables that
"share" the relation. Any time a foreign key field needs to be written,
a row is inserted in the identity table and its last genereated ID is used.
This is no hard check for uniqueness: the code that adds records must
generate an ID first. The uniqueness comes from the fact that all
generated IDs are different.

When I first encountered an ID-only table in my own database scheme, I
had given it a really hard thought. Somehow it didn't feel right. But
every other option would have given me a worse scheme and now I think
there can be situations where it is useful.

Best regards.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:24 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0