46 lines
1.1 KiB
Python
46 lines
1.1 KiB
Python
import sqlite3
|
||
|
||
|
||
def DropAllTables(db_path):
|
||
"""
|
||
删除指定数据库中的所有8张表(如果存在)。
|
||
|
||
:param db_path: str, SQLite 数据库文件的路径
|
||
:return: None
|
||
"""
|
||
|
||
# 表名列表(根据你之前创建的8张表)
|
||
tables = [
|
||
'db_config', # 表1:配置表
|
||
'db_device', # 表2:设备表
|
||
'db_node', # 表3:节点信息表
|
||
'db_group', # 表4:组表
|
||
'db_user', # 表5:用户表
|
||
'db_extend_extent', # 表6:扩展片段表
|
||
'db_path', # 表7:路径表
|
||
'db_extend_name' # 表8:扩展名表
|
||
]
|
||
|
||
# 连接到SQLite数据库
|
||
conn = sqlite3.connect(db_path)
|
||
cursor = conn.cursor()
|
||
|
||
# 遍历并删除每张表
|
||
for table in tables:
|
||
cursor.execute(f"DROP TABLE IF EXISTS {table};")
|
||
print(f"表 [{table}] 已删除")
|
||
|
||
# 提交更改
|
||
conn.commit()
|
||
conn.close()
|
||
|
||
print("✅ 所有预定义表已删除完成")
|
||
|
||
|
||
def main():
|
||
DropAllTables(db_path='../src/db_ntfs_info.db')
|
||
|
||
|
||
if __name__ == '__main__':
|
||
main()
|