0

I have a couple .sql scripts. I want to write a wrapper function/script to call and run all of those .sql files. It can be either in sql or powershell.

I appreciate any help.

3
  • What do you mean by either SQL or Powershell? If you want to run in SQL, you can add all scripts(.sql) to stored proc. Commented Jul 30, 2015 at 15:16
  • I mean I need to write a script either with sql or powershell. Commented Jul 30, 2015 at 15:25
  • thanks. so what would be a sample code in my store proc ? Commented Jul 30, 2015 at 15:26

1 Answer 1

2
Get-ChildItem -Path "path_to_folder_with_scripts" -Filter "*.sql" | % {invoke-sqlcmd -InputFile $_.FullName}

Edit path_to_folder_with_scripts to your path to folder with sql files

Sign up to request clarification or add additional context in comments.

2 Comments

This only shows the sql files in folder. I need to run them.
@kimitrio: that's what the pipe to invoke-sqlcmd does.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.