Professional Web Applications Themes

primary key question involving use of strings. - MySQL

I want to have a unique ID for an entry in a table as a string something like "page.paragraph.token" where all three parts combine to make a unique identifier. Is it ok to also use this as a primary key or should I maintain an integer key too to be used as a foreign key from other tables? Any pointers appreciated....

  1. #1

    Default primary key question involving use of strings.


    I want to have a unique ID for an entry in a table as a string something
    like

    "page.paragraph.token"

    where all three parts combine to make a unique identifier.

    Is it ok to also use this as a primary key or should I maintain an
    integer key too to be used as a foreign key from other tables?

    Any pointers appreciated.
    Hadron Guest

  2. #2

    Default Re: primary key question involving use of strings.

    Hadron wrote: 

    You can use this as the primary key. But retrieving by the primary key
    will be slower.

    I normally use integer PK's, especially when this will be joined with
    other tables. I may or may not have an additional unique index.

    --
    ==================
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    net
    ==================
    Jerry Guest

  3. #3

    Default Re: primary key question involving use of strings.

    On Feb 27, 10:36 am, Jerry Stuckle <net> wrote: 




    >
    > You can use this as the primary key. But retrieving by the primary key
    > will be slower.
    >
    > I normally use integer PK's, especially when this will be joined with
    > other tables. I may or may not have an additional unique index.
    >
    > --
    > ==================
    > Remove the "x" from my email address
    > Jerry Stuckle
    > JDS Computer Training Corp.
    > net
    > ==================[/ref]

    just to be clear -
    a primary key can be made up of more than one field, so if you had a
    table like this:

    mytable(page,paragraph,token)

    where `token` was autoincrementing, for instance, then all three
    fields could combine to form the PK

    page paragraph token
    1 1 1
    1 1 2
    1 2 1
    1 3 1
    2 1 1
    2 1 2
    2 1 3
    etc

    strawberry Guest

  4. #4

    Default Re: primary key question involving use of strings.

    On Tue, 27 Feb 2007 10:57:43 +0100, Hadron wrote: 

    As a compound key, it won't have any particular disadvantages to this
    particular design. There are other challenges with compound keys which
    are general to the class, though.

    For the design and assuming that the doent doesn't change, it's okay.
    If the doent is subject to updating, you might have a good deal of
    fun maintaining the records.

    You may also want to consider exactly what you're attempting to retrieve
    from the table. In the case of (for example) a database-driven index, is
    that combination really unique? That is, might not the same passage
    belong to more than one possible search term?

    I do concur as well with Jerry's general recommendation for having a
    record ID integer for structure, on general principles.

    --
    47. If I learn that a callow youth has begun a quest to destroy me, I will
    slay him while he is still a callow youth instead of waiting for him to
    mature.
    --Peter Anspach's list of things to do as an Evil Overlord
    Peter Guest

Similar Threads

  1. Primary Scratch & Windows Primary Paging file?
    By Tommy Oberst in forum Adobe Photoshop 7, CS, CS2 & CS3
    Replies: 14
    Last Post: April 15th, 10:26 PM
  2. parsing strings - question
    By edhusar in forum Macromedia ColdFusion
    Replies: 2
    Last Post: May 25th, 11:39 PM
  3. Silly question about a strings in php
    By Kaspa in forum PHP Development
    Replies: 4
    Last Post: January 14th, 08:18 AM
  4. Changing Primary Index Question
    By Bill Hamilton in forum Informix
    Replies: 8
    Last Post: September 4th, 05:29 PM
  5. Replies: 12
    Last Post: August 3rd, 01:50 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