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


SongContract.SongEntry.COLUMN_TITLE
SongContract.SongEntry.COLUMN_RELEASEDATE


但我收到一个错误:


  无法解析方法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 +“ TEXT NOT NULL,” +
            SongContract.SongEntry.COLUMN_RELEASEDATE +“ INTEGER NOT NULL,” +
            SongContract.SongEntry.COLUMN_RATING +“ TEXT,” +“ UNIQUE” +“(” +
            SongContract.SongEntry.COLUMN_TITLE +“,” + SongContract.SongEntry.COLUMN_RELEASEDATE +“)” +“);”;

09-28 09:40