Skip to main content

dbsplitsql

A lightweight Python utility package to split and process large SQL scripts into manageable SQL statements.

Overview

dbsplitsql is a Python package designed to help developers and database engineers split large SQL files into individual executable SQL statements. It is useful for:

  • Database migration scripts
  • SQL deployment automation
  • ETL workflows
  • SQL parsing utilities
  • Handling large SQL dump files

This package was originally created and published on PyPI in 2019.


Features

  • Split large SQL scripts into separate queries
  • Lightweight and easy to use
  • Supports automation workflows
  • Useful for database maintenance and migrations
  • Open-source Python utility package

Installation

Install directly from PyPI:

pip install dbsplitsql

Usage

Usage

Process a Single SQL File

python main.py -f hr.sql

This generates object-wise DDL files inside the DDLS folder.

Example output:

DDLS/
    hr/
        departments.sql
        employees.sql
        vw_employee_details.sql
        fn_get_employee_count.sql
        trg_employee_insert.sql

Process Multiple SQL Files from a Directory

Suppose your directory structure is:

testddl/
    hr.sql
    sales.sql

Run:

python main.py -d testddl

Generated output:

DDLS/
    hr/
        departments.sql
        employees.sql
        vw_employee_details.sql
        fn_get_employee_count.sql
        trg_employee_insert.sql

    sales/
        customers.sql
        orders.sql
        vw_order_summary.sql
        fn_total_orders.sql
        trg_order_insert.sql

Supported Database Objects

The utility currently supports splitting:

  • TABLES
  • VIEWS
  • FUNCTIONS
  • TRIGGERS
  • PROCEDURES

It also preserves associated:

  • ALTER TABLE constraints
  • PRIMARY KEYS
  • FOREIGN KEYS
  • CHECK constraints

until the next CREATE object statement is encountered.


Features

  • Supports enterprise-style DDL extracts

  • Handles multiple schemas in a single file

  • Handles multiple schema files in a directory

  • Automatically creates schema-wise folders

  • Splits database objects into separate SQL files

  • Removes:

    • GO statements
    • separator comments
    • extraction headers
  • Preserves ALTER TABLE constraints with parent object


Output Structure

Generated DDLs are organized schema-wise:

DDLS/
    schema_name/
        object_name.sql

Example Supported DDL

CREATE TABLE hr.employee
(
    employee_id INT
)
GO

ALTER TABLE hr.employee
ADD CONSTRAINT pk_employee
PRIMARY KEY(employee_id)
GO

Generated file:

employee.sql

Content:

CREATE TABLE hr.employee
(
    employee_id INT
)

ALTER TABLE hr.employee
ADD CONSTRAINT pk_employee
PRIMARY KEY(employee_id)

Project Links


Technologies Used

  • Python
  • SQL
  • PyPI Packaging
  • GitHub

Contributing

Contributions are welcome.

Steps to Contribute

  1. Fork the repository
git clone https://github.com/balagdivya/dbsplitsql.git
  1. Create a new branch
git checkout -b feature-name
  1. Make your changes

  2. Commit changes

git commit -m "Added new feature"
  1. Push the branch
git push origin feature-name
  1. Create a Pull Request on GitHub

Publishing to PyPI

Build the package

python setup.py sdist bdist_wheel

Install Twine

pip install twine

Upload to PyPI

twine upload dist/*

License

MIT License


Author

Divya Goteti

Release files for dbsplitsql 0.0.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dbsplitsql 0.0.11
File Size Uploaded
dbsplitsql-0.0.11.tar.gz 5.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dbsplitsql 0.0.11
File Interpreter ABI Platform
dbsplitsql-0.0.11-py3-none-any.whl Python 3 none any Details

Total release size: 12.0 kB

Release files / dbsplitsql-0.0.11.tar.gz

Download URL dbsplitsql-0.0.11.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
bb28987e3f36ccfd5a664531644991b5e9fe3206d8321b6878cf0a6d61b76efa
BLAKE2b-256 checksum
How to use checksums
e880a9693a8077ef83e394a8a39eca2e7e8300eb46dcdcc35927131e21c48469
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Release files / dbsplitsql-0.0.11-py3-none-any.whl

Download URL dbsplitsql-0.0.11-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
67733ed6b94d178e39c78af96cbaae7d07740bf7a02fd67fac07f12e04854dda
BLAKE2b-256 checksum
How to use checksums
53365a7c7ece11419871faaf9229057906012f76c6fb61a490df4bcc6baf0486
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Release history Release notifications | RSS feed

This release

0.0.11 This release

2 release files

0.0.8

3 release files

0.0.7

1 release file

0.0.6

1 release file

0.0.5

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page