Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8268375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:51:54+00:00 2026-06-08T05:51:54+00:00

I have a question about deleteAll() function. I’m using a key with autoincrement property

  • 0

I have a question about deleteAll() function. I’m using a key with autoincrement property for my database. When I delete all rows from my db, it deletes everything. But when I insert a new row, key doesn’t start from 1, for example before deletion key was 15, new key becomes 16 instead of 1 after deletion. How can I fix this? Any suggestions?

here my codes

 public int deleteAll(){

 return sqLiteDatabase.delete(MYDATABASE_TABLE, null, null);

 }

   public void onCreate(SQLiteDatabase db) {

  db.execSQL(SCRIPT_CREATE_DATABASE);

 }

And my database script

private static final String SCRIPT_CREATE_DATABASE =

     "create table "
                + MYDATABASE_TABLE + "("
                + KEY_ID + " integer primary key autoincrement, " 
                + COLUMN_NAME + " text not null, " 
                + COLUMN_EMAIL + " text not null, "
                + COLUMN_PHONE + " text not null, "
                + COLUMN_ADDRESS + " text not null"
                + ");";
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T05:51:56+00:00Added an answer on June 8, 2026 at 5:51 am

    Your code shouldn’t depend on the value of the auto-incremented key.

    For displaying to the user, use a separate counter when you iterate the database cursor. Users generally don’t need to know the key, but just a serial number. Both of them can be different.

    But if you do insist on restarting the key value, try dropping the table and recreating it. But beware of the old key values being used in other tables as foreign keys. Use triggers to handle such cases.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about the images displaying using a function getImage_w($image,$dst_w), which takes
I have question about XSLT1.0. The task is to write out in HTML all
I have a question about this formula from a book: EFW (cm,kg)= 10^(-1,7492+(0,166*BPD)+(0,046*AC)-(2,646*AC*BPD/1000)) The
I have question about database optimizing, indexing. I have table that called projects and
I have a question about the IsolatedStorageSettings in WP7. normally i parsed all my
I have question about sending emails from MVC3 application. I already read for exmple
I have question about how I can save the result of function I have
I have question about python and sqlite3. I want to drop a table from
I have question about removing element from QList. myclass.h: class node2D : public QObject
I have question about parsing in Html helper : I have sth like: @foreach

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.