Jump to content


Photo

MySQL UNIQUE


  • Please log in to reply
4 replies to this topic

#1 johnnyk

johnnyk
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 26 June 2006 - 12:45 AM

What's the difference between UNIQUE and PRIMARY KEY?
Rediscover the Web:
<a href="http://www.spreadfir...;t=219"></a><br />

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,025 posts

Posted 26 June 2006 - 06:50 AM

A table can have only one PRIMARY KEY and it is always UNIQUE.

You can also have several other indexes which may be UNIQUE or not.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 johnnyk

johnnyk
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 26 June 2006 - 07:51 PM

So if I just need one unique column, should I use primary key?
Also, I saw a tutorial online that defined one column as primary key and unique id. It looks like this:
create table myBlobs
(
blobId int auto_increment not null,
blobTitle varchar(50),
blobData longblob,
blobType varchar(50),
primary key(blobId),
unique id(blobId)
);
[a href=\"http://www.devarticles.com/c/a/MySQL/Blobbing-Data-With-PHP-and-MySQL/1/\" target=\"_blank\"]http://www.devarticles.com/c/a/MySQL/Blobb...HP-and-MySQL/1/[/a]

Why would they define it as primary key and unique?
Rediscover the Web:
<a href="http://www.spreadfir...;t=219"></a><br />

#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,025 posts

Posted 26 June 2006 - 08:44 PM

Because they don't know what they are doing.

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]So if I just need one unique column, should I use primary key?[/quote]
Yes
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 johnnyk

johnnyk
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 26 June 2006 - 09:47 PM

[!--quoteo(post=388209:date=Jun 26 2006, 04:44 PM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Jun 26 2006, 04:44 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Because they don't know what they are doing.
[/quote]
Hah. Alright, thanks.

Rediscover the Web:
<a href="http://www.spreadfir...;t=219"></a><br />




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users