sqlite基本使用方法
来源:互联网 发布:做淘宝店铺用什么软件 编辑:程序博客网 时间:2024/04/27 07:48
- 新建(打开)数据库文件
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> .databasesseq name file--- --------------- -------------------------------------0 main D:\tool\mydata.db
- 表列表
sqlite> .tablebooksqlite>
- 表信息
sqlite> .schema bookCREATE TABLE "book"(name TEXT, price float, SN TEXT PRIMARY KEY);sqlite> .fullschemaCREATE TABLE "book"(name TEXT, price float, SN TEXT PRIMARY KEY);/* No STAT tables available */sqlite> .schemaCREATE TABLE "book"(name TEXT, price float, SN TEXT PRIMARY KEY);sqlite>
- 显示设置选项
sqlite> .show echo: off eqp: off explain: off headers: off mode: listnullvalue: "" output: stdoutseparator: "|" "\r\n" stats: off width:sqlite>
- 创建表
sqlite> CREATE TABLE staff(NO TEXT PRIMARY KEY, name VARCHAR(32), age int);sqlite> .tablebook staffsqlite>
- 插入数据记录到表
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.NOsqlite> 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|马化腾|32014002|马云|42014003|李彦宏|62014004|胡夸风|62014006|窦思涡|11sqlite>
- 查看表中记录
sqlite> select * from staff;2014001|马化腾|32014002|马云|42014003|李彦宏|62014004|胡夸风|62014006|窦思涡|11sqlite> select * from staff where age > 6;2014006|窦思涡|11sqlite> select * from staff where age >= 6;2014003|李彦宏|62014004|胡夸风|62014006|窦思涡|11sqlite> select * from staff where age >= 6 order by name;2014004|胡夸风|62014003|李彦宏|62014006|窦思涡|11sqlite> select * from staff where age >= 6 order by namec desc;Error: no such column: namecsqlite> select * from staff where age >= 6 order by name desc;2014006|窦思涡|112014003|李彦宏|62014004|胡夸风|6sqlite> select AVG(age) from staff;6.0sqlite>
- 更新表中记录
sqlite> update staff set age=age+10;sqlite> select * from staff;2014001|马化腾|132014002|马云|142014003|李彦宏|162014004|胡夸风|162014006|窦思涡|21sqlite> select * from staff where age < 15;2014001|马化腾|132014002|马云|14sqlite> update staff set age=age+10 where age < 15;sqlite> select * from staff;2014001|马化腾|232014002|马云|242014003|李彦宏|162014004|胡夸风|162014006|窦思涡|21sqlite>
- 删除表中记录
sqlite> select * from staff;2014001|马化腾|232014002|马云|242014003|李彦宏|162014004|胡夸风|162014006|窦思涡|212014113|will delete|23sqlite> delete from staff where NO='2014113';sqlite> select * from staff;2014001|马化腾|232014002|马云|242014003|李彦宏|162014004|胡夸风|162014006|窦思涡|21sqlite>
0 0
- sqlite基本使用方法
- 【android】SQlite数据库基本使用方法
- 【基础】SQLite的基本使用方法
- iOS sqlite数据库的基本使用方法
- Android中SQLite的基本使用方法
- SQLite使用方法
- SQLite使用方法
- SQLite使用方法
- SQLite使用方法
- SQLite使用方法
- 【SQLite使用方法】
- SQLite使用方法
- SQLite基本
- sqlite基本
- Android-SQLite数据库使用方法
- Android SQLite使用方法
- SQLite使用方法 SQLiteOpenHelper操作
- Sqlite 简单使用方法
- BST创建
- 2.C++ STL笔记: Bitset相关
- 工欲善其事必先利其器之Git
- Struts2 poi导出excel
- Spring MVC报错:The request sent by the client was syntactically incorrect ()
- sqlite基本使用方法
- 白话Aulolayout
- Struts2学习笔记——Namespace
- OC核心语法(2)构造函数
- WinCE6.0的EBOOT概要
- 常用工具
- HDU 1754 I Hate It(入门线段树)
- (三)洞悉linux下的Netfilter&iptables:内核中的rule,match和target
- UVA839 Not so Mobile【二叉树】【递归】