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()
相关推荐
TonyLee01719 小时前
使用argparse模块以及shell脚本
python
Blossom.11820 小时前
Prompt工程与思维链优化实战:从零构建动态Few-Shot与CoT推理引擎
人工智能·分布式·python·智能手机·django·prompt·边缘计算
贺今宵20 小时前
安装better-sqlite3报错electron-vite
javascript·sql·sqlite·sqlite3
love530love21 小时前
Windows 11 下 Z-Image-Turbo 完整部署与 Flash Attention 2.8.3 本地编译复盘
人工智能·windows·python·aigc·flash-attn·z-image·cuda加速
MediaTea1 天前
Python:模块 __dict__ 详解
开发语言·前端·数据库·python
jarreyer1 天前
python,numpy,pandas和matplotlib版本对应关系
python·numpy·pandas
代码or搬砖1 天前
HashMap源码
开发语言·python·哈希算法
顽强卖力1 天前
第二章:什么是数据分析师?
笔记·python·职场和发展·学习方法
站大爷IP1 天前
Python实现Excel数据自动化处理:从繁琐操作到智能流程的蜕变
python
BBB努力学习程序设计1 天前
Python 进阶知识点精讲:上下文管理器(Context Manager)的原理与实战
python·pycharm