faqts : Computers : Databases : MySQL : Language and Syntax

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

4 of 8 people (50%) answered Yes
Recently 4 of 8 people (50%) answered Yes

Entry

Do you need a PRIMARY KEY or other way to specify a unique value in a MySQL row?

Mar 15th, 2004 10:28
Matt Chatterley, mike gifford,


In order that you can be guaranteed to uniquely identify a given ROW in
a table, you must assign a primary key to that row - this is both a
unique value used to identify the row (e.g. UserID in a 'users' table),
and an index for look-ups against this identification.
If you wanted to ensure a particular column was unique, you would need
to add a UNIQUE INDEX to the table:
ALTER TABLE Table1 ADD INDEX index_name UNIQUE (Unique_Column);