Friday, March 23, 2012

Scheduling a .sql file through "jobs"

This is going to be a stupid, easy question; but I'm a SQL Server Newbie, so
here goes...
I have a .sql file that I need to schedule to run through SQL Server. The
actual SQL in it is too large to be pasted into the Exec Transact-SQL screen
on the scheduler. Is there a way to just call the .sql file from
transact-sql? Something like, "exec c:\scripts\analyzedb.sql", or something
along those lines? I've just been looking and looking for this, and can't
find it... thanks for any help anyone can give me.
Set the type of your jobstep to CmdExec instead of TSQL. CmdExec steps can
run commandline commands and batch files. You can then use the SQL Server
command line tool to run the script. The syntax for this is something like:
osql -E -i yourfilename.sql
For more details on osql see Books Online.
Jacco Schalkwijk
SQL Server MVP
"Amy" <Amy@.discussions.microsoft.com> wrote in message
news:999685D4-886D-42B0-A24A-F8A4FEBCAE00@.microsoft.com...
> This is going to be a stupid, easy question; but I'm a SQL Server Newbie,
> so
> here goes...
> I have a .sql file that I need to schedule to run through SQL Server. The
> actual SQL in it is too large to be pasted into the Exec Transact-SQL
> screen
> on the scheduler. Is there a way to just call the .sql file from
> transact-sql? Something like, "exec c:\scripts\analyzedb.sql", or
> something
> along those lines? I've just been looking and looking for this, and can't
> find it... thanks for any help anyone can give me.
>
|||Thanks, Jacco! That was just what I needed to know... :-)
"Jacco Schalkwijk" wrote:

> Set the type of your jobstep to CmdExec instead of TSQL. CmdExec steps can
> run commandline commands and batch files. You can then use the SQL Server
> command line tool to run the script. The syntax for this is something like:
> osql -E -i yourfilename.sql
> For more details on osql see Books Online.
> --
> Jacco Schalkwijk
> SQL Server MVP
>
> "Amy" <Amy@.discussions.microsoft.com> wrote in message
> news:999685D4-886D-42B0-A24A-F8A4FEBCAE00@.microsoft.com...
>
>

No comments:

Post a Comment