Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite:"ALTER TABLE `game` ADD UNIQUE(`name`)" Error in SQLite

Tags:

sqlite

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 !

like image 680
cmh Avatar asked Mar 23 '12 16:03

cmh


1 Answers

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);

like image 91
ronando_lu Avatar answered Oct 24 '22 11:10

ronando_lu