sqlites3基本操作

xiaoxiao2021-02-28  5

import sqlite3 conn = sqlite3.connect("D://python_communication//workspace//TensorFlow//data//test.db") # 使用游标查询数据库 cur = conn.cursor() # 建表 cur.execute("create table catalog (id integer primary key,pid integer,name varchar(10) UNIQUE,nickname text NULL)") # 插入数据 for t in [(0,10,'abc','X'),(1,20,'cba','Y')]: cur.execute("insert into catalog values (?,?,?,?)",t) # 提交操作 conn.commit() # 查询 cur.execute("select * from catalog") # 提取查询到的数据 print(cur.fetchall())
转载请注明原文地址: https://www.6miu.com/read-1400145.html

最新回复(0)