KEY上使用AUTOINCREMENT

KEY上使用AUTOINCREMENT

本文介绍了仅允许在INTEGER PRIMARY KEY上使用AUTOINCREMENT-Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在数据库中创建一个表,该表的ID本身会自动递增,但是每当我尝试向查询中添加AUTOINCREMENT关键字时,它就会告诉我:

I'm trying to create a table in my DB with an ID that is autoincrement itself but whenever I try to add the AUTOINCREMENT keyword to my query it tells me that :

这是我的查询:

@Override
public void onCreate(SQLiteDatabase db) {
    String sql = "CREATE TABLE IF NOT EXISTS " + TABLE_TASKS + " ( "
            + KEY_ID + "INTEGER PRIMARY KEY AUTOINCREMENT, "
            + KEY_NOTETITLE + " TEXT, " + KEY_NOTECONTENT + " Text, "
            + KEY_STATUS + " INTEGER)";
    db.execSQL(sql);
}

我也尝试编写AUTO_INCREMENT,但是随后出现语法错误.

I have also tried to write AUTO_INCREMENT but then I got syntax error.

我发现这是问题的根源,因为每当我尝试删除AUTOINCREMENT单词时,它就可以正常工作.

I found out that this is the source of the problem because whenever I try to remove the AUTOINCREMENT word it works fine.

所以...您认为出了什么问题?

So... what do you think is the problem?

推荐答案

您需要在KEY_IDINTEGER

所以改变

+ KEY_ID + "INTEGER PRIMARY KEY AUTOINCREMENT, "

+ KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "

这篇关于仅允许在INTEGER PRIMARY KEY上使用AUTOINCREMENT-Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 00:31