Last active
April 25, 2020 16:49
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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