【脚本语言系列】关于Python数据库处理SQLite,你需要知道的事
2017-05-24 20:12
1121 查看
如何使用SQLite
下载地址(SQLite v3.19.0.管理数据库文件的命令行工具包,包括3个可执行程序:sqldiff.exe, sqlite3.exe,sqlite3_analyzer.exe):https://www.sqlite.org/2017/sqlite-tools-win32-x86-3190000.zip
将3个程序解压到需要使用的位置即可使用;
使用命令行工具
创建数据库
sqlite3.exe python
创建表;向表中插入内容
CREATE TABLE people (name VARCHAR(30), age INT, sex CHAR(1))
INSERT INTO people VALUES ('Tom', 20, 'M') INSERT INTO people VALUES ('Jack', 21, 'M')
查看表中内容
SELECT * FROM people
退出
.exit
使用Python
# -*- coding:utf-8 -*- # import sqlite3 con = sqlite3.connect('python') # connect to db cur = con.cursor() # get the db cursor cur.execute('insert into people (name, age, sex) values (\'Jee\',21, \'F\')') # execute SQL, add record r = cur.execute('delete from people where age=20') # execute SQL, del record con.commit() # commit change cur.execute('select * from people') # execute SQL, get record s = cur.fetchall() # get data print s # print data cur.close() # close cursor con.close() # close connection
什么是SQLite
SQLite是一款轻型的嵌入式数据库,相对于其他的庞大数据库软件,SQLite显得十分轻巧。SQLite不需要MySQL的守护进程,也不需要安装Access那么庞大的软件。
相关文章推荐
- 【脚本语言系列】关于Python数据库处理MySQL, 你需要知道的事
- 【脚本语言系列】关于Python数据库处理SQLAlchemy,你需要知道的事
- 【脚本语言系列】关于PythonNoSQL数据库处理memcached,你需要知道的事
- 【脚本语言系列】关于Python数据库处理SQLite数据库,你需要知道的事
- 【脚本语言系列】关于PythonNoSQL数据库处理redis,你需要知道的事
- 【脚本语言系列】关于PythonNoSQL数据库处理dbm,你需要知道的事
- 【脚本语言系列】关于Python基础知识异常处理,你需要知道的事
- 【脚本语言系列】关于Python图像处理PIL,你需要知道的事
- 【脚本语言系列】关于Python异常处理,你需要知道的事
- 【脚本语言系列】关于Python数据库访问ActiveXDataObject,你需要知道的事
- 【脚本语言系列】关于Python数据库访问DAO, 你需要知道的事
- 【脚本语言系列】关于Python结构化二进制文件处理Microsoft Excel,你需要知道的事
- 【脚本语言系列】关于Python基础知识处理字符串,你需要知道的事
- 【脚本语言系列】关于Python结构化二进制文件处理HDF5,你需要知道的事
- 【脚本语言系列】关于Python结构化文本文件处理JSON,你需要知道的事
- 【脚本语言系列】关于 Python XML处理,你需要知道的事
- 【脚本语言系列】关于Python图像处理scikits-image, 需要知道的事
- 【脚本语言系列】关于Python结构化文本文件处理配置文件.ini,你需要知道的事
- 【脚本语言系列】关于Python数据库访问专用模块,你需要知道的事
- 【脚本语言系列】关于Python音频处理WMPlayerOCX,你需要知道的事情