SQLite基本语句
来源:互联网 发布:php 直播 编辑:程序博客网 时间:2024/06/04 19:03
创建首个数据库。在命令行窗口中输入如下命令来创建一个名为 test.db 的数据库。
- sqlite3 test.db
创建表:
- sqlite> create table mytable(id integer primary key, value text);
- 2 columns were created.
该表包含一个名为 id 的主键字段和一个名为 value 的文本字段。
注意: 最少必须为新建的数据库创建一个表或者视图,这么才能将数据库保存到磁盘中,否则数据库不会被创建。
接下来往表里中写入一些数据:
- sqlite> insert into mytable(id, value) values(1, 'Micheal');
- sqlite> insert into mytable(id, value) values(2, 'Jenny');
- sqlite> insert into mytable(value) values('Francis');
- sqlite> insert into mytable(value) values('Kerk');
查询数据:
- sqlite> select * from test;
- 1|Micheal
- 2|Jenny
- 3|Francis
- 4|Kerk
设置格式化查询结果:
- sqlite> .mode column;
- sqlite> .header on;
- sqlite> select * from test;
- id value
- ----------- -------------
- 1 Micheal
- 2 Jenny
- 3 Francis
- 4 Kerk
.mode column 将设置为列显示模式,.header 将显示列名。
修改表结构,增加列:
- sqlite> alter table mytable add column email text not null '' collate nocase;;
创建视图:
- sqlite> create view nameview as select * from mytable;
创建索引:
- sqlite> create index test_idx on mytable(value);
4. 一些有用的 SQLite 命令
显示表结构:
- sqlite> .schema [table]
获取所有表和视图:
- sqlite > .tables
获取指定表的索引列表:
- sqlite > .indices [table ]
导出数据库到 SQL 文件:
- sqlite > .output [filename ]
- sqlite > .dump
- sqlite > .output stdout
从 SQL 文件导入数据库:
- sqlite > .read [filename ]
格式化输出数据到 CSV 格式:
- sqlite >.output [filename.csv ]
- sqlite >.separator ,
- sqlite > select * from test;
- sqlite >.output stdout
从 CSV 文件导入数据到表中:
- sqlite >create table newtable ( id integer primary key, value text );
- sqlite >.import [filename.csv ] newtable
备份数据库:
- /* usage: sqlite3 [database] .dump > [filename] */
- sqlite3 mytable.db .dump > backup.sql
恢复数据库:
- /* usage: sqlite3 [database ] < [filename ] */
- sqlite3 mytable.db < backup.sql
0 0
- sqlite基本使用语句
- SQLite基本语句
- SQLite基本语句
- sqlite基本语句使用
- SQLite 基本语句使用
- sqlite基本sql语句使用
- sqlite基本sql语句使用
- sqlite基本sql语句使用
- sqlite数据库基本语句集合
- sqlite基本sql语句使用
- iOS-SQLite数据库基本语句
- sqlite用到的基本语句
- sqlite基本sql语句使用
- 关于Sqlite的一些基本语句使用
- [Sqlite] Sqlite的基本日常SQL操作语句汇总
- 【Cocos2d-x 020】 sqlite基本sql语句使用
- 数据库Sqlite基本的增删改查语句
- SQlite语句
- leetcode Add and Search Word - Data structure design回溯算法+Trie字典树
- genymotion升级风波-engine not found 及virtual box 的无法打开新任务
- 高级进阶自己需要掌握的东西
- Java线程同步
- JavaScript在网页中的位置
- SQLite基本语句
- (oracle)invalid username/password:logon denied
- shell脚本中的命令替换
- iOS开发学习笔记(二)—— 让图片“动”起来!
- Notepad++选中行操作 快捷键 使用技巧
- GoF23种设计模式
- ora-01843错误
- 2015年第十六周lcd
- IO-05~~~IO-09