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
0
votes
1 answer

Not able to execute sql command through a session created using POPEN in python

I'm trying to connect to SQL server using the below code I'm getting error invalid argument. I'm trying to read from a sql file and the run the query on the session created by popen using sqlcmd. My SQL file contain this code - select…
Hemant
  • 1,313
  • 17
  • 30
0
votes
2 answers

how to connect to Microsoft Sql Server 2000, sql server 2005, sql server 2008 and sql server 2012 using the sqlcmd from the same machine?

I need to connect to different sql server databases through python script. I'm trying to use the sqlcmd or sql native client to connect to all these databases.I've installed the native client for sql 2005 and 2008 but all I'm seeing is sql native…
Hemant
  • 1,313
  • 17
  • 30
0
votes
1 answer

Pass parameter in create table using batch file and SQLCMD

I have to pass a parameter (date) into a create table script that will be triggered via a batch file. I have used SQLCMD and the code is as follows Batch for /f "tokens=1-4 delims=/:." %%a in ("%TIME%") do ( set hh=%%a&set nn=%%b&set…
Vibhav MS
  • 33
  • 1
  • 3
  • 7
0
votes
1 answer

using sqlcmd command to get the result to a file in a shared path with user name and password protection

I have a sqlcmd command which will give the result of to a file which will be placed in a shared folder. exec xp_cmdshell 'sqlcmd -s $dataSource -d $dbName -i $inputFilePath -o $outputFilePath' Now, what if the shared drive is protected and…
Shavez
  • 63
  • 1
  • 13
0
votes
2 answers

Getting connectivity error when using :connect command in sqlcmd, but not when doing command line connect

I'm just starting out with sqlcmd on SQL Server 2005, enterprise edition. I can connect to my server fine, from the command line: sqlcmd -SSQLSERVERNAME -Q"select test=1" However, when I create a junk.sql file that has just this one line: :connect…
Sylvia
  • 2,578
  • 9
  • 30
  • 37
0
votes
1 answer

sqlcmd runs script but script does not affect database

So we have a .bat file that runs SQL scripts, e.g. @ECHO --- 03_Case6395_Publication.sql --- >> dbupt.log sqlcmd -U %1 -P %2 -S %3 -d %4 -i 03_Case6395_Publication.sql -k -b >> dbupt.log IF ERRORLEVEL 1 GOTO ErrorTag The script runs and gives no…
nickytonline
  • 6,855
  • 6
  • 42
  • 76
0
votes
1 answer

How to run sqlcmd remotely on a machine which does not have SSMS

Is there a way in which we can run sqlcmd on a machine without having SSMS.
Shavez
  • 63
  • 1
  • 13
0
votes
1 answer

Batch File Error when running the scheduled job

sqlcmd -S servername\sqldeveloper -E "EXEC sp_BackupDatabases @databaseName=’myDatabase’ , @backupType='F', @backupLocation='D:\Backup\'" this is my batch file query for backup database. but when i run this its giving the following error: 'EXEC…
Praveen Kumar
  • 27
  • 1
  • 7
0
votes
2 answers

Share C# program on network

I have a problem with share a C# program on network. I installed SQL Server 2008 R2 and I enabled TCP/IP and remote connection on it also I can connect to server with sqlcmd -U usr -P pwd -S 192.168.1.11\SQLEXPRESS without any problem but when I…
amin
  • 9
  • 2
0
votes
2 answers

Need sql commands to automatically execute each line in batch file

Trying to set up batch file to automatically execute sql commands. Can type them manually, but cannot figure out how to get it to run each line by itself. This is what I have (need to set sa user automatically: sqlcmd -E EXEC sp_password NULL,…
user2665375
  • 3
  • 1
  • 5
0
votes
1 answer

How to save a SQLCMD code as a executable file

I have a set of SQLCMD codes which are to be saved as exe files so that people can just execute the file rather than copy paste the code and run the command in command line.
Illuminati
  • 555
  • 2
  • 7
  • 34
0
votes
2 answers

SQL Server: Stopping Queries Externally

I run queries using SQLCMD utility via PHP and I wanted to know if there was a way to stop queries or scripts that I have executed via another SQL command by passing the process ID or something. I also make use of the PHP Driver for SQL Server would…
Abs
  • 56,052
  • 101
  • 275
  • 409
0
votes
0 answers

Looking for an easier way to create a database from a subset of another database

For testing I'm looking for a good way of pulling say 500 members out of a 300,000 member database, along with all the dependencies, and placing them into a new database. To do this originally I was using jailer but that application was creating…
Classtronaut
  • 203
  • 4
  • 9
0
votes
0 answers

OSQL.exe is not a valid WIN 32 application

I am trying to compile some indexes using osql.exe command utility (sql server 2008 R2) but getting this error- Error: OSQL.Exe is not a valid Win32 application. Command: C:\Program Files\Microsoft SQL Server\100\Tools\Binn>osql.exe -S 10.42.92.11…
Praveenks
  • 1,436
  • 9
  • 40
  • 79
0
votes
1 answer

sqlcmd won't accept password as part of the initial command

I am using sqlcmd to query a SQL server database from a UBUNTU machine (an ODBC driver was installed for this purpose) If I pass the following command: sqlcmd -S xyz -d xyz -U xyz I am prompted for a password, and I can then successfully query…
ALB
  • 3
  • 1
  • 3