Results 1 to 3 of 3

Thread: Dual Field Primary Key

  1. #1
    4x4
    Join Date
    Oct 2004
    Posts
    1,043

    Exclamation Dual Field Primary Key

    Has anyone ever used a primary key that's made up of two fields?

    I am using it because I want to utilize the "ON DUPLICATE KEY" ability MySQL provides for updating OR inserting a new row.
    (I am doing this now and it works great, my concern is in the future when more gets added to the table.)

    My concern is that the primary key is made up of the user_id and label_id. So, my concern is what if the user_id is 11 and the label_id is 22 that would make the primary key 1122. Now what if it was also checking a user_id of 1 and a label_id of 122 or any other way they can match up and over lap. Since they make up the SAME primary key will I run into issues or does mysql have a way to differentiate between them?


    -Todd

  2. #2
    Registered
    Join Date
    Aug 2006
    Location
    Sacramento, CA
    Posts
    208
    That will not cause a problem. It does not create keys by concatenating the string, both fields are stored in whatever format you have set for that field.

    For example if both user_id and label_id are INT (4 bytes) each key will store 8 bytes to uniquely identify that row.
    ________
    Fetish latex
    Last edited by rpanella; 03-17-2011 at 11:07 AM.

  3. #3
    4x4
    Join Date
    Oct 2004
    Posts
    1,043
    Quote Originally Posted by rpanella View Post
    That will not cause a problem. It does not create keys by concatenating the string, both fields are stored in whatever format you have set for that field.

    For example if both user_id and label_id are INT (4 bytes) each key will store 8 bytes to uniquely identify that row.
    Awesome.
    That's what I couldn't find on google (How it works).

    FWIW both fields are INT(11), expecting some big #s

Similar Threads

  1. dual monitors
    By Chris in forum General Chat
    Replies: 19
    Last Post: 11-12-2007, 01:10 PM
  2. Dual monitors
    By Cutter in forum General Chat
    Replies: 20
    Last Post: 02-15-2006, 02:58 PM
  3. Seeing if MySQL field Contains Digit
    By Mike in forum Website Programming & Databases
    Replies: 2
    Last Post: 12-20-2005, 09:22 AM
  4. Dual monitor rocks
    By s2kinteg916 in forum General Chat
    Replies: 31
    Last Post: 04-13-2005, 03:09 PM
  5. changing a field type in mysql
    By eMEraLdwPn in forum Website Programming & Databases
    Replies: 2
    Last Post: 02-06-2004, 10:13 PM

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
  •