views:

26

answers:

1

I want to store domain names(example:google.com - without "http://" and "www")in MySQL as primary key+Index.

so when I call a domain through PHP I should get the result according to that domain faster. Right now I am inserting domain in plain text.

is it right way to do it?? or do I need to hash it??

your Ideas please

+2  A: 

I think you should not use char/varchar in primary index. Rather create an int PK and domain column with unique constraint.

I think that would work in your case.

Checkout some reasons here:

http://stackoverflow.com/questions/164991/char-or-varchar-as-primary-key-in-an-isam-mysql-table

http://forums.mysql.com/read.php?153,243809,243818#msg-243818


EDIT

Here is the sample table. I created this table on assumptions. Change it according to your need.

CREATE  TABLE IF NOT EXISTS `test`.`sample` (

  `id` INT NOT NULL AUTO_INCREMENT ,

  `domains` VARCHAR(100) NOT NULL ,

  PRIMARY KEY (`id`) ,

  UNIQUE INDEX `domains_UNIQUE` (`domains` ASC) );

P.S. Created using mysql workbench.

Krunal
can you draft a sample table?? I am not very familiar with MySQL
mathew
@mathew - checkout updated answer.
Krunal
Great Thanks?? one question why domains_UNIQUE?? you already mentioned as UNIQUE INDEX
mathew
@mathew - It is name of the index.
Krunal
OH...Thanks man
mathew