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 7653351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:00:42+00:00 2026-05-31T12:00:42+00:00

In Android, I created an SQLite database containing one table, which in turn has

  • 0

In Android, I created an SQLite database containing one table, which in turn has an auto-increment ID column.

Suppose I have 4 records. When I delete all of them, the next inserted record has the ID of a 5th one (4), but I need to insert this record starting again from the 1st position, i.e. 0.

How can I achieve this?

  • 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-05-31T12:00:43+00:00Added an answer on May 31, 2026 at 12:00 pm

    EDIT: Maybe I should make it clear that just inserting the rows with the correct id instead of manipulating the sequence number definitely is a better idea than the below method. If there’s no row with id=3 in the table, you can just insert with a fixed value in the id even in an AUTOINCREMENT table.


    That said, if you’re really sure, you can set the auto increment value to any value using;

    UPDATE sqlite_sequence set seq=<next sequence no -1> where name=<table name>;
    

    That is, if you want AUTOINCREMENT on the next insert on table ‘TableA’ to generate 5, you do;

    UPDATE sqlite_sequence set seq=4 where name='TableA';
    

    Note that resetting seq behaves a bit different from what you may expect, it just means that the lowest id generated will be the greater of seq + 1 and the max id still in the table + 1.

    That is, if you delete all values >=5, you can reset the sequence value to 4 and have 5 generated as the next sequence number, but if you still have the id 10 in the table, the next number generated will be 11 instead.

    Maybe I should point out the fact that I cannot find this exact behavior documented anywhere, so I’d not rely on the behavior for every future version of sqlite. It works now, it may not tomorrow.

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

Sidebar

Related Questions

I have an sqlite database on android created like this: sqlite> .schema CREATE TABLE
i have created one android application that was connecting to sqlite database. and i
I have this error: 12-07 15:27:11.567: E/AndroidRuntime(15797): Caused by: android.database.sqlite.SQLiteException: no such column: recipient:
I created a SQLite database on Android device. The program can read/write to database
I created a sample application using android sqlite database, my requirements are How can
I have an SQLite3 Database (created in a desktop sqlite application), with the android_metadata
How can I edit an SQLite database after it has been created and stored
I am developing an android database application in which i have to add multiple
I have Created a database in Sqllite Android Application and I tried to add
I'm trying to insert some data in my Android SQLite freshly created Database with

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.