Skip to content

Instantly share code, notes, and snippets.

@ettorerizza
Last active April 25, 2020 16:49
Show Gist options
  • Save ettorerizza/33cb3bc9e491bcfb216901eb43d81388 to your computer and use it in GitHub Desktop.
Save ettorerizza/33cb3bc9e491bcfb216901eb43d81388 to your computer and use it in GitHub Desktop.
bulk import a folder of csv into sql server, creating tables on the fly
#Install-Module dbatools
#In case of scripts are disabled, run first :
#powershell -noprofile -ExecutionPolicy bypass
import-module dbatools;
Get-ChildItem -Path "C:\CSV_PATH" | ForEach-Object {
Import-DbaCsv -Csv $_.FullName -SQLInstance "DESKTOP-C5EUKT9" -Database "stagging" -AutoCreateTable
}
# alternative using csvkit is a bit more accurate, but much slower:
#csvsql --db mssql+pyodbc://servername/databasename?driver=SQL+Server+Native+Client+11.0 --overwrite --insert my.csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment