9

我正在尝试更改定义如下的 SQLite 表:

    String CREATE_TABLE="CREATE TABLE IF NOT EXISTS " + tab_NAME + " ("
                            + row_ID + " INTEGER PRIMARY KEY , "
                            + row_NAME + " TEXT, "
                            + row_EMAIL + " TEXT, "
                            + row_WEBSITE + " TEXT, "
                            + row_TELEPHONE1 + " TEXT, "
                            + row_TELEPHONE2 + " TEXT, "
                            + row_TELEPHONE3 + " TEXT, "
                            + row_TELEPHONE4 + " TEXT, "
                            + row_TELEPHONE5 + " TEXT);";
        db_name.execSQL(CREATE_TABLE);

        String newTab="CREATE TABLE IF NOT EXISTS temp ("
                + row_ID + " INTEGER PRIMARY KEY AUTOINCREMENT , "
                + row_NAME + " TEXT, "
                + row_EMAIL + " TEXT, "
                + row_WEBSITE + " TEXT, "
                + row_TELEPHONE1 + " TEXT, "
                + row_TELEPHONE2 + " TEXT, "
                + row_TELEPHONE3 + " TEXT, "
                + row_TELEPHONE4 + " TEXT, "
                + row_TELEPHONE5 + " TEXT);";
        db_name.execSQL(newTab);

这是 auto_increment alter 语句:

    String alter="ALTER TABLE temp AUTO_INCREMENT=1;";
    ourDatabase.execSQL(alter);

我有一个错误说(1) near AUTO_INCREMENT: syntax error

怎么了??有什么帮助吗??

4

2 回答 2

17

在 SQLite 中,声明为 INTEGER PRIMARY KEY 的列将自行自动递增。删除 AUTOINCREMENT 关键字,然后尝试。

检查SQLite 常见问题解答

于 2012-12-23T14:59:52.623 回答
4

sqlite将列设置PRIMARY KEYAUTOINCREMENT. 因此,无需将列明确指定为AUTOINCREMENT. 检查此链接以供参考。

于 2012-12-24T11:14:17.350 回答