Questions tagged [sqlcmd]

SQLCMD is a command line tool used to run SQL batches on Microsoft SQL Server.

SQLCMD.EXE is a command line tool used to run SQL batches on Microsoft SQL Server. Get help by running SQLCMD -? and by searching for SQLCMD in the documentation for SQL Server Management Studio. SQLCMD is installed as a part of the Microsoft SQL Server client tools package, and completely supersedes OSQL.EXE.

In addition to command line flags, SQLCMD supports 18 special commands inside SQL files that are not a part of T-SQL syntax. SQLCMD commands aside from "GO" must be prefixed with a colon (:) and appear at the beginning of a line.

SQL Server Management Studio also supports these 18 commands if you select "SQLCMD Mode" from the "Query" menu. This disables IntelliSense.

Reference

SqlCmd on Microsoft TechNet

1169 questions
6
votes
1 answer

How to show progress in a batch file using sqlcmd?

I'm doing a backup of a large database in a dos batch file (not powershell), using sqlcmd (sqlcmd reference). It takes about 30 minutes. sqlcmd -S 127.0.0.1 -d DbNameHere -E -Q "BACKUP DATABASE [DbNameHere] TO DISK = N'c:\Temp\MyBackup.bak' WITH…
Thierry_S
  • 1,526
  • 16
  • 25
6
votes
1 answer

Create zip file from SQL Server

Here is code which I use to create a .rar file with a password DECLARE @source VARCHAR(1000), @destination VARCHAR(1000), @Command VARCHAR(1000) SET @source = 'E:\Temp\testRar.txt' SET @destination = 'E:\Temp\testRar.rar' SET…
tungula
  • 578
  • 1
  • 6
  • 12
6
votes
3 answers

Running sqlcmd locally - Error Locating Server

I am trying to run a SQL script locally using sqlcmd, but I keep getting the following response: HResult 0xFFFFFFFF, Level 16, State 1 SQL Server Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF]. Sqlcmd : error : Microsoft…
Dave New
  • 38,496
  • 59
  • 215
  • 394
6
votes
7 answers

Remove column header from SQL Server query result

I want to remove column header from SQL Server query output. I did the search but not found any solution. I have a query eg. select cc.DepartmentID , cc.Name from HumanResources.Department cc When I run this query I am getting output like…
Roxx
  • 3,738
  • 20
  • 92
  • 155
6
votes
8 answers

How to encrypt all existing stored procedures of a database

Is there any possibility to encrypt all existing stored procedures of a SQL Server 2008 database AFTER they have been created via an SQLCMD script? The reason I want to do this is the following: I'd like to develop the stored procedures without…
Marc
  • 9,012
  • 13
  • 57
  • 72
6
votes
0 answers

Visual Studio Database Deployment - Script not running in SQLCMD mode

I have a SQL Server 2008 Database Project that I'm attempting to deploy using Visual Studio 2010. When I click deploy, the build works fine, but after it creates the deployment script and begins to execute it, I get the following errors: Error 8 …
6
votes
1 answer

SQL Server 2008 in single-user mode allows no connections

I don't know the SA password so I restarted my SQL Server 2008 Standard Edition instance in Single-user mode with the hope of changing the SA password. Immediately afterwards I tried connecting with sqlcmd -S serverName\ss2008 Msg 18461, Level 14,…
Blanthor
  • 2,568
  • 8
  • 48
  • 66
5
votes
8 answers

How to execute a 3GB SQL file (Microsoft SQL Server)?

I have a big SQL file that does not fit into memory and needs to be executed against Microsoft SQL Server 2008. It seems that the sqlcmd.exe tool always loads it into memory first which is impossible in this case. Any ideas? Unfortunately, I can't…
tobi
5
votes
1 answer

Programmatically detect which SQL Server is principal,which is the mirror?

I am looking for a way to programmatically query which SQL server is serving as the principal SQL server and which one is the mirror in a pair. Does anyone know if this is possible via PowerShell (SQLPS) or CMD (SQLCMD)? If so, how can I go about…
SRG
  • 51
  • 2
5
votes
2 answers

How can I run sqlcmd.exe from an ASP page?

As part of our database revision control (and auto-installation) procedures we need to be able run sqlcmd.exe on various .sql files from within an ASP page. The code I'm using to do this is: Dim cmd : cmd = "sqlcmd -S " & DATABASE_SERVER & " -U " &…
jammus
  • 2,540
  • 23
  • 28
5
votes
3 answers

sqlcmd not connecting to Azure database

I am trying to use the command below to access my database within Azure sqlcmd -s tcp:DBNAME HERE.database.windows.net -U USERNAME -P PASSWORD I get the error Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Named Pipes Provider: Could…
Paul
  • 2,773
  • 7
  • 41
  • 96
5
votes
4 answers

Sqlcmd: Error: Microsoft SQL Server Native Client 10.0 : Communication link failure

Below, you'll notice some Windows Command Prompt commands that I'm trying to call from the 64 bit Program Files folder for Microsoft SQL Server 2008 C:\Program Files\Microsoft SQL Server\100\Tools\Binn>SQLCMD -S "SQLI2B2" -d "I2B2_CRC-DEV" -i…
JustBeingHelpful
  • 18,332
  • 38
  • 160
  • 245
5
votes
2 answers

Using double quotes in a T-SQL script fails in SQLCMD, but not SSMO

Executing the following script via sqlcmd fails. However, executing it via ssmo or SQL Server Management Studio works. sqlcmd -S . -d test -i input.sql input.sql: CREATE FUNCTION test() RETURNS @t TABLE ("ID" INT) AS BEGIN RETURN END …
RichB
  • 520
  • 5
  • 10
5
votes
3 answers

Drop DB but don't delete *.mdf / *.ldf

I am trying to automate a process of detaching and dropping a database (via a VBS objshell.run) If I manually use SSMS to detach and drop I can then copy to database files to another location... however if I use: sqlcmd -U sa -P MyPassword -S…
Qazxswe
  • 139
  • 1
  • 4
  • 10
5
votes
2 answers

sqlcmd access : password with special character

i try to access with sqlcmd by this command: sqlcmd -U sa -P $test$ -S hostname -d db_test -i .\prova.sql > upgrade.log but the login failed. The password i correct, i think is a problem with special character, in this case the $. Do yuo have any…
fabrix_00
  • 153
  • 4
  • 5
  • 11