https://github.com/jabercrombia/csv-to-sql
A simple Python script that converts CSV files into SQL CREATE TABLE and INSERT statements. Drop your CSV files into the csv/ directory, run the script, and get structured SQL output in the sql/ directory
https://github.com/jabercrombia/csv-to-sql
csv pandas python sql
Last synced: about 1 year ago
JSON representation
A simple Python script that converts CSV files into SQL CREATE TABLE and INSERT statements. Drop your CSV files into the csv/ directory, run the script, and get structured SQL output in the sql/ directory
- Host: GitHub
- URL: https://github.com/jabercrombia/csv-to-sql
- Owner: jabercrombia
- Created: 2025-03-20T18:35:05.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-20T19:16:23.000Z (about 1 year ago)
- Last Synced: 2025-03-20T20:47:30.179Z (about 1 year ago)
- Topics: csv, pandas, python, sql
- Language: Python
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# CSV to SQL Converter
This script converts CSV files from the `csv/` directory into SQL `CREATE TABLE` and `INSERT` statements, saving the output in the `sql/` directory.
## Directory Structure
```
project_root/
│-- csv/ # Place CSV files here
│-- sql/ # Generated SQL files are saved here
│-- script.py # Python script to convert CSV to SQL
```
## Input Requirements
- CSV files should be placed in the `csv/` directory.
- The first row must contain column names.
- Ensure correct formatting (e.g., no empty headers).
## Usage
1. **Install Dependencies** (if not installed):
```sh
pip install pandas
```
2. **Run the Script**:
```sh
python script.py
```
3. **Output**:
- The generated SQL file is saved in the `sql/` directory.
- It is named after the CSV file (e.g., `csv/data.csv` → `sql/data.sql`).
## Next Steps
- Improve SQL type inference (e.g., `INTEGER` for `id`, `year`).
- Add error handling for incorrect CSV formats.
- Optimize bulk inserts for efficiency.