Getting CSV files into a database usually means an import wizard for one file at a time, or a script for many. Rons Data Stream does it with a saved Job: point it at a folder of CSV files, tell it which table or database to write to, and run it whenever new files arrive. It can clean the data on the way in, and it works in the other direction too, from SQL Server tables to CSV, JSON or XML.
Which Output to Choose
| You want | Output Format | Output Container |
|---|---|---|
| Rows in a SQL Server table | SQL Table | SQL Server |
| A SQLite database file | SQLite Database | Directory (SQLite cannot be written to Azure Blob Storage) |
SQL statements you can run yourself, for example one INSERT per row
|
Text Template | Directory |
Step 1 – Read the CSV Files
- Click New Job on the Start Page and save the Job.
- In the Job Palette, under Source Containers, click Directory and choose the folder with your CSV files. (The files can also come from Azure Blob Storage.)
-
Under Source Profiles, click CSV. Choose the
Source Container, set the file filter (for example
orders_*.csv) and the delimiter.
Every file that matches the filter is loaded in the same run.
Step 2 – Clean on the Way In (optional)
Databases are less forgiving than text files. A date in the wrong format or a stray space can stop an import or, worse, load quietly as the wrong value. Add a Cleaner under Data Cleaners to fix these first, for example:
- Replace Date Time to bring dates to one format, including Unix time stamps
- Remove Space and Change Case to tidy text
- Delete Column for columns the table does not need, or Add Column(s) for a column it does, such as a source or batch name
- Delete Row with a Filter selector to leave out rows you don't want to load
The Data Builder shows each file before and after the Cleaner, so you can check the data before anything is written to the database.
Step 3a – Write to SQL Server
- Under Output Containers, click SQL Server and enter the connection details for your server and database.
- Under Output Formats, click SQL Table and choose the SQL Server container.
- Set the table. The data is mapped to an existing table, or the table is created if it is missing. The SQL Table settings in the application show the options for a table that already exists.
Step 3b – Write to SQLite
- Under Output Containers, click Directory and choose where the database file goes.
- Under Output Formats, click SQLite Database and choose that container.
SQLite needs no server: the result is a single database file you can open with any SQLite tool or use in your own application.
Step 3c – Or Generate SQL Statements
If you prefer to review the SQL before running it, use a Text Template
output. A text template writes any text you like for each row, for example an
INSERT INTO … VALUES (…) statement, using the column values; the
Text Template settings in the application show how to insert them. The result is
a script you can run in SQL Server Management Studio or any other SQL tool. (Text
templates cannot be written to Azure Blob Storage.)
Step 4 – Check and Process
Open the Data Builder, check a few files, then click Process Job. Add an Output Logger to keep a log file of each load; it makes it easy to see which files loaded and which had errors.
The Other Way: SQL Server to CSV
The same Job can read from SQL Server. Add a SQL Server Source Container and a SQL Table Source Profile (tables and views can be read), then choose CSV, JSON, XML, HTML or another output format. This is a simple way to produce regular extracts for colleagues or other systems.
Running It Regularly
Once the Job works, run it again whenever new files arrive, or run it from a batch file or the command line so a scheduled task can do it. See How to Run a Nightly CSV Clean-up from the Command Line.
Rons Data Stream Lite is free and processes up to 3 files per run, enough to test your Job against a test database. Rons Data Stream Pro removes the limit; it is a one-time purchase of about US$30. Download Rons Data Stream.