Create SQL Server job automatically

前端 未结 5 1506
北恋
北恋 2020-12-18 12:27

I am writing SQL Server deployment scripts which create SQL Server job automatically on a specific SQL Server server/instance. I have found that I can extract the sql statem

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-18 12:42

    Futher to BrianD's answer above, you can define variables (actually more like preprocessor macros than variables) at the sqlcmd level; these are enclosed in parentheses with a leading $ sign:

    SET @JobName = '$(JobName)'
    SET @Owner = '$(Owner)'
    

    This allows you to pass the information on the command line to sqlcmd with the -v switch:

    sqlcmd -... -i create_jobs.sql -v JobName=Job1 -v Owner=BrianD
    

提交回复
热议问题