PDA

View Full Version : [MySql] Problema ad inserire un indice su un campo di una tabella.


Rintrah84
18-06-2009, 18:36
Ho una tabella e voglio indicizzarne un campo, se faccio così mi dà un errore e non capisco perchè...cosa sbaglio nella sintassi?


mysql> CREATE INDEX Comune_Index USING unique ON comuni(comune);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use n
ear 'unique ON comuni(comune)' at line 1


Grazie
Andrea

CwNd
21-06-2009, 13:35
Dal manuale di mysql:


CREATE [UNIQUE|FULLTEXT|SPATIAL] INDEX index_name
[index_type]
ON tbl_name (index_col_name,...)
[index_type]

index_col_name:
col_name [(length)] [ASC | DESC]

index_type:
USING {BTREE | HASH | RTREE}


Come vedi "unique" non risulta essere un index_type :)

Forse volevi scrivere:

CREATE UNIQUE INDEX Comune_Index ON comuni(comune);

Ciao! :)