blanch wrote:
Hi all,
I'm pretty new to MySQL, but have some Access background. I've created
a table for which I intended the email column to be the primary key,
but didn't specify it at creation. Now, I'm trying to figure out how
to specify it post facto.
alter table add primary key (email_column);
http://dev.mysql.com/doc/mysql/en/ALTER_TABLE.html
But I have to point out that using email as a primary key isn't usually
an appropriate choice.
Is a given user's email address never going to change? If it can
change, how do other tables that reference this one make sure they
reference the correct record? You can enforce this behavior
automatically by declaring foreign keys with the ON UPDATE CASCADE
clause, but you have to remember to do that. And note that referential
integrity only works with InnoDB tables. See
http://dev.mysql.com/doc/mysql/en/In...nstraints.html
Sorry to make trouble! :-) I just want you to avoid difficulty later on.
It'd be better for data management to assign another column to be the
primary key. This column should have no significance other than its use
to uniquely identify the record. Therefore it has no reason to change
its value. It is customary to use an integer column for this purpose.
Regards,
Bill K.