You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gitProject/src/AiDiary/check_db.py

24 lines
656 B

import sqlite3
# 连接到数据库
try:
conn = sqlite3.connect('database.db')
c = conn.cursor()
# 查看所有表
print("数据库中的表:")
c.execute("SELECT name FROM sqlite_master WHERE type='table';")
tables = c.fetchall()
for table in tables:
print(f"- {table[0]}")
# 查看表结构
print(f" {table[0]}表结构:")
c.execute(f"PRAGMA table_info({table[0]});")
columns = c.fetchall()
for column in columns:
print(f" - {column[1]} ({column[2]})")
conn.close()
except Exception as e:
print(f"检查数据库出错: {e}")