Skip to content

Karthikn07-K/SQL-Batch-Runner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🗄️ SQL Batch Runner

A lightweight web-based tool to run multiple SQL scripts sequentially against a SQL Server database and export results as CSV files — all from your browser.

Python Flask License


✨ Features

  • 🔁 Run multiple .sql files in sequence with one click
  • ✏️ Inline SQL editor for the first query (editable before running)
  • 💾 Auto-export results to CSV with timestamps (no overwrites)
  • 🔐 Supports both Windows Auth and SQL Login
  • 📋 Live log viewer with status per step
  • ⛔ Cancel a running job mid-way
  • 📥 Download CSVs directly from the browser

📁 Project Structure

sql-batch-runner/
├── app.py               # Flask backend
├── requirements.txt     # Python dependencies
├── static/
│   └── index.html       # Frontend UI
├── sql/                 # Place your .sql files here
│   ├── 01_setup.sql
│   ├── 02_ledger.sql
│   └── ...
├── .gitignore
└── README.md

🚀 Quick Start

1. Clone the repo

git clone https://github.com/YOUR_USERNAME/sql-batch-runner.git
cd sql-batch-runner

2. Install dependencies

pip install -r requirements.txt

3. Install ODBC Driver (if not already)

Download ODBC Driver 17 for SQL Server from Microsoft.

4. Configure paths in app.py

Open app.py and update the two config lines near the top:

SQL_FOLDER        = r"C:\path\to\your\sql\files"   # folder containing your .sql files
BASE_OUTPUT_FOLDER = r"C:\SQL_Exports"              # where CSVs will be saved

You can also update the FILE_NAME_MAP dict to control the output CSV filename for each step:

FILE_NAME_MAP = {
    2: "Ledger",
    3: "Summary",
    4: "Reconciliation",
    ...
}

5. Run the app

python app.py

6. Open in browser

Navigate to: http://localhost:5000


🛠️ How It Works

Step Behaviour
File 1 Runs the editable query in the browser editor. No CSV saved.
Files 2–N Runs each .sql file in sorted order. Results saved as FileName_YYYYMMDD_HHMMSS.csv
  • SQL files are picked up automatically from SQL_FOLDER, sorted alphabetically.
  • The first file's SQL can be edited directly in the UI before running.
  • All output CSVs are saved under a user-specified subfolder inside BASE_OUTPUT_FOLDER.

⚙️ Configuration Reference

Variable Description
SQL_FOLDER Directory containing .sql files
BASE_OUTPUT_FOLDER Root directory for CSV exports
FILE_NAME_MAP Maps file index → friendly CSV filename

📦 Dependencies

Package Purpose
flask Web server and REST API
pyodbc SQL Server connectivity

🤝 Contributing

Contributions are welcome! Please:

  1. Fork the repo
  2. Create a feature branch (git checkout -b feature/your-feature)
  3. Commit your changes (git commit -m 'Add some feature')
  4. Push to the branch (git push origin feature/your-feature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License — see the LICENSE file for details.

About

Browser-based tool to run multiple SQL Server scripts sequentially and export results as CSV — built with Flask and pyodbc.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors