The method for resetting the auto-numbered column in SQLite.

Source: Internet
Author: User

The method for resetting the auto-numbered column in SQLite.

Currently, all popular databases provide automatic numbers, and SQLite is no exception. When the database contains an automatically numbered field, SQLite automatically creates a table named sqlite_sequence. This table contains two fields: name and seq. The name field records the table where the automatic number field is located, and the seq field records the sequence number currently used (the number of the next record is the current sequence number plus 1 ).

During the development process, we often need to reset the table. That is to say, clear all records in the table and set the automatic number to 0. In SQLite, you only need to modify the sqlite_sequence table:
Copy codeThe Code is as follows:
UPDATE sqlite_sequence SET seq = 0 WHERE name = 'tablename'

You can also delete the record directly:
Copy codeThe Code is as follows:
Delete from sqlite_sequence WHERE name = 'tablename'

To reset all tables, simply clear sqlite_sequence:
Copy codeThe Code is 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.