问一下 使用Python怎么去拿到Sqlite数据库的字段名

2025-03-06 02:20:25
推荐回答(1个)
回答1:

sqlite3数据库里表的信息存储在了一个名为sqlite_master的表中
因此可以通过这条语句来查看数据库中所有表的名称
SELECT name FROM sqlite_master WHERE type='table';
下面是Python的用法

1
2
3
4

con = sqlite3.connect('database.db')
cursor = con.cursor()
cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
print(cursor.fetchall())