gpt4 book ai didi

java - 创建唯一复合列的语法 - Android SQLiteOpenHelper

转载 作者:太空宇宙 更新时间:2023-11-04 13:04:56 25 4
gpt4 key购买 nike

我的SQLiteOpenHelper中有这个onCreate方法类,我想在这两列上添加唯一约束(复合唯一列):

  • SongContract.SongEntry.COLUMN_TITLE
  • SongContract.SongEntry.COLUMN_RELEASEDATE

但是我收到错误:

Cannot resolve method UNIQUE

这是我的代码:

public void onCreate(SQLiteDatabase db) {
final String SQL_CREATE_SONG_TABLE = "CREATE TABLE " + SongContract.SongEntry.TABLE_SONG + " (" +
SongContract.SongEntry._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
SongContract.SongEntry.COLUMN_TITLE + " TEXT NOT NULL, " +
SongContract.SongEntry.COLUMN_RELEASEDATE + " INTEGER, " +
UNIQUE(SongContract.SongEntry.COLUMN_TITLE, SongContract.SongEntry.COLUMN_RELEASEDATE) +
SongContract.SongEntry.COLUMN_RATING + " TEXT);";

db.execSQL(SQL_CREATE_SONG_TABLE);
}

实现我的目标的正确语法是什么?

最佳答案

在使用 sqllite 后我发现了正确的语法:

最终字符串 SQL_CREATE_SONG_TABLE = "CREATE TABLE "+ SongContract.SongEntry.TABLE_SONG + "("+ SongContract.SongEntry._ID + "整数主键自动增量,"+ SongContract.SongEntry.COLUMN_TITLE + "文本不为空,"+ SongContract.SongEntry.COLUMN_RELEASEDATE + "INTEGER NOT NULL, "+ SongContract.SongEntry.COLUMN_RATING + "文本, "+ "唯一"+ "("+ SongContract.SongEntry.COLUMN_TITLE + ","+ SongContract.SongEntry.COLUMN_RELEASEDATE + ") "+ ");";

关于java - 创建唯一复合列的语法 - Android SQLiteOpenHelper,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34578724/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com