Professional Web Applications Themes

key on more table - MySQL

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: [email]thinkmarcoyahoo.it[/email] ------- --- 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. [url]http://www.avast.com[/url]...

  1. #1

    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: [email]thinkmarcoyahoo.it[/email]
    -------


    ---
    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.
    [url]http://www.avast.com[/url]



    myname@yahoo.it Guest

  2. #2

    Default Re: key on more table

    [email]mynameyahoo.it[/email] 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.
    [email]jstucklexattglobal.net[/email]
    ==================
    Jerry Stuckle Guest

  3. #3

    Default Re: key on more table

    Jerry Stuckle wrote:
    > [email]mynameyahoo.it[/email] 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//
    Christian Kirsch Guest

  4. #4

    Default Re: key on more table

    [email]mynameyahoo.it[/email] 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.
    Dikkie Dik Guest

Similar Threads

  1. Replies: 0
    Last Post: September 16th, 04:37 PM
  2. Replies: 0
    Last Post: September 10th, 10:49 PM
  3. Replies: 0
    Last Post: September 10th, 05:33 PM
  4. Replies: 0
    Last Post: September 10th, 05:29 PM
  5. Replies: 2
    Last Post: August 12th, 07:55 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139