sqlite3 mydata.db # 指定数据库文件启动sqlite .open mydata.db # 使用.open命令打开打开数据库文件
sqlite> .help .backup ?DB? FILE Backup DB (default "main") to FILE .bail on|off Stop after hitting an error. Default OFF .clone NEWDB Clone data into NEWDB from the existing database .databases List names and files of attached databases .dump ?TABLE? ... Dump the database in an SQL text format If TABLE specified, only dump tables matching LIKE pattern TABLE. .echo on|off Turn command echo on or off .eqp on|off Enable or disable automatic EXPLAIN QUERY PLAN .exit Exit this program .explain ?on|off? Turn output mode suitable for EXPLAIN on or off. With no args, it turns EXPLAIN on. .fullschema Show schema and the content of sqlite_stat tables .headers on|off Turn display of headers on or off .help Show this message .import FILE TABLE Import data from FILE into TABLE .indices ?TABLE? Show names of all indices If TABLE specified, only show indices for tables matching LIKE pattern TABLE. .load FILE ?ENTRY? Load an extension library .log FILE|off Turn logging on or off. FILE can be stderr/stdout .mode MODE ?TABLE? Set output mode where MODE is one of: csv Comma-separated values column Left-aligned columns. (See .width) html HTML <table> code insert SQL insert statements for TABLE line One value per line list Values delimited by .separator string tabs Tab-separated values tcl TCL list elements .nullvalue STRING Use STRING in place of NULL values .once FILENAME Output for the next SQL command only to FILENAME .open ?FILENAME? Close existing database and reopen FILENAME .output ?FILENAME? Send output to FILENAME or stdout .print STRING... Print literal STRING
sqlite> .databases seq name file --- --------------- ------------------------------------- 0 main D:\tool\mydata.db
sqlite> .table book sqlite>
sqlite> .schema book CREATE TABLE "book"(name TEXT, price float, SN TEXT PRIMARY KEY); sqlite> .fullschema CREATE TABLE "book"(name TEXT, price float, SN TEXT PRIMARY KEY); /* No STAT tables available */ sqlite> .schema CREATE TABLE "book"(name TEXT, price float, SN TEXT PRIMARY KEY); sqlite>
sqlite> .schema book CREATE TABLE "book"(name TEXT, price float, SN TEXT PRIMARY KEY); sqlite> .fullschema CREATE TABLE "book"(name TEXT, price float, SN TEXT PRIMARY KEY); /* No STAT tables available */ sqlite> .schema CREATE TABLE "book"(name TEXT, price float, SN TEXT PRIMARY KEY); sqlite>
sqlite> CREATE TABLE staff(NO TEXT PRIMARY KEY, name VARCHAR(32), age int); sqlite> .table book staff sqlite>
sqlite> INSERT INTO staff VALUES("2014001", "马化腾", 3); sqlite> INSERT INTO staff VALUES("2014002", "马云", 4);; sqlite> INSERT INTO staff VALUES("2014002", "李彦宏", 6);; Error: UNIQUE constraint failed: staff.NO sqlite> INSERT INTO staff VALUES("2014003", "李彦宏", 6); sqlite> INSERT INTO staff VALUES("2014004", "胡夸风", 6); sqlite> INSERT INTO staff VALUES("2014006", "窦思涡", 11); sqlite> select * from staff ...> ; 2014001|马化腾|3 2014002|马云|4 2014003|李彦宏|6 2014004|胡夸风|6 2014006|窦思涡|11 sqlite>
sqlite> select * from staff; 2014001|马化腾|3 2014002|马云|4 2014003|李彦宏|6 2014004|胡夸风|6 2014006|窦思涡|11 sqlite> select * from staff where age > 6; 2014006|窦思涡|11 sqlite> select * from staff where age >= 6; 2014003|李彦宏|6 2014004|胡夸风|6 2014006|窦思涡|11 sqlite> select * from staff where age >= 6 order by name; 2014004|胡夸风|6 2014003|李彦宏|6 2014006|窦思涡|11 sqlite> select * from staff where age >= 6 order by namec desc; Error: no such column: namec sqlite> select * from staff where age >= 6 order by name desc; 2014006|窦思涡|11 2014003|李彦宏|6 2014004|胡夸风|6 sqlite> select AVG(age) from staff; 6.0 sqlite>
sqlite> update staff set age=age+10; sqlite> select * from staff; 2014001|马化腾|13 2014002|马云|14 2014003|李彦宏|16 2014004|胡夸风|16 2014006|窦思涡|21 sqlite> select * from staff where age < 15; 2014001|马化腾|13 2014002|马云|14 sqlite> update staff set age=age+10 where age < 15; sqlite> select * from staff; 2014001|马化腾|23 2014002|马云|24 2014003|李彦宏|16 2014004|胡夸风|16 2014006|窦思涡|21 sqlite>
sqlite> select * from staff; 2014001|马化腾|23 2014002|马云|24 2014003|李彦宏|16 2014004|胡夸风|16 2014006|窦思涡|21 2014113|will delete|23 sqlite> delete from staff where NO='2014113'; sqlite> select * from staff; 2014001|马化腾|23 2014002|马云|24 2014003|李彦宏|16 2014004|胡夸风|16 2014006|窦思涡|21 sqlite>
原文地址:http://blog.csdn.net/arbboter/article/details/41863103