views:

76

answers:

3

Hi Guys,

I have a problem with MySql primary keys, it's for my project i'm working on now!

i have to have a unit name(not a number)as a key in my database, it is a combination of letters and numbers, i can't use any primary key in INT type, where it increments as usual!

what is better? should i stick to old INT, auto increment way?

or it's better to use a VARCHAR to primary key? if so what is the ideal data type?

regards, Rangana

+4  A: 

You can keep the primary key as an auto-inc integer column, and then add another column which is a VARCHAR column with a UNIQUE constraint on it.

Amber
+3  A: 

an auto-incrementing integer primary key is preferred. It's meaningless so it will never change (and possibly cause problems).

Galen
+2  A: 

The shorter column size the better for a key in general. So, use an auto incremental integer as a primary key and a unique index for the name.

Vasileios Lourdas