Self-increment primary key in SQLite

Source: Internet
Author: User
Tags sqlite table definition

Http://stackoverflow.com/questions/8519936/sqlite-autoincrement-primary-key-questions

I ' m not sure whether your ' re actually using SQLite according to the syntax of your example.

If you is interested in the SQLite FAQ #1: How does I create an autoincrement field?:

Short answer:a column declared INTEGER PRIMARY KEY would autoincrement.

Http://stackoverflow.com/questions/7905859/is-there-an-auto-increment-in-sqlite

You get the one for free, called ROWID. Every SQLite table whether you ask for it or not.

If you include a-column of type INTEGER PRIMARY KEY, that's column points at (was an alias for) the Automatic ROWID column.

ROWID (by whatever name-call it) are assigned a value whenever you INSERT a row, as you would expect. If you explicitly assign a Non-null value on INSERT, it'll get that specified value instead of the auto-increment. If you explicitly assign a value of NULL on INSERT, it'll get the next auto-increment value.

Also, should try to avoid:

 INSERT INTO people VALUES ("John", "Smith");

and use

 INSERT INTO people (first_name, last_name) VALUES ("John", "Smith");

instead. The first version is very fragile-if your ever add, move, or delete columns in your table definition the INSERT would eith Er fail or produce incorrect data (with the values in the wrong columns).

Https://www.sqlite.org/autoinc.html

Self-increment primary key in SQLite

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.