Files
fastcopy/db_manage/drop_all_tables.py
2025-05-15 16:33:30 +08:00

46 lines
1.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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()