2011-12-09 26 views
0

我在我的項目中使用了grails 1.2.2和1.3.7。 我想添加一個索引到域的表。Grails將域字段添加爲數據庫索引

class Test { 
String name 
String surname 

static mapping = { 
name column: 'name', index: 'test_dx' 
surname column: 'surname', index: 'test_dx' 
} 

}

我試圖與這兩個版本的Grails與dbCreate的=「創造」或dbCreate的=「創建降」或dbCreate的=「更新」(是一個我想用)但沒有創建「自定義索引」。

+0

你想要一個特定類型的索引,例如一個獨特的索引? –

+0

對於第一步,我只需要一個索引,而不是唯一的。 下一步應該定義一些獨特的索引(例如:姓和名應該是唯一的) – Mcgyver83

回答

1

你的例子適合我。如果我跑我的應用程序在update模式,MySQL數據庫,然後我從MySQL控制檯中看到這一點:

mysql> show index from test; 
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ 
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | 
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ 
| test |   0 | PRIMARY |   1 | id   | A   |   0 |  NULL | NULL |  | BTREE  |   | 
| test |   1 | test_dx |   1 | name  | A   |   0 |  NULL | NULL |  | BTREE  |   | 
| test |   1 | test_dx |   2 | surname  | A   |   0 |  NULL | NULL |  | BTREE  |   | 
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ 
3 rows in set (0.00 sec) 

什麼數據庫您使用的?

+0

我正在使用Oracle 10g – Mcgyver83

相關問題