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
-1
votes
3 answers

executing sql files in for loop, error is not recorded and not stoping after error

in below batch script, I expect all scripts were kept at c:\temp and they will execute one by one and reord all successful/error records in log file, if any error occours then it should stop what syntex going wrong here, one more I kept this batch…
Hemu
  • 5
  • 8
-1
votes
1 answer

Get an error message from a SQL query back into Python

I need to be able to tell if SQL queries kicked off by Python have failed. So far I have: import subprocess p = subprocess.Popen(['sqlcmd', '-E -m-1 -S 1070854A\AISP -i NewStructures.sql >>process.log'], stdout=subprocess.PIPE,…
-2
votes
1 answer

What are the default locations that OSQL and SQLCMD search to connect to a server when -S option is not specified?

I am trying to identify how osql and sqlcmd resolve server name and user to connect to that server when we do not specify server using -S option and use -E option. Below is the output for various queries I ran. List all available servers on the…
Sachin Kumar
  • 808
  • 3
  • 11
  • 29
-2
votes
3 answers

How to execute a file.sql (script) and save the results in a file in my computer using CMD (SQLCMD)?

I need to run a script saved in my computer through CMD (SQLCMD) and save the result in other file in my computer.
leo stark
  • 1
  • 1
  • 1
-2
votes
1 answer

mvn build failed given error , 'sqlcmd' is not recognized .?

I used mvn , build tool to build my project. my sql server is MSSQL2017 . but when I , build project, it failed, given like this error. need some exptert help to fix it. [INFO] Creating database:…
uma
  • 1,477
  • 3
  • 32
  • 63
-2
votes
1 answer

How to create a SQL-SERVER database from several script files?

I've been struggling with this for several days. I have an application that uses a SQL SERVER database for storing its data. This database has several tables, stored procedures, functions and views. I used to generate a large database creation…
-2
votes
1 answer

Does the RoundhousE (database migration utility) support running SQL Server scripts in SQLCMD mode?

It would be awesome if this super RoundhousE database migration tool supported SQL Server scripts in SQLCMD mode. The Visual Studio Data Tools generate scripts in SQLCMD mode. It would be nice to add these SQLCMD mode scripts to the RoundHouse…
-2
votes
1 answer

Installing SQL Server Express 2008 using VB.NET

I'm trying to install SQL Server 2008 using vb.net, run SQL Script and backgroundworker Here is my code: Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click …
-2
votes
2 answers

Multiple queries on same connection using same T-SQL variables

I'm trying to create something similar to SQL Server Management Studio. I want the ability to run several queries on the same connection like one does in the same tab in SSMS, however from c# each SqlCommand is executed separately even with the same…
-2
votes
1 answer

Best way to execute sql command in c#

I need to do some sql query against sql-server 2008 R2. The command is: C:> sqlcmd –S .\APPSDB 1> use Example_database 2> go 1> Select SiteName, SiteID, Platform, Description, AdminUser from dbo.ExampleInfo 2> go I want to develop a console…
ericyoung
  • 621
  • 2
  • 15
  • 21
-3
votes
2 answers

Create a new database on SQL Server on Linux using sqlcmd

i'm new in SQL Server and i don't know what happened. i need to create a database,how i can do it? i have problems Why the > is show me?
sanlegas
  • 109
  • 1
  • 4
-3
votes
1 answer

Insert new line with text after n lines and 3 lines at beginning from other file - Windows

Could you please help find a Windows solution that can solve the below needs? Currently I do this manually in Notepad++ with regular expression, but this routine will be used by several persons and an automatic way will be better. I have a huge…
Cosmin
  • 15
  • 5
-3
votes
1 answer

Sql CMD Command with parameters

I got this code from Stackoverflow to insert data in table. But I wonder what it actually doing can someone please explain me this, What cmd.Parameters.add method does? 2: Why data conversion required? 3: What is @BSal here…
surya
  • 1
  • 1
  • 5
-4
votes
1 answer

SQLCMD fails on INSERT with "Syntax error at line xxxxx near command '&'"

I use SQLCMD to import DDL generated by mssql-scripter and i got this error: The offending INSERT is the following: INSERT [dbo].[Settings_ContentPartFieldDefinitionRecord] ([Id], [Name], [Settings], [ContentFieldDefinitionRecord_id],…
lfassio
  • 23
  • 4
1 2 3
77
78