您的位置:首页 > 数据库

sqlite3命令行常用命令

2016-12-02 17:15 295 查看
转载请标明出处:http://blog.csdn.net/xx326664162/article/details/53436776 文章出自:薛瑄的博客

所有命令可查看这里:SQLite 教程

1、sqlite3,或者sqilite3+.db,其中是数据库的名字,进入到sqlite互动模式。如果没有这个名字的数据库就创建一个新的数据库。

2、 .exit ,退出sqlite互动模式的命令

3、 create table < table_name> (f1 type1, f2 type2,…); 创建新表

sqlite> create table peopleinfo
...> (_id integer primary key autoincrement,
...> name text not null,
...> age integer,
...> height float);
sqlite>


4、.tables显示数据库中所有表名

5、drop table < table_name>删除表

6、.schema < table_name> 查看表的结构

7、.database 显示当前打开的数据库文件

8、insert into < table_name> values (value1, value2,…);向表中添加新记录

9、select * from < table_name>;查询表中所有记录

10、update < table_name> set < f1=value1>, < f2=value2>… where < expression>; 更新表中记录

sqlite> update peopleinfo set height=1.88 where name='Lily';
sqlite> select * from peopleinfo;
select * from peopleinfo;
1        Tom         21        1.81
2        Jim         22        1.78
3        Lily        19        1.68
4        Lucy        21        1.68
5        John        21        1.86
sqlite>


11、连表查询

company表:

companyIdcompanyNamecontacts
1腾讯科技马化腾
2微软公司鲍威尔
3新浪科技小明
users表:

userIdcompanyIduserNameuserAgeaddress
11jack23上海
21jack223上海
32jack323上海
42jack423上海
53jack523上海
63jack623上海
表的 companyId已关联,要根据company表查询出companyId为1下的所有用户信息。

设查询companyName是腾讯科技,contacts是马化腾的所有用户:

select b.* from company表 a left join users表 b on a.companyId=b.companyId where a.companyName='腾讯科技' and a.contacts='马化腾'


两表关联查询SQL语句的,要怎么写?

SQL总结(二)连表查询

目前总结了,这些常用的,以后会持续更新。。。

参考:

sqlite3命令行下的常用命令

Android开发之手动建立SQLite数据库

SQLite关于时间段查询的sql
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: