How would you execute a stored procedure in SQL Server (using windows authentication) from a batch file?
Asked
Active
Viewed 7.5k times
3 Answers
34
If you are using Sql Server 2005+, you can use sqlcmd utility.
Example:
sqlcmd -Q "exec storedProcName" -S YourServer -d YourDatabase -o C:\yourOutput.txt

dugas
- 12,025
- 3
- 45
- 51
-
and you put this in a .bat file and run using cmd? – Nitrodbz Oct 19 '12 at 18:54
-
1Yes, you can execute from a .bat file. – dugas Oct 19 '12 at 19:25
5
With SQL Server 2005 and above you can use sqlcmd.exe. More info about how to use it:

Robin V.
- 1,484
- 18
- 30