Reputation: 93
I need to save Url´s as unique key in table:
CREATE TABLE urls (
id int(5) NOT NULL auto_increment,
url text(2000) NOT NULL,
date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id),
UNIQUE KEY (url)
);
I cant import this to my phpmyadmin, i get error because of the
UNIQUE KEY (url)
Anybody could give me an advice how to save url´s as unique key´s in database?
GReetings
Upvotes: 0
Views: 1119
Reputation: 3119
You have to specify key's length so that Mysql can guarantee the uniqueness of the column. However if you try something like this,
CREATE TABLE urls (
id int(5) NOT NULL auto_increment,
url text(1000) NOT NULL,
date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id),
UNIQUE KEY (url(1000))
);
you will get an error: "Specified key was too long; max key length is 767 bytes" which according to http://dev.mysql.com/doc/refman/5.1/en/create-index.html is indeed the limit of InnoDB tables' columns. Thus I would suggest that you change your column lenght to 767 bytes.
Upvotes: 1