Hi,
I want to know what's the difference between Unique and primary key in mysql?
for example what's difference between using Unique for Username Field (in user table ) or primary?
Thanks
regards
| SitePoint Sponsor |
Hi,
I want to know what's the difference between Unique and primary key in mysql?
for example what's difference between using Unique for Username Field (in user table ) or primary?
Thanks
regards


in mysql? nothing




Columns in a unique constraint may be null, which is not allowed for primary key columns.

also, the auto_increment feature requires a primary index.
More than one field in a table may be unique for a record. One can be the primary key, for the other you'd use the unique constraint.
membership_no, name, address, telno, locker_no
membership_no is unique and the primary key
locker_no is also unique in the table, as no-one shares lockers. (assumes old members who used the locker last year are deleted)
Thanks All,
very useful tips.
Bookmarks