---
title: "Python操作sqlite数据库的一些记录"
author: "Thomas会Coding"
date: "2014-12-28T21:36:36Z"
tags: []
categories: ["编程语言"]
slug: "python-sqlite"
draft: false
lastmod: "2014-12-28T21:36:36Z"
id: 2170734
url: "https://zzcjobstudy.iteye.com/blog/2170734"
---

Python 内置了sqlite的模块

```
import sqlite3

connection=sqlite3.connect('coachdata.sqlite')
cursor=connection.cursor();
'''cursor.execute("""create table athletes(id integer primary key autoincrement unique not null,
                name text not null,
                dob date not null
                )""")'''
#创建表
#cursor.execute("insert into athletes(name,dob) values(?,?)",('zzc','1990-0210'));
#插入表
cursor.execute("select * from athletes")
#查询表
print cursor.fetchall()
connection.commit()
#一定要提交
connection.close()
```

 cursor.fetchone()返回下一个数据行

cursor.fetchmany()返回多个数据行

cursor.fetchall()返回所有数据