Skip to content
Andrew Fenna edited this page May 23, 2016 · 6 revisions

Run SQL scripts & commands using SQL Server's sqlcmd.exe application. This task only supports a subset of commonly used commands, please contribute more!

desc "Create the initial database"
sql_cmd :create do |cmd|
   cmd.server = "myserver"
   cmd.database = "somedatabase"
   cmd.trusted_connection
   cmd.scripts = ["create.sql", "update.sql"]
   cmd.exe = "path to sqlcmd"
end

##Required Parameters #1 server #1 database #1 scripts #1 exe

##Optional Parameters ##Server & Database

The name of the server and database to connect to and use. By default, sqlcmd uses the default instance on localhost.

server = "myserver" database = "somedatabase" If you have to pass an instance name, it requires a backslash. So, it must be escaped, by using a double-backslash.

server = "myserver\myinstance" Username & Password OR Trusted Connection

##TODO The username and password to connect as.

username = "Someone" password = "FooBar"

Or, you can login with Windows integrated security. Without any authentication parameters, sqlcmd uses a trusted connection implicitly, so this is often not required at all.

##trusted_connection

##Scripts

The script files for sqlcmd to execute.

scripts = ["script1.sql", "script2.sql"]

Clone this wiki locally