0

I have over than 200 csv files that each of them is diffrent table.

I create now a new DB and want to upload them all so I will have all the table.

I not accessable to old DB to backup in diffrent way.

I looking for a simple way to do it fast (script/gui/ 3pary tool)

I found I can do it with sqlServer gui but I cant upload there multiple files, only 1 by 1, so it will takes hours.

I saw this post How to upload multiple csv files to sql server without constrains but it not help me, not found there any solution.

  • You could use a PowerShell script to create the tables and import data but the code would need to determine table names based on file names, determine column names based on the file header names (if you have those), and guess at proper column data types. If you don't have the source database schema available, the best you can do is guess at data types. – Dan Guzman Jul 22 '18 at 13:42
  • All is on csv files, but how can I put them all in DB with power shell – Jonert6544 Jul 22 '18 at 21:04
0

I you want to use powershell to upload these CSV files, w/out having to code/script, take a look https://dbatools.io/. Look for the cmdlet Import-DbaCsvToSql

All the documentation is available on the site. Just download the tools from github or the powershell gallery.

You can use Get-ChildItem cmdlet to get all the CSV files in a folder and use the pipleline to send the files to import-dbacsvtosql

Get-ChildItem -Path "Path To your CSV's" | foreach-object{Import-dbacsvtosql -Csv $_.FullName -SQLInstance "yoursqlserver" -Database "yourdb"}

  • I didn't understand how to install this module offline , I follow dbatools.io/offline I use in win 7 so I download powershellgallery.com/api/v2/package/dbatools and change the extention to zip , and extract it to the powelshell module , now what? how to I install it? – Jonert6544 Jul 23 '18 at 15:49
  • did you follow the instructions at dbatools.io/download – Goforebroke Jul 23 '18 at 15:52
  • yes but I think I miss something , can you please help me with that ? – Jonert6544 Jul 23 '18 at 15:54
  • offline instructions. Unzip file and save to c:\programfiles\WindowsPowerShell\Modules. Just name the folder dbatools. Open a powershell prompt and run the command Get-ChildItem -Recurse c:\programfiles\WindowsPowerShell\Modules\dbatools | Unblock-File . Update the $env:PSMODULEPATH per this link docs.microsoft.com/en-us/powershell/developer/module/… – Goforebroke Jul 23 '18 at 16:01
  • That what I did ,save it to \Module , Don't I need to run something to install it? when I run on sqlserverPowerShell Import-dbacsvtosql I got error – Jonert6544 Jul 23 '18 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.