Mysql composite pk (two int + string)

Hi,
What do you about this way
to set up a primary key ?


 CREATE TABLE IF NOT EXISTS `product_click` (
  `product_id` int unsigned NOT NULL,
  `user_id` int unsigned NOT NULL,
  `link` varchar(255) NOT NULL,
  `date` datetime NOT NULL,
  `clicks` int unsigned NOT NULL default '1',
  PRIMARY KEY  (`product_id`,`user_id`,`link`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

I found it in a project I’m
working on and imho it’s
not a good choice.

Bye.

i think it’s excellent

what would you do instead?

I would have chosen a simple id autoincrement
but I think from your reply isn’t a good way
to go through :slight_smile:
In my opinion wasn’t a good choice because of the
varchar field.
But peeping into the code I saw


INSERT INTO lp_mail_click (product_id,user_id,link,date) VALUES ($product_id,$user_id,$link,$date)
  ON DUPLICATE KEY UPDATE date = " . $date . ", clicks=clicks+1";

so now I can see the light :slight_smile:

As usual thanks for the reply.