If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Unique column without indexing

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-10-05, 06:06
ManhQuynh ManhQuynh is offline
Registered User
 
Join Date: Feb 2005
Location: Sweden
Posts: 45
Unique column without indexing

Hi,

Is it possible to have a varchar column unique without indexing it?
My table looks like this:
CREATE TABLE `tbladvert` (
`adId` int(11) unsigned NOT NULL auto_increment,
`adSubject` varchar(150) NOT NULL default '',
`adDate` date NOT NULL default '0000-00-00',
`adImage` tinyint(1) NOT NULL default '0',
`adType` tinyint(1) NOT NULL default '0',
`adFrom` varchar(50) NOT NULL default '',
`adURL` varchar(255) NOT NULL default '',
PRIMARY KEY (`adId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

I would like to make adURL unique.

//M
Reply With Quote
  #2 (permalink)  
Old 03-10-05, 06:41
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
no, it's not, because that's how mysql implements unique constraints

what's wrong with indexing it?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 03-10-05, 11:43
ManhQuynh ManhQuynh is offline
Registered User
 
Join Date: Feb 2005
Location: Sweden
Posts: 45
Hi,

Thank you for the quick answer. It's no wrong with indexing it, except for I've heard that the more index you have in a table the slower the table will be to search in. Is it true?

//M
Reply With Quote
  #4 (permalink)  
Old 03-10-05, 12:35
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
that's just a general rule, but in your case having a unique index is actually a very good idea, since you have a surrogate (auto_increment) primary key
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 03-10-05, 20:41
ManhQuynh ManhQuynh is offline
Registered User
 
Join Date: Feb 2005
Location: Sweden
Posts: 45
Ok!
I'll need to search on adImage and adType in my table, should I index them aswell?

//M
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On