This script clears all data from .db files in a specified folder while preserving the database schema (tables and their structures). It iterates through each SQLite database, deletes the data from all tables, and leaves the table structures intact.
Before running the script, you need to update the following variable with the appropriate path:
folder_with_dbs: The folder where your.dbfiles are located.
Replace the placeholder with your actual path:
folder_with_dbs = r'C:\path\to\your\db\files'- Clears data from all tables in
.dbfiles while keeping the schema intact. - Automatically detects and processes all
.dbfiles in the specified folder. - Safeguards database structure by not modifying tables or schema.
- Python: Version 3.12
- SQLite: Built-in Python support (no external libraries required).
- Install Python 3.12 from the official Python website: https://www.python.org/downloads/.
- No external libraries are required, as SQLite is built into Python.
- Update the
folder_with_dbsvariable with the path to the folder containing.dbfiles. - Run the script:
python clear_db_data.py
- The script will process all
.dbfiles in the specified folder and clear the data from all tables.
- Place
.dbfiles in a folder, e.g.,C:\Data\DB_Folder. - Set
folder_with_dbstoC:\Data\DB_Folder. - Run the script to clear data from all tables in each
.dbfile within the folder.
- The script will not remove tables or modify the database schema, it only clears the data from the tables.
- Ensure that the folder path is correctly specified and the
.dbfiles are valid SQLite databases.
Feel free to fork the repository and submit pull requests for enhancements or bug fixes.
This project is licensed under the MIT License.
For questions or issues, please open an issue in the repository or contact the maintainer.