1. 导入包
import sqlite3
2. 创建连接
con = sqlite3.connetc('test.db') #不存在则创建
3. 获取数据库cursor对象
cur = con.cursor()
4. 创建表的sql语句
sql = ''' create table t_person(
pno INTEGER primary key autoincrement,
pname VARCHAR not null,
age INTEGER
)'''
try:
#执行sql语句,创建表
cur.excute(sql)
except Exception as e:
print(e)
print(‘创建表成功')
finally:
cur.close()#关闭游标
con.close()#关闭连接