This project provides a utility for splitting a large SQL file into smaller SQL files, each containing the SQL script for creating a separate database table. Additionally, it can recombine those smaller SQL files back into a single SQL file.
- Split a large SQL file that contains multiple
CREATE TABLE
statements into separate SQL files, one for each table. - Optionally capture and include SQL header lines in each output file.
- Recombine the smaller SQL files back into a single SQL file.
- Display the progress of the file processing in the terminal.
- Command line interface for easy usage.
- A C++17 compatible compiler.
- CMake for building the project (optional).
Clone the repository and navigate to the project directory. Run the following commands to compile the code:
mkdir build
cd build
cmake ..
make
Releases are available for Windows, macOS, and Linux but we encourage you to compile the code yourself.
You can use the compiled binary directly from the command line:
SQLSplit <command> <options>
split
- Splits a SQL file into multiple table files.combine
- Combines multiple table files into a single SQL file.
- For split:
<input_file> [output_directory]
- For combine:
<input_directory> <output_file>
SQLSplit split database.sql output_directory
SQLSplit combine output_directory combined_database.sql
You can also use the project as a library in your own C++ project.
Include FileUtil.h
in your C++ project and use the FileUtil::splitSQL
and FileUtil::recombineSQL
methods.
#include "FileUtil.h"
int main() {
// Split SQL file
std::vector<std::string> outputFiles = FileUtil::splitSQL("path/to/large/sql/file.sql", "path/to/output/directory");
// Recombine SQL files
FileUtil::recombineSQL(outputFiles, "path/to/recombined/sql/file.sql");
return 0;
}
Contributions are welcome. Please open an issue or submit a pull request if you would like to contribute to the project.
This project is licensed under the MIT License - see the LICENSE file for details.