Questions tagged [sqlcmd]

SQLCMD is Microsoft SQL Server's command line utility that allows you execute T-SQL commands from a command prompt.

Filter by
Sorted by
Tagged with
0 votes
0 answers
24 views

Sqlcmd: The -W and the -y/-Y options are mutually exclusive

I am working on SQL server task. I need a sqlcmd result file with complete records with headers. Here is the command and error message below sqlcmd -S [Server_Name] -U [User_Name] -P [Password] -d [...
Yuvaraj's user avatar
1 vote
0 answers
46 views

SQL script to run from batch jobs

I have a sql script that truncates the table and insert into database from a linked server.Since the server is SQL express I will need to use batch jobs to schedule the jobs. Below is a snippet of the ...
SQL_NoExpert's user avatar
  • 1,049
0 votes
0 answers
98 views

SQLCMD - Access is Denied After Running Script

I'm working with a vendor about this, but a supplied script that they have to run to upgrade their software, after running, ruins access to SQLCMD. Before running the script I can open a Command ...
kblair's user avatar
  • 1
0 votes
1 answer
271 views

"Fatal scripting error" when parsing SQLCMD query

Similar issue seen here. I am trying to run the following command from SSMS running in SQLCMD mode. :r C:\dev\test scripts\sample.sql But I get the following error: A fatal scripting error occurred. ...
mft25's user avatar
  • 101
0 votes
0 answers
24 views

How to throw an error in SSDT Post-Deploy script to fail it's execution?

I'm using Microsoft SSDT to version DB schema. I have a script to autogenerate some triggers and i need to make sure that we don't forget to run it when tables change. I added a part to PostDeploy ...
Ivan Koshelev's user avatar
0 votes
1 answer
71 views

Neatly print sp_help output similar to psql \d+

I've just been granted access to a SQL Server data warehouse and I'm trying to get to grips with sqlcmd. Coming from a Postgres/psql background, I'm used to being able to quickly look up a table ...
Matt's user avatar
  • 271
1 vote
0 answers
266 views

What is the relationship between sqlcmd and ODBC driver

I'm trying to install sql server 2022 on a build machine, and then test that I can connect to that server with sqlcmd. I previously had ODBC driver 17 and was getting errors from that command, so I ...
britzkopf's user avatar
0 votes
1 answer
283 views

Failed to initialize sqlcmd library with error number -2147467259

This is my code: SET @msg = 'Customer Voice replies.'; SET @query= 'SELECT [column1],[column2] FROM [StagingMX].[dbo].[_CVA] WHERE DATEDIFF(day, [Completion time] ,GETDATE()) = 1 AND [...
Raúl Vélez's user avatar
0 votes
1 answer
137 views

Backup database on local pc

I am using this script to backup database on computer A: sqlcmd -U MyDatabase -P MyPassword -S .\SQLEXPRESS -Q "EXEC sp_BackupDatabases @backupLocation = 'c:\shared', @databaseName='MyDatabase', @...
dafie's user avatar
  • 171
2 votes
2 answers
646 views

SQLCMD fails if -c; is specified in parameters on SQL Server 2019

The following sqlcmd fails with no error and no output, just returns silently. SQLCMD -U dbuser -d dbname -w 255 -h-1 -P mypassword -S dbserver -Q "ALTER TABLE xyz ADD abcd NUMERIC(1)" -c; ...
Ozair Kafray's user avatar
0 votes
1 answer
124 views

Restoring SQL Server database on Windows instance from Linux SQLCMD

I have a SQL Server that is running under Windows. And I have a Linux client. AFAIK SQLCMD requires "local" (server-related) path to backup files. So the question is - how to specify windows ...
Eldhenn's user avatar
4 votes
2 answers
928 views

Suppressing SQL Server Management Studio's 'Messages' from output of SQLCMD via SQL Server Agent

I've created a script that outputs data in an XML format, and was using SQL Server Agent (Job Step of Type 'Operating System (cmdexec)') to run a job monthly/quarterly to output the data to a specific ...
Abe Dickenson's user avatar
0 votes
2 answers
2k views

Which install kit installs sqlcmd.exe?

I recently had to uninstall Visual Studio 2012 and DTS, then install VS 2017 and DTS again. Afterwards, The directory containing sqlcmd.exe was not in my PATH variable. I installed the following. ...
lit's user avatar
  • 231
0 votes
1 answer
228 views

How do I stop SQLCMD from misinterpreting variable parameters?

I have a server config script we call with SQLCMD that runs a lot of other scripts in a folder, using :R \\folder\path\script.sql. One of those scripts creates an Agent job that has a TSQL step that ...
Fredric Shope's user avatar
0 votes
0 answers
2k views

Comparing DATETIME value with the one in previous row and selecting it if its bigger by at least 5 minutes

I'm trying to write a query to select all rows in a table where the timestamp column's value is bigger by at least 5 minutes than the value in the previous row. My main problem is trying to get ...
kiw1498's user avatar
0 votes
1 answer
531 views

SQLCMD :CONNECT with a specific port?

In SSMS with TSQL is it possible to do a SQLCMD :CONNECT to a SQL Server with a specified port? Something like this: :CONNECT MySQLServer, 49603 I know there is the -S switch for SQLCMD in the ...
Conrad S.'s user avatar
  • 515
2 votes
2 answers
390 views

In SSMS, are IntelliSense and SQLCMD mode mutually exclusive?

In SSMS, are IntelliSense and SQLCMD mode mutually exclusive? Is there any way to make IntelliSense work when SQLCMD mode is enabled? (I use SQLCMD a lot) I'm trying to understand why IntelliSense ...
spinjector's user avatar
1 vote
1 answer
661 views

SQLCMD Using Powershell Gives No Response

I have SQL Server 2019 Standard installed on my Server 2019. I also have installed the SQL CMD Line tools V21.1.18246. When I open my PowerShell in Administrator mode and do a sqlcmd -? the command ...
JukEboX's user avatar
  • 121
0 votes
1 answer
272 views

sqlcmd is running but database shown no running query

We are facing this weird issue on our Azure setup. The database is SQLServer and client is CentOS. We fire queries using sqlcmd. Sometimes it happens that you see the sqlcmd running, but there is no ...
Manoj R's user avatar
  • 101
-1 votes
1 answer
559 views

How to not include the query in sqlcmd output file [closed]

I have a batch script that I am using to generate a dataset from a stored procedure but it keeps including the query that calls the stored procedure in the output file and I need it to stop. The batch ...
DruidsFlame's user avatar
0 votes
1 answer
2k views

Does SQLCMD "!!" command work in Azure Data Studio

In SQL Server Management Studio, it is possible to run batch commands when in SQLCMD mode, using the !! command. However, in Azure Data Studio, this does not seem to work (SQLCMD has been available in ...
Reversed Engineer's user avatar
0 votes
1 answer
233 views

Dumping mssql db from one server and restoring on another on Mac/Linux

Using either MacOS or Linux, my objective is to copy a database from one MSSQL database server to another. The source database server is remote, while the target database server (which will be ...
iskandarblue's user avatar
1 vote
1 answer
5k views

In mssql 2019 where sqlcmd utility is?

I am working on the tool that will silently deploy SQL server instance and I need to run a few scripts after installation, but I struggle to find where SQLCMD utility is. For example, I use this: ...
Dejan Dozet's user avatar
3 votes
2 answers
2k views

using SQLCMD to export/extract data withot trailing spaces

I am trying to extract data from some of my tables using sqlcmd utility as SSMS does not generate appropriate csv-s for me. My issue: all csv extract includes trailing spaces according to table ...
Oliver76's user avatar
1 vote
1 answer
372 views

Lost SQL credentials and unable to connect to SQL via SQLCMD

I have a machine running SQL 2014 but have neither the windows authentication or sa authentication details due to mismanagement of a previous support team. Having tried logging in to SQL Management ...
Fraz Mahmud's user avatar
0 votes
2 answers
4k views

How to find a list of local MS SQL Servers?

I looked at How can I determine installed SQL Server instances and their versions? already but CMD returns nothing: C:\Windows\system32>sqlcmd -L C:\Windows\system32> But when using Visual ...
Shervin Rad's user avatar
0 votes
1 answer
194 views

sqlcmd returns Msg 701 when importing +10MB queries

I have a powershell script that exports data from DBF files, saves them as .SQL files and then imports the SQL files into MS SQL 2016 using the sqlcmd command. There's one SQL file per table in my ...
VolrathTheFallen's user avatar
0 votes
0 answers
3k views

Remove (XX.. rows affected) from SQLCMD output to file [duplicate]

Using SQLCMD with -o to file. How to get rid of the (XX... rows affected) message at the end for a clean output?
EvolveX's user avatar
0 votes
1 answer
3k views

Encrypt connection when using sqlcmd

Trying to connect database with an encrypted connection, tried below sql queries: sqlcmd -N -E -S tcp:SQLSERVER,1234 -U username -P password -d Database -Q "INSERT INTO table1 VALUES(1,2,2) ERROR:...
chris's user avatar
  • 103
2 votes
2 answers
1k views

:!!echo command not working from sqlcmd

I have a sql script file which is executed from a batch file and is supposed to execute some sql scripts and write errors and output to files. Here is an example of how the script file looks like: :...
Daniela's user avatar
  • 21
0 votes
2 answers
685 views

Copy last modified files from network path into SQL server box and rename them using Agent job

I have to copy latest backup from a network path and bring that to my SQL server physical drive for restore, I have to do that using agent job. This is what i am doing. Created a SQL server agent ...
datalearner's user avatar
2 votes
1 answer
162 views

SQLCMD external editor

I have set the environment variable SQLCMDEDITOR=gvim to invoke an vim with the ED command of SQLCMD. From my old Windows 7 computer, it used to work. I have now a new laptop (windows 10) and, when ...
user2698903's user avatar
3 votes
2 answers
14k views

How to print results in SQLcmd window

I'tm trying to show in SQLcmd window the results of these queries: SELECT SYSDATETIME() AS "date"; PRINT 'EXTRAÍDO POR:' SELECT SUSER_NAME() AS "Owner" PRINT 'PASSWORD SETTINGS'; exec ...
Lucas's user avatar
  • 33
1 vote
1 answer
79 views

Why do I need DAC if I am able to connect to the server via sqlcmd?

DAC attracted my attention at the moment when I was unable to connect to the SQL Server using a traditional way (the reason was deleting logon trigger). I made some searches on the web and it turned ...
Rauf Asadov's user avatar
  • 1,253
2 votes
1 answer
4k views

Linux sqlcmd connecting to Windows Sql Server using kerberos

I'm pretty sure I am going to have to expand upon this a bit as I am new, and my question is probably not clear. I have an Active Directory environment that includes a Microsoft SQL Server running ...
Petter's user avatar
  • 121
1 vote
2 answers
1k views

How to create a csv with SQLCMD which can be imported into another database system

I may be doing this all the wrong way so please point me in the right direction if I am missing something. I have an Ubuntu server with SQLCMD installed and a Windows Server with a MSSQL database. I ...
Adsy2010's user avatar
  • 113
1 vote
3 answers
4k views

Invoke-SQLCmd Date output format

I’m having a problem with a result set that I am getting from a stored procedure when running a PowerShell script (Using Invoke-SQLCmd) to get the results and send the output to a .csv file. The date ...
Swiss Tony's user avatar
3 votes
2 answers
1k views

Suppress database change message in SQLCMD.exe

I am writing a script generation script. The script is generating list of DDL statments. The util_generator.sql generation starts with database connection: USE [TARGET_DATABASE] GO ... Many queries ...
Dudi Boy's user avatar
  • 151
2 votes
1 answer
403 views

Session ID in SQLCMD running multi-batch script

My script contains multiple GO keywords. I know that SQLCMD interprets GO as a batch delimiter, so the code is not run as a single block but instead each part between the delimiters (a batch) is run ...
Andriy M's user avatar
  • 22.9k
1 vote
1 answer
230 views

Restore ALL databases with sqlcmd in SQL Server (Express, Docker, 2017)

These documentation articles https://learn.microsoft.com/en-us/sql/linux/tutorial-restore-backup-in-sql-server-container?view=sql-server-2017 and https://learn.microsoft.com/en-us/sql/linux/sql-...
Chaim Eliyah's user avatar
0 votes
3 answers
2k views

Check if a SQL Login exists without SA

How can I check if a SQL Login exists for an arbitrary domain user if the account I'm running doesn't have SA rights to the instance (but will be dbo on at least one DB) Ideally I'd like the solution ...
Kelewan's user avatar
1 vote
1 answer
5k views

exporting a sql view to a csv file

Whilst I can just about script to pull data via queries, I'm finding it very difficult to figure out how to export the results of a query to a .csv file and save in a network storage location (novice ...
Stl's user avatar
  • 21
5 votes
1 answer
7k views

How to Natively Return Output when using Invoke-Sqlcmd?

How do I natively log output from the PowerShell Invoke-Sqlcmd? I am using Invoke-Sqlcmd to loop through a large (50,000-90,000 SQL files w/ 1-10 inserts in each) set of small SQL insert statements. ...
SQLSean's user avatar
  • 53
0 votes
2 answers
739 views

Are the switches for the SQLCMD command case sensitive?

I have MS SQL Server 2014 Management Studio installed on two computers, both of which run on Windows 10. The switches for SQLCMD command are case-sensitive on one computer, but it is not on the other ...
susmithsuresh86's user avatar
2 votes
1 answer
709 views

SQLCMD :connect directive - how can I specify connection protocol?

In a script I have the directive :connect DbServer and it seems that if I run this script in SQLCMD (like this: sqlcmd -i script.sql then sqlcmd attempts to connect using Named Pipes (which doesn'...
Yuri Makassiouk's user avatar
0 votes
1 answer
924 views

SQLCMD cannot connect my named instance

I am using SQL Server 2017 based on Windows server 2016. I am trying to connect my named instance, but I got the error message as below screenshot: So I tried to reinstall ODBC Driver 13. But I got ...
DBALUKE HUANG's user avatar
0 votes
1 answer
2k views

Msg 102, Level 15, State 1, Server DESKTOP-U368A1B, Line 1 Incorrect syntax near '1'

I get the above error message when i run the following perl script from the cmd, that is supposed to do some transaction in my database. #!/usr/bin/perl. use warnings; use strict; my ( $pid1, $...
user avatar
3 votes
1 answer
2k views

How do I force windows to use a specific version of SQLCMD?

I have several versions of SSMS installed on my machine. We have legacy servers running several versions of SQL Server, mainly 2008, 2012, and 2014. I use SQLCMD all the time, but it seems to default ...
Red_Shadow's user avatar
3 votes
1 answer
6k views

How to format the output of SQL queries on SQLCMD for SQL Server 2017 on RHEL Linux 7.3?

I have installed SQL Server 2017 on RHEL Linux 7.3, and using SQLCMD utility for querying the SQL Server. When I try to query for example: 'SELECT * FROM SYS.DATABASES'. I get output like the ...
SSS's user avatar
  • 397
4 votes
1 answer
2k views

SSMS generated script failing to execute

So I am in a situation where I need to import a small DB (under 1GB) from a newer version of SQL Server (I am restoring to a 2014 SQL Server from a 2016 SQL server), without a direct connection ...
Will's user avatar
  • 43