Home>

I deleted a multiple times (or cleared) a table with the Drop Table IF EXISTS command ... but, despite the fact that the records of only 3, Primary Key (_id) is not counting from 1 How can it be reset?

Here is the dbhelper code in which I create a database

package com.nikitafront.androidlarning;
Import android.content.context;
import android.database.sqlite.sqliteDatabase;
import android.database.sqlite.sqliteOpenHelper;
import androidx.annotation.nullable;
Public Class Dbhelper EXTENDS SQLiteOpenHelper {
Public Static Final int database_version= 1;
Public Static Final String Database_Name= "MyDatabase";
Public Static Final String Table_Name= "Users";
Public Static Final String Key_id= "_id";
Public Static Final String Key_Login= "_login";
Public Static Final String Key_Password= "_password";
Public Dbhelper (@NULLABLE CONTEXT CONTEXT) {
    Super (Context, Database_Name, Null, Database_Version);
}
@OVerride
Public Void OnCreate (SQLITEDATABASE DB) {
    DB.EXECSQL ("CREATE TABLE"
            + Table_Name + "("
            + Key_id + "Integer Primary Key AutoIncrement Not Null,"
            + Key_login + "Text,"
            + KEY_PASSWORD + "TEXT"
            + ");");
}
@OVerride
Public Void Onupgrade (SqliteDatabase DB, Int OldVersion, Int NewVersion) {
    DB.EXECSQL ("Drop Table If Exists" + Table_Name);
    ONCREATE (DB);
}

}

PRIMARY KEY (_ID) leads counting not with 1 Why do you care? If you need the sequence number of the entry in the table -there is RowID.

Akina2021-06-09 09:40:31