Running SQL Query From Batch File- MS SQl 2000 Mar 25, 2008. Hello, I am looking for some way to run a sql query from a batch file on the SQL server. The query needs a user entered parameter, if that can be accomodated it would be great. I read about some osql command & tried to run it but it kept saying 'Server does not exist or access denied.' Sep 05, 2017 SQL Server execute BAT file Axeshkumar Patel. How to Create Batch file to Execute SQL Scripts. SQL Server DBA Tutorial 121-How to Run SQL Server Agent Jobs in Batch File.
Active9 years, 4 months ago
I want to create backup job on sql server. And i want to execute batch file in job. I just wonder the part of executing batch file from sql job. Do you have any idea?
Any help would appreciated.
uzay95uzay95
migrated from superuser.comMay 25 '10 at 12:48
This question came from our site for computer enthusiasts and power users.
Tsql Execute Sql File
2 Answers
If you do this is as a SQL Server Agent job (from SSMS) it makes calling batch files a lot easier. Just add a step of type '
Chris_KChris_KOperating System (CmdExec)
' and point it to your .bat file.2,76466 gold badges3535 silver badges4444 bronze badges
If you're using besides sql server 2008 enterprise (or above) then xp_cmdshell is the way to do it, although you'll have to enable it first with sp_configure.
If you are lucky enough to be on mssql 2008 enterprise then the backup compression feature is what you should be using.
You may want to do something a bit more advanced then calling a static.bat file.Here are some useful samples:
Sample sql script to zip and transfer database backup file
How to take SQL database backup in .zip format
Sample sql script to zip and transfer database backup file
How to take SQL database backup in .zip format
Community♦
Nick KavadiasNick Kavadias10.3k77 gold badges3131 silver badges4545 bronze badges