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()
相关推荐
V搜xhliang024618 分钟前
OpenClaw科研全场景用法:从文献到实验室的完整自动化方案
运维·开发语言·人工智能·python·算法·microsoft·自动化
李崧正40 分钟前
Java技术分享:Lambda表达式与函数式编程
java·开发语言·python
BIGmustang44 分钟前
python练手之用tkinter写一个计算器
开发语言·python
WL_Aurora1 小时前
Python 算法基础篇之链表
python·算法·链表
曲幽1 小时前
FastAPI 少有人提的实用技巧:把 Depends 依赖提到路由层,代码少写60%
python·fastapi·web·routes·depends·prefix·apiroute
qiaozhangchi1 小时前
求解器学习笔记
笔记·python·学习
kexnjdcncnxjs2 小时前
Redis如何记录每一次写操作_开启AOF持久化机制实现命令级追加记录
jvm·数据库·python
程序媛徐师姐2 小时前
Python基于Django的小区果蔬预定系统【附源码、文档说明】
python·django·小区果蔬预定系统·果蔬预定·python小区果蔬预定系统·小区果蔬预定·python果蔬预定系统
小何code2 小时前
人工智能【第8篇】监督学习实战:线性回归与逻辑回归算法详解(万字长文+完整代码实现)
人工智能·python·学习·机器学习·逻辑回归·线性回归