12

I used the same command syntax above as in Mysql and would like set a unique key for the tables's filed on Android Device environment, however, the error prompted in LogCat:

03-23 16:16:45.580: E/Database(657): Failure 1 (near "UNIQUE": syntax error) on 0x2c0240 when preparing 'ALTER TABLE game ADD UNIQUE(name);'.

Checking the SQLite's doc, it seems that SQLite does not use this way for setting a unique key. Does anyboy know to do it ? Thanks for response inadvance !

cmh
  • 271
  • 1
  • 4
  • 17
  • 1
    possible duplicate of [Can column constraints be altered after creation in SQLite?](http://stackoverflow.com/questions/19079608/can-column-constraints-be-altered-after-creation-in-sqlite) – sashoalm Dec 02 '13 at 16:07

1 Answers1

35

sqlite support alter in another way. You can try the following: create unique index unique_name on game(name); If you want to create a constraint for two or more columns at one time: create unique index unique_name on game(name1,name2,mame3);

Josh Matthews
  • 12,816
  • 7
  • 36
  • 39
ronando_lu
  • 366
  • 3
  • 2