操作SQLite3创建表
import sqlite3
con = sqlite3.connect('first.db') # 在硬盘上创建连接
cur = con.cursor() # 创建游标对象,执行sql
# sql语句
sql = '''create table t_person(
pno INTEGER primary key autoincrement,
pname VARCHAR not null,
age INTEGER
)'''
try:
# 执行sql
cur.execute(sql)
print('创建成功')
except Exception as e:
print(e)
print('创建失败')
finally:
#关闭游标
cur.close()
#关闭连接
con.close()
插入数据
import sqlite3
con = sqlite3.connect('first.db') # 在硬盘上创建连接
cur = con.cursor() # 创建游标对象,执行sql
# sql语句
sql = 'insert into t_person(pname, age) values (?,?)'
# 在创建表时,设置主键自增,这里就不插入pno的值了
try