In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces how to use the Autoincrement keyword in SQLite, the content is very detailed, interested friends can use for reference, I hope it can be helpful to you.
The AUTOINCREMENT of SQLite is a keyword used to automatically increment the values of fields in a table. We can use the AUTOINCREMENT keyword on a specific column name to automatically increment the value of this field when we create the table.
Note: the keyword AUTOINCREMENT can be used for integer fields.
Grammar
The basic usage of the AUTOINCREMENT keyword is as follows:
CREATE TABLE table_name (column1 INTEGER AUTOINCREMENT, column2 datatype, column3 datatype,. ColumnN datatype,)
Example:
Consider that the COMPANY table should be created as follows:
Sqlite > CREATE TABLE COMPANY (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INT NOT NULL, ADDRESS CHAR (50), SALARY REAL)
The following records are now inserted into the table COMPANY:
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) VALUES ('James', 24,' Houston', 10000.00)
This will be inserted into the table COMPANY 7 tuples, and COMPANY will have the following records:
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 South-Hall 45000.07 James 24 Houston 10000.0
Personal understanding:
1. Database insert field:
AUTOINCREMENT (self-increment field) cannot reuse the id value of the deleted field, which ensures that the id must be unique. Rowid is to find the largest existing rowid+1, and it is possible that rowid+1 (current rowid) has been deleted before.
two。 After the database rowid reaches its maximum:
AUTOINCREMENT (self-increment field) returns an SQLITE_FULL error code; the new value of rowid randomly finds the id value of an unused field before this maximum number, which may be a field that has been deleted before.
On how to use the Autoincrement keyword in SQLite to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.