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}")