sqlite3 是SQLite的python接口,由Gerhard Häring编写,属于python的标准库,无需额外安装。下面介绍sqlite3的用法。...(值唯一)
#NOT NULL 值非空约束
c.execute('''CREATE TABLE IF NOT EXISTS pets
(id INTEGER PRIMARY...KEY, name TEXT , type TEXT NOT NULL, sex CHAR(1), weight real)''')
sqlite 和 python的数据类型对照表:
?...INTO pets VALUES (1,'Tom', '猫', 'male', 5)")
#可以只给定部分值,未给定值的为Null(当然,有非空约束的不能为空), 对应python类型 None
c.execute...("INSERT INTO pets(id, name, type) VALUES (2,'喜洋洋', '羊')")
#可以用普通的 python 字符串格式化:
c.execute("INSERT