我有一个表创建,但我希望该组的名称是唯一的(为了防止重复)我该怎么做?这是我的查询创建。
db.execSQL("CREATE TABLE "+ tablemachine+" ("+
idMaquina +" INTEGER PRIMARY KEY AUTOINCREMENT, "
+ name+ " text not null, " //I want this field unique
....
答案 0 :(得分:0)
Just add "UNIQUE" like that
"CREATE TABLE "+ tablemachine+" ("+idMaquina +" INTEGER PRIMARY KEY AUTOINCREMENT, "
+ name+ " TEXT NOT NULL UNIQUE, " //I want this field unique
答案 1 :(得分:0)
您可以在列的末尾添加UNIQUE
`"CREATE TABLE "+ tablemachine+" ("+idMaquina +" INTEGER PRIMARY KEY
AUTOINCREMENT, "
+ name+ " TEXT NOT NULL UNIQUE, " //I want this field unique`
或添加约束,您的SQL应该如下所示
db.execSQL("CREATE TABLE "+ tablemachine+" ("+
idMaquina +" INTEGER PRIMARY KEY AUTOINCREMENT, "
+ name+ " text not null, constraint table_name_constraint unique
(name)) "