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()
相关推荐
m0_702036531 分钟前
CSS如何兼容新旧方案结合响应式容器查询
jvm·数据库·python
ZHW_AI课题组12 分钟前
基于ElasticNet网格搜索的汽车燃油效率预测
python·机器学习·回归算法
在坚持一下我可没意见21 分钟前
Python 修仙修炼录 05:循环神通,省去无用苦修
开发语言·python·面试·入门·循环·复习
大飞记Python42 分钟前
从“驱动地狱”到一行代码:WebDriverManager使用手记(附模板)
python·测试
Cloud_Shy6181 小时前
Python 数据分析基础入门:《Excel Python:飞速搞定数据分析与处理》学习笔记系列(第九章 Excel 自动化 上篇)
python·数据分析·excel·numpy·pandas
LucaJu1 小时前
一次 OOM 线上排查实录
java·jvm·oom·内存溢出
子午1 小时前
基于YOLO的玫瑰叶片检测系统~Python+深度学习+人工智能+目标检测+YOLOV8算法
人工智能·python·yolo
Hesionberger1 小时前
LeetCode 101:对称二叉树(多语言解法)
开发语言·python
小陈的进阶之路1 小时前
Python系列课(11)——PySpark
开发语言·python·ajax
WL_Aurora1 小时前
备战蓝桥杯国赛【Day 12】
python·蓝桥杯