Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

This is how I have designed:

visitorID
visitedprofileID
datetime

Is it a good idea to add an ID (primary key) to the table, I mean recordID (primary key).

(MySQL with PHP)

share|improve this question
    
Is date type datetime? –  Jack Douglas Sep 28 '11 at 12:04
    
@JackDouglas, yes, it is datetime –  ilhan Sep 28 '11 at 12:07
    
You might be interested in this thread: dba.stackexchange.com/questions/6108/… –  Derek Downey Sep 28 '11 at 12:32

1 Answer 1

I think your two choices here are:

  1. make the (visitorID,visitedprofileID) combination a primary key

  2. add a recordID as primary key

If the table is InnoDB (or it will be in the future for Foreign Key usage), I would go with the second option. Given the way InnoDB handles indexing by adding the primary key to secondary indexes for lookup, if you ever wanted to add an index on datetime, the single field would result in a smaller index.

share|improve this answer
    
+1 for InnoDB info and smaller index observation. BTW Option 1 would be great for MyISAM since you could auto_increment visitorID sequentially within visitedprofileID. –  RolandoMySQLDBA Sep 28 '11 at 14:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.