sqlite3 在Python中使用

SQLite是一种关系型数据库管理系统,使用SQL语言进行数据操作。Python内置了一个SQLite模块,可以轻松地在Python中使用SQLite数据库。

python 复制代码
"""
文件型数据库: 就是一个文件,不需要在电脑安装数据库软件
python3 内置了sqlite3  可以管理sqlite数据库
"""

import sqlite3
con = sqlite3.connect("python2407.abc")
cur = con.cursor()

# cur.execute("SELECT name FROM sqlite_master WHERE type='table';")
# print(cur.fetchall())

# cur.execute("""
# CREATE TABLE users (
#     id INTEGER PRIMARY KEY AUTOINCREMENT,
#     username TEXT NOT NULL UNIQUE,
#     password TEXT NOT NULL
# );
# """)

# cur.execute("PRAGMA table_info(users);")
# print(cur.fetchall())

# cur.executemany("INSERT INTO users (username, password) VALUES (?, ?);", [
#     ('user3', 'password'),
#     ('user4', 'password'),
#     ('user5', 'password'),
#     ('user6', 'password'),
#     ('user7', 'password'),
# ])
#
# con.commit()

cur.execute("SELECT * FROM users;")
print(cur.fetchall())


cur.close()
con.close()
相关推荐
ZhengEnCi5 小时前
P2M-Matplotlib折线图完全指南-从数据可视化到趋势分析的Python绘图利器
python·matlab·数据可视化
ZhengEnCi7 小时前
P2L-Matplotlib饼图完全指南-从数据可视化到图表定制的Python绘图利器
python·matlab
曲幽7 小时前
你的REST接口还在“过度投喂”数据吗?——FastAPI + GraphQL实战避坑指南
python·fastapi·web·graphql·route·cors·rest·strawberry
用户8358086187918 小时前
基于 Self-RAG 与列表级重排序的进阶 RAG 系统设计与实现
python
Warson_L1 天前
Python `Annotated` 与 LangGraph Reducer 学习笔记
python
韩师傅1 天前
海天线算法的前世今生
python·计算机视觉
韩师傅1 天前
当你的甲方设备过烂,要如何快速出效果?
python·计算机视觉
Warson_L1 天前
LangGraph的MessageState and HumanMessage
python
韩师傅1 天前
当你的甲方吐槽天空不够蓝,你应该如何应对
python·计算机视觉
Warson_L1 天前
python的类&继承
python