iOS Development database-SQLite clears the table and zeros the self-increment column

Source: Internet
Author: User
Tags sqlite database

Usually, when you clear the table, you also need to reset the self-increment column to zero. Here's how to define a self-increment column in SQLite:

1 CREATE TABLE TableName (id INTEGER PRIMARY KEY autoincrement, ...);

A table named Sqlite_sequence is automatically created when the SQLite database contains a self-increment column. This table consists of two columns: name and seq. The name records the table where the increment column is located, and the SEQ record is the current ordinal (the number of the next record is the current ordinal plus 1). If you want to set the ordinal of a self-increment column to zero, you only need to modify the Sqlite_sequence table.

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

You can also delete the record directly:

3 DELETE from sqlite_sequence WHERE name = ' TableName ';
To reset all the table's self-increment columns to zero, empty the Sqlite_sequence table directly:
4
Transact-SQL
DELETE from Sqlite_sequence;

iOS Development database-SQLite clears the table and zeros the self-increment column

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.