check if a column is unique

Hi,

I want to check if a column is unique using internal yii features. how?

There is the CUniqueValidator …

The user can even delete and recreate the index using a checkbox. I use createIndex() and dropIndex() to do that, but I need to check before to display the checkbox checked or not, so I need to check directly in the database. how can I do?

There is no such feature in Yii because Yii is not a DBMS and syntax of table manipulations may vary from one database to another.

To check if a column has a unique index in MySQL you can do something like this:




SHOW COLUMNS FROM `Tablename` WHERE `Field` = 'FieldName' AND `Key` = 'UNI'



Oh I didn’t notice methods to create tables and add indexes appeared in 1.1.6, but anyway I don’t see another way to check if a key is unique.

Thank you Andy!