Method of resetting AutoNumber columns in SQLite _sqlite

Source: Internet
Author: User
Tags sqlite

The current popular database provides automatic numbering type, SQLite is no exception. When an AutoNumber field is included in the database, SQLite automatically creates a table named Sqlite_sequence. This table contains two fields: Name and seq. The Name field records the table in which the AutoNumber field is located, and the SEQ Field records the currently used ordinal (the next record is the current ordinal number plus 1).

In the development process, we often have to reset the table. This means that all the records in the table are emptied and the automatic number is returned to 0. In SQLite, you just need to modify the Sqlite_sequence table:

Copy Code code as follows:

UPDATE sqlite_sequence SET seq = 0 WHERE name = ' TableName '

You can also delete the record directly:
Copy Code code as follows:

DELETE from sqlite_sequence WHERE name = ' TableName '

If you want to reset all the tables, just empty the sqlite_sequence:
Copy Code code as follows:

DELETE from Sqlite_sequence

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.