Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2005
    Location
    Sweden
    Posts
    45

    Unanswered: 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

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    no, it's not, because that's how mysql implements unique constraints

    what's wrong with indexing it?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    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

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    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
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •