sqlite中的自增主键

http://*.com/questions/8519936/sqlite-autoincrement-primary-key-questions

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

If you are, you may be interested in SQLite FAQ #1: How do I create an AUTOINCREMENT field?:

Short answer: A column declared INTEGER PRIMARY KEY will autoincrement.

http://*.com/questions/7905859/is-there-an-auto-increment-in-sqlite

You get one for free, called ROWID. This is in every SQLite table whether you ask for it or not.

If you include a column of type INTEGER PRIMARY KEY, that column points at (is an alias for) the automatic ROWID column.

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

Also, you 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 you ever add, move, or delete columns in your table definition the INSERT will either fail or produce incorrect data (with the values in the wrong columns).

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

有主键的表,会生成一个隐藏的表,叫做

select 'drop table ' || name || ';' from sqlite_master where type = 'table';

筛选的结果中有:  drop table sqlite_sequence;

上一篇:Java Tuple2使用accessor方法和直接调用变量之间的区别


下一篇:servlet 中 service ,doGet , doPost 关系