SQL

Bulk importing CSV files into SQL

I am working on a way to import the NAR files from my EMC CX4s to a SQL database. I have been reviewing the performance data of several databases, and have realized that not all the LUNs need as much performance they were sized for. As such, I have been able to reclaim some disk, but this is a slow and tedious process.
So my thinking was – Import the NAR data into a SQL database and use simple queries to summarize the data. Eventually, I will create a SSRS report to automate all of it.

Inserting from SQL is surprisingly simple. Per http://sqlserver2000.databases.aspfaq.com/how-do-i-load-text-or-csv-file-data-into-sql-server.html, if you have the table pre-created, simply run:

BULK INSERT OrdersBulk 
    FROM ‘c:file.csv’ 
    WITH 
    ( 
        FIRSTROW = 2
        FIELDTERMINATOR = ‘,’, 
        ROWTERMINATOR = ‘n’ 
    )

Leave a Reply