[QT] [Sql]sql Learning record 5_sqlite autoincrement (auto increment)

Source: Internet
Author: User
Tags sqlite

Definitions and examples see: http://www.runoob.com/sqlite/sqlite-autoincrement.html

Sqliteautoincrement (auto increment)

SQLite's autoincrement is a keyword that is used to automatically increment the value of a field in a table. We can use the autoincrement keyword on a specific column name to automatically increase the value of the field when we create the table.

The keyword autoincrement can only be used for integer fields.

Instance

Let's say the company table you want to create looks like this:

SQLite> CREATE TABLE company(   ID INTEGER PRIMARY KEY   autoincrement, NAME TEXT not Null, age int. not NULL, ADDRESS CHAR, SALARY REAL);   

Now, insert the following records into the company table:

INSERT into Company(NAME,Age,ADDRESS,SALARY)VALUES( ' Paul ', 32, ' California ', 20000.00 );INSERT into Company(NAME,Age,ADDRESS,SALARY)VALUES(' Allen ', 25, ' Texas ', 15000.00 );INSERT into Company(NAME,Age,ADDRESS,SALARY)VALUES(' Teddy ', 23, ' Norway ', 20000.00 );INSERT into Company(NAME,Age,ADDRESS,SALARY)VALUES( ' Mark ', 25, ' Rich-mond ', 65000.00 );INSERT into Company(NAME,Age,ADDRESS,SALARY)VALUES( ' David ', 27, ' Texas ', 85000.00 );INSERT into Company(NAME,Age,ADDRESS,SALARY)VALUES( ' Kim ', 22,  ' South-hall ' , 45000.00  INSERT into company  (name,age ,address,salary) Span class= "PLN" >values  (  ' James ' , 24,  ' Houston ' , 10000.00     

This inserts 7 tuples into the company table, at which time the records for the company table are as follows:

ID NAME Age ADDRESS SALARY----------  ----------  ---------- ---------- ----------1 Paul 32 California 20000.02 Allen 25 Texas 15000.03 Teddy 23 Norway 20000.04 Mark 25 Rich-mond 65000.05 david 27  texas 85000.06 kim 22 Span class= "Typ" >south-hall 45000.07 james 24  houston 10000.0      

[Qt][sql]sql Learning record 5_sqlite autoincrement (auto increment)

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.