Files
QueryCarInfo2/check_table_structure.py
2025-09-23 20:13:58 +08:00

27 lines
661 B
Python

import sqlite3
# 连接到数据库
try:
conn = sqlite3.connect('car_info.db')
cursor = conn.cursor()
# 获取car_owners表的结构
cursor.execute('PRAGMA table_info(car_owners)')
rows = cursor.fetchall()
print('car_owners表结构:')
for row in rows:
print(row)
# 也检查query_history表的结构,了解两个表的关系
print('\nquery_history表结构:')
cursor.execute('PRAGMA table_info(query_history)')
rows = cursor.fetchall()
for row in rows:
print(row)
except Exception as e:
print(f'查询表结构时出错: {e}')
finally:
if conn:
conn.close()