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 > question about Unique

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-08-04, 06:53
sjl301 sjl301 is offline
Registered User
 
Join Date: Feb 2004
Location: London England
Posts: 8
question about Unique

Hello,

When defining a field as unique within a table, I understand that you use Unique(fieldname) when creating the table.

I'm using a BLOB to store a long string, and want these long strings to be unique. If I try to use Unique(type) (where type is a blob) I get the error:

Error 1170 Blob column 'type' used in key specification without a key length

Does anybody know how I can make ths Blob unique?

Cheerz,

Steve
Reply With Quote
  #2 (permalink)  
Old 03-08-04, 07:56
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Quote:
Only the MyISAM table type supports indexing on BLOB and TEXT columns. When putting an index on a BLOB or TEXT column you MUST always specify the length of the index:
Code:
CREATE TABLE test (blob_col BLOB, INDEX(blob_col(10)));
-- http://www.mysql.com/doc/en/CREATE_T...E TABLE Syntax
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 03-08-04, 08:17
sjl301 sjl301 is offline
Registered User
 
Join Date: Feb 2004
Location: London England
Posts: 8
I'm sorry, i'm a little confused!

How do I use the code:
CREATE TABLE test (blob_col BLOB, INDEX(blob_col(10)));

to make blob_col unique?
Reply With Quote
  #4 (permalink)  
Old 03-08-04, 08:21
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
i am confused about your confusion

since your table exists already, there's little point in using CREATE TABLE

you will probably want to try this --

ALTER TABLE yourtable
ADD UNIQUE(blob_col(10)));
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 03-08-04, 08:42
sjl301 sjl301 is offline
Registered User
 
Join Date: Feb 2004
Location: London England
Posts: 8
I am building the database at the moment fo a university project so am just dropping and recreating the whole database as it changes - that is why I am using create table.

I am currently creating the table as:

CREATE TABLE TOOL (toolNumber INT NOT NULL AUTO_INCREMENT, type BLOB, location VARCHAR(255), returnDate VARCHAR(30), PRIMARY KEY(toolNumber));

Now I want to change this so that the field type is unique.

The statments

CREATE TABLE test (blob_col BLOB, INDEX(blob_col(10)));

ALTER TABLE test
ADD UNIQUE(blob_col(10));

return the error:
ERROR 1061: Duplicate key name 'blob_col'
Reply With Quote
  #6 (permalink)  
Old 03-08-04, 08:53
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Quote:
The statments

CREATE TABLE test (blob_col BLOB, INDEX(blob_col(10)));

ALTER TABLE test
ADD UNIQUE(blob_col(10));

return the error:
ERROR 1061: Duplicate key name 'blob_col'
that should not really surprise you

you create an INDEX on the blob column, then attempt to add a UNIQUE index as well

may i suggest you define only one index on the column
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
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