How do I?

admin

Administrator
Staff member
make a unique key in mysql? If you have a table that has a username and password field in mysql how do you make the username field unique.

I have searched the internet and tried numerous code such as the following.

CREATE TABLE users (
user_id int(32) unsigned NOT NULL DEFAULT '0' auto_increment,
user_name varchar(16) NOT NULL,
password varchar(16) NOT NULL,
PRIMARY KEY (user_id),
UNIQUE idx_user_id (user_id),
KEY (user_name),
UNIQUE idx_user_name (user_name)
);


phpmyadmin will not accept any of the SQL statements I put in to create a table with a unique field. I am beginning to think it is not possible. Does anyone have any SQL code that works in mySQL for creating unique fields??

Thanks.
 
Back
Top