I'm messing around with databases and tables and I made a table names 'users' with columns like userid (primary & auto increment), username, etc, and I have one called verified which i set as a boolean (tinyint) and default value defined to 0. The problem is when I made this column it automatically tried to make it a primary key and require unique. I obviously don't want either of the 2 to be the case but it won't let me switch it! If I go in and edit the column and change it to text, however, it doesn't assume this PK value or the other things. I'm really confused why this keeps happening. Any ideas?
EDIT: Wait, does gold key mean not primary? I'm getting really confused.
I'd guess so. Since using an autoincrement requires that the PK be in use, and that PK is not in gold, that would suggest that phpmyadmin uses gold to mark what is not a pk.
I haven't used phpmyadmin in a long long time. You could simply issue a SHOW CREATE TABLE yourtablename query and it will give you the text required to create it. That would indicate all your keys as well.
I grant you that this is not normal usage, but it's perfectly legal.
I'll be damned, this whole time I thought that you required PK for ai in mysql!
Would there be any benefit of doing the above instead versus swapping the PK and UK on that table? I typically don't use AI at all as I don't usually use a surrogate key, but this may become beneficial in the future for an alternate field I would want to increment.
With the InnoDB storage engine, the table data is physically organized to do ultra-fast lookups and sorts based on the primary key column or columns.
In other words, the primary key is placed FIRST in the record layout *AND* forms the basis of the B-TREE organization of the entire table.
SQL Server takes great pains to emphasize that choosing your primary key can make a huge difference in performance. MySQL isn't quite so sensitive, but it can still make a noticeable difference.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Still really confused, i just started over with a new table and I can't change primary keys or anything. Ugh!
I did show table and this is what I get:
Code:
CREATE TABLE `users` (
`userid` int(11) NOT NULL AUTO_INCREMENT,
`uname` text NOT NULL,
`pword` text NOT NULL,
`email` text NOT NULL,
`nickname` text NOT NULL,
`verified` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`userid`),
UNIQUE KEY `userid` (`userid`),
KEY `userid_2` (`userid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
I *think* the query looks correct (except what is "KEY `userid_2` (`userid`)")... But this is what it actually shows:
Wow that was quite the process. Not sure what all went down but I must say I find it strange that the PK is denoted by a silver key. Seems as though it should be the gold. Anyways... I was clearly pressing SOMETHING wrong.. although I'm not sure what, I think it was successful this time. Really was not looking forward to re-installing. Does this look right to you too (the show turned up identical)? Also, does setting a value at the PK automatically set it as UNIQUE? Because it doesn't show unique I don't think.