Skip to content
Andrew Fenna edited this page May 10, 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"
sqlcmd :create do |cmd|
   cmd.server = "myserver"
   cmd.database = "somedatabase"
   cmd.username = "username"
   cmd.password = "password"
   cmd.scripts = ["create.sql", "update.sql"]
end

##Required Parameters ##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

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