Skip to main content

It will split all the table and views of a schema in a file, into its respective files

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dbsplitsql-0.0.11.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dbsplitsql-0.0.11-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file dbsplitsql-0.0.11.tar.gz.

File metadata

  • Download URL: dbsplitsql-0.0.11.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for dbsplitsql-0.0.11.tar.gz
Algorithm Hash digest
SHA256 bb28987e3f36ccfd5a664531644991b5e9fe3206d8321b6878cf0a6d61b76efa
MD5 21fff1607c1587ba48b382f91d814e75
BLAKE2b-256 e880a9693a8077ef83e394a8a39eca2e7e8300eb46dcdcc35927131e21c48469

See more details on using hashes here.

File details

Details for the file dbsplitsql-0.0.11-py3-none-any.whl.

File metadata

  • Download URL: dbsplitsql-0.0.11-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for dbsplitsql-0.0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 67733ed6b94d178e39c78af96cbaae7d07740bf7a02fd67fac07f12e04854dda
MD5 74e03363b04bdf23367a090876c55a21
BLAKE2b-256 53365a7c7ece11419871faaf9229057906012f76c6fb61a490df4bcc6baf0486

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page