https://github.com/ttulka/sql-tables-sorter
SQL Tables Sorter
https://github.com/ttulka/sql-tables-sorter
database java schema sql sql-tables-sorter table
Last synced: 2 months ago
JSON representation
SQL Tables Sorter
- Host: GitHub
- URL: https://github.com/ttulka/sql-tables-sorter
- Owner: ttulka
- License: apache-2.0
- Created: 2017-07-24T05:55:13.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-07-25T06:32:46.000Z (almost 9 years ago)
- Last Synced: 2025-12-26T12:52:16.370Z (6 months ago)
- Topics: database, java, schema, sql, sql-tables-sorter, table
- Language: Java
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SQL Tables Sorter
Calculates the right order of the tables from a SQL creation script (for example an SQL script generated from `mysqldump` etc.).
## Prerequisites
- Java 8
- Maven
## Usage
First, clone or fork the repository:
```
$ git clone git@github.com:ttulka/sql-tables-sorter.git
$ cd sql-tables-sorter
```
Now build it:
```
$ mvn clean package
```
And finally run it:
```
$ java -jar target/SqlTablesSorter-1.0-SNAPSHOT.jar -f
```
### Example
*dump.sql*
```sql
CREATE TABLE `attachment` (
id INT,
name VARCHAR(100),
content TEXT,
document_id INT,
CONSTRAINT `fk_document` FOREIGN KEY (`document_id`) REFERENCES `document` (`id`)
);
CREATE TABLE `document` (
id INT,
title VARCHAR(100),
content TEXT,
patient_id INT,
CONSTRAINT `fk_patient` FOREIGN KEY (`patient_id`) REFERENCES `patient` (`id`)
);
CREATE TABLE `patient` (
id INT,
full_name VARCHAR(100)
);
```
```
$ java -jar target/SqlTablesSorter-1.0-SNAPSHOT.jar -f dump.sql
```
Output
```
patient
document
attachment
```
## License
[Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)