how to execute SQL statements in command prompt (CMD)
You are looking for the sqlcmd
utility lets you enter Transact-SQL statements, system procedures, and script files at the command prompt
sqlcmd -U myLogin -P myPassword -S MyServerName -d MyDatabaseName
-Q "query"
Refer this
Edit: The OP said The sqlcmd.exe
file is available in the installation path C:\Program Files\Microsoft SQL Server\110\Tools\Binn
You are executing with C:\Users>
make the path to C:\Program Files\Microsoft SQL Server\110\Tools\Binn
and execute sqlcmd
or add the sqlcmd
path (C:\Program Files\Microsoft SQL Server\110\Tools\Binn)
to system PATH
Execute SQL script from command line
Take a look at the sqlcmd
utility. It allows you to execute SQL from the command line.
http://msdn.microsoft.com/en-us/library/ms162773.aspx
It's all in there in the documentation, but the syntax should look something like this:
sqlcmd -U myLogin -P myPassword -S MyServerName -d MyDatabaseName
-Q "DROP TABLE MyTable"
How to I run a single sql command from the sqlcmd prompt?
I think you want the -q
switch:
sqlcmd -S localhost -U MyUser -P MyPass -d MyDb -q "SELECT 1"
Documentation is here
Run SQL script via command line to remote server
-d - Specifies the database name - learn.microsoft.com/en-us/sql/tools/sqlcmd-utility – Ctznkane525
sqlcmd -S myServer\instanceName -i C:\myScript.sql -d DatabaseName
Related Topics
Order by a Field Being Equal to a Specific Value
Aggregation with Group by Date in Spark Sql
Refresh Materialized View Periodically Postgres
Drop Foreign Keys Generally in Postgres
Sql: Insert a Linebreak in Varchar String
What's The Default Window Frame for Window Functions
How to Override SQL Sanitization in Coldfusion
How to Delete Last Record(On Condition) from a Table in MySQL
Sql Server - Is Using @@Rowcount Safe in Multithreaded Applications
How to Control Nullability in Select into for Literal-Based Columns
Sql Server Creating a Temp Table for This Query
Get All The Rows Referencing (Via Foreign Keys) a Particular Row in a Table
How to Perform a Simple String Mapping as Part of a T-Sql Select
Select The Rows That Just Inserted
% in The Beginning of Like Clause