www.webdeveloper.com
Results 1 to 4 of 4

Thread: [RESOLVED] Mysql, text fields and primary keys

  1. #1
    Join Date
    Jul 2003
    Posts
    259

    resolved [RESOLVED] Mysql, text fields and primary keys

    Hi,

    Does anyone know if it's possible to create a table and make a text field its primary key in mysql?

    Thanks

  2. #2
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    I can't seem to find anything saying one way or another, but my thought is no, they can't. My rationale is that any key on a TEXT/BLOB type requires a prefix, making a primary key from a prefix wouldn't be sensible.

    Really your PK should be an immutable representation of the tuple that is this row.
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

  3. #3
    Join Date
    Jul 2003
    Posts
    259
    So... when I went home me and my brother tried a few things and it seems that as long as you make a key no larger than 1024 k (I believe that's the size) a text field can be a key. So some rudimentary math came along and I think that's something close to 124 or 125 characters (can't remember exactly... divide 1024 by 8 and you'll get it). So as long as you limit it to that many characters when you create the field you're good to go.

  4. #4
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    right, like i was saying it would be a finite size. text has no actual restriction on how much can be stored in it, based on how mysql has handled it. of course, this all goes away if you come back and say that you meant VARCHAR instead of TEXT.
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles