Schedule Script in agent job

  • How do I run a sql script in a sqlagent job? I have a SQL script I want to schedule and run as a job. script name is d:\scripts\reindex.sql

    I know the command for executing Stored procedures but I don't want to create a stored procedure for it. The script will change daily so if I know the command string I need to use in the command section of the jobs, I could do this. Does anyone run sql scripts?

    thanks,

  • In SSMS, create a new job with a new job step. Set Type as "Transact-SQL script (T-SQL)" and type your T-SQL directly in the Command box. Alternately, you can use sqlcmd.exe in the Command box to run your script file. You have to specify the path name for sqlcmd.exe e.g. C:\Program Files\Microsoft SQL Server\90\Tools\Binn\sqlcmd.exe -i C:\myfolder\myscript.sql

    Greg

  • Thanks, that's what I did for now.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply