SQLITEÊý¾Ý±íÖ÷¼üÉèÖÃId×ÔÔö·½·¨
¸ã¶¨ÁËÒ»¸öÀ§ÈÅÐí¾ÃµÄÎÊÌ⣬ÔÀ´sqliteÖеÄÖ÷¼üÒ²ÊÇ¿ÉÒÔÉèÖÃΪ×ÔÔöµÄ£º£©·½·¨¾ÍÊÇÉùÃ÷Ϊ INTEGER PRIMARY KEY µÄ×ֶοÉÒÔ×Ô¶¯Ôö¼Ó¡£
ÍøÉϲ鵽×ÊÁÏ˵£¬´Ó SQLite µÄ 2.3.4 °æ±¾¿ªÊ¼£¬Èç¹û½«Ò»¸ö±íÖеÄÒ»¸ö×Ö¶ÎÉùÃ÷Ϊ INTEGER PRIMARY KEY£¬ÄÇôֻÐèÏò¸Ã±íµÄ¸Ã×ֶβåÈëÒ»¸ö NULL Öµ£¬Õâ¸ö NULL Öµ½«×Ô¶¯±»¸ü»»Îª±È±íÖиÃ×Ö¶ÎËùÓÐÐеÄ×î´óÖµ´ó 1 µÄÕûÊý£»Èç¹û±íΪ¿Õ£¬ÄÇô½«±»¸ü»»Îª 1¡£
CREATE TABLE "ProcessList"(
[Id] integer(4) PRIMARY KEY
,[Type] varchar(20)
,[Name] varchar(30)
,[IsUse] int
)
Ö´ÐÐ
insert into processlist
values
(null,'a','b',1)
ÔÚÂß¼ÒâÒåÉϵȼÛÓÚ£º
insert into processlist VALUES((SELECT max(Id) from processlist)+1, 'a','b',1);
insert into processlist
values
(null,'aa','bb',1)
Ö´ÐÐÁ½Ìõ²åÈëÓï¾äºóÔÙ²éѯ±íÖÐÊý¾Ý£º
select * from processlist
½á¹ûÈçÏ£º
Id Type Name IsUse
1 a b 1
2 aa bb 1
Ò»¸öеÄAPIº¯Êý sqlite3_last_insert_rowid() ·µ»Ø×î½üµÄ²åÈë²Ù×÷µÄÕûÐμü.×¢ÒâÕâ¸öÕûÐͼüʼÖÕ±È֮ǰ²åÈë±íÖеÄ×îºóÒ»¸ö¼ü´ó1¡£Ð¼üÏà¶ÔÓÚ±íÖеÄÒÑÓмüÀ´ËµÊÇΨһµÄ£¬ µ«Ëü¿ÉÄÜÓë֮ǰ´Ó±íÖÐɾ³ýµÄ¼üÖµÖصþ¡£ÒªÊ¼Öյõ½ÔÚÕû¸ö±íÖÐΨһµÄ¼ü£¬ÔÚINTEGER PRIMARY KEYµÄÉùÃ÷֮ǰ¼Ó¹Ø¼ü´ÊAUTOINCREMENT.ÕâÑù±»Ñ¡µÄ¼ü½«×ÜÊDZȱíÖÐÒÑ´æÔÚµÄ×î´ó¼ü´ó1¡£Èô¿ÉÄܵÄ×î´ó¼üÒÑ´æÔÚÓÚ±íÖУ¬INSERT²Ù×÷½«Ê§°Ü²¢·µ»ØÒ»¸öSQLITE_FULL´íÎóÂë.
Ïà¹ØÎĵµ£º
×Ô¼¸Ê®ÄêÇ°³öÏÖµÄÉÌÒµÓ¦ÓóÌÐòÒÔÀ´£¬Êý¾Ý¿â¾Í³ÉΪÈí¼þÓ¦ÓóÌÐòµÄÖ÷Òª×é³É²¿·Ö¡£ÕýÓëÊý¾Ý¿â¹ÜÀíϵͳ·Ç³£¹Ø¼üÒ»Ñù£¬ËüÃÇÒ²±äµÃ·Ç³£ÅӴ󣬲¢Õ¼ÓÃÁËÏ൱¶àµÄϵ
ͳ×ÊÔ´£¬Ôö¼ÓÁ˹ÜÀíµÄ¸´ÔÓÐÔ¡£Ëæ×ÅÈí¼þÓ¦ÓóÌÐòÖð½¥Ä£¿éÄ£¿é»¯£¬Ò»ÖÖÐÂÐÍÊý¾Ý¿â»á±È´óÐ͸´ÔӵĴ«Í³Êý¾Ý¿â¹ÜÀíϵͳ¸üÊÊÓ¦¡£Ç¶ÈëʽÊý¾Ý¿âÖ±½ÓÔÚÓ¦ÓóÌÐò½ø³Ì
ÖÐ ......
°ÝGoogleµÄScott Hessͬ־Ëù´Í£¬SQLiteÒ²ÍƳöÁËÈ«ÎÄËÑË÷¹¦ÄÜ¡£
SQLiteͨ¹ý½¨Á¢Ò»¸öÐéÄâ±í£¬½«ÊäÈëµÄÎÄ×Ö¸ù¾Ý¿Õ¸ñ¡¢±êµã·ûºÏµÈ¹æÔò½øÐзִʣ¬×éÖ¯³ÉÒ»¿ÃBÊ÷£¬ÒÔ´ËÀ´Ìá¸ßËÑË÷Ëٶȡ£
ÈçºÎʹÓÃÕâÒ»¹¦ÄÜ£¬ÐÔÄÜÉÏÈçºÎ£¬´ó¼Ò¸÷×ÔÑо¿È¥°É¡£
ÔÚÕâÀ ......
.dump ?TABLE? ... ÒÔSQLÓï¾ä·½Ê½ÏÔʾ±íµÄ½á¹¹¡£È磺
sqlite> .dump websties
BEGIN TRANSACTION;
COMMIT;
sqlite> .dump websites
BEGIN TRANSACTION;
CREATE TABLE [websites] (
[WebID] INTEGER NOT NULL PRIMARY KEY,
[WebName] VARCHAR(20) NULL
);
INSERT INTO "websites" VALUES(1,'CTOChina.net'); ......
.help ÏÔʾ°ïÖúÐÅÏ¢
.import FILE TABLE °ÑÎļþÖеÄÊý¾Ýµ¼Èëµ½±íÖÐ,¸÷×Ö¶ÎÓÃseparator£¨Ä¬ÈÏÊÇ"|"£©µÄֵΪ·Ö¸ô·û,ÏÂÃæÎÒÃǾٸöÀý×Ó¡£ ÎÒÃÇÔÚFÅÌϽ¨Ò»¸ödata.txtÎļþ£¬ÄÚÈÝÈçÏ£º
4|¿ªÔ´
5|¼¼Êõ
.importÃüÁî²Ù×÷ÈçÏ£º
sqlite> .import data.txt websites
sqlite>
²é¿´½á¹ûÈçÏ£º
sqlite> select * from ......
×î½ü¹«Ë¾ÐèÒª½«×ÀÃæϵͳ²¿Êðµ½PDAÉÏÃæÈ¥£¬Ñ¡ÔñÁËWM6×÷Ϊ²¿Êðƽ̨¡£ÔÚÑ¡ÔñÊý¾Ý¿â·½Ãæ³öÏÖÁËÒ»µã¹ËÂÇ£¬ÒòΪ¶ÔÓÚPDA¶øÑÔ£¬ÐÔÄÜÊÇÊ×Òª¿¼ÂǵÄÒòËØ¡£
ÔÚ¿ªÔ´µÄÊý¾Ý¿âSqliteºÍSQLCEÖ®¼äÅÇ»²£¬ËùÒÔÕë¶ÔÕâ¸öÇé¿ö£¬¶ÔSqliteºÍSQLCEÔÚWM6ÉÏÃæ×öÁËÐÔÄܲâÊÔ¡£ÎÒÒ²½«×Ô¼ºÔÚ×ö²âÊÔ¹ý³ÌÖÐÅöµ ......