okay...I have searche and read and all tons of crap and I still cannot get an answer to this one. I know WHAT an primary key, index, and unique is but can someone please explain HOW an INDEX is used.
for example this is a table I have:
CREATE TABLE `users` (
`id` INT( 4 ) UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT ,
`username` VARCHAR( 20 ) NOT NULL ,
`md5pass` VARCHAR( 32 ) NOT NULL ,
`userlevel` ENUM( '0', '1', '2' ) DEFAULT '1' NOT NULL ,
`real_first` VARCHAR( 25 ) NOT NULL ,
`real_last` VARCHAR( 25 ) NOT NULL ,
`profile` LONGTEXT NOT NULL ,
PRIMARY KEY ( `id` )
);
I know that the PRIMARY KEY is what I can use to identify say...two people with the same first name...but I was thinking why do I need a id if I am going to have unique usernameS? I don't have that set in the table cause I have it in my code:
$name_check = mysql_query("SELECT * FROM users WHERE username='$u_name'");
if (mysql_num_rows($sql_username_result) > 0){
$loginerror = "That username has already been taken. Please pick another!";
header("Location: index.php?pg=create");
} else { //the insert crap...
So what type of key(s) would you recomend for this particular table....and where should I put'em.
Thanks a ton in advance...