How can we help you today?

SQLCMD - Running SQL Queries from a Command Prompt

Issue
Running SQL statements to query data.

Product Line
Microsoft SQL Server

Environment
Command Prompt (DOS Window)

Cause
In some cases there could be no access to SQL Server Management Studio.

Resolution
*Warning: Irreparable database damage can occur. This procedure should only be performed by users familiar with SQL Server and proficient in writing SQL queries . Databases should be backed up prior to running any SQL statements.*

The sqlcmd utility lets users enter Transact-SQL statements, system procedures, and script files at the command prompt.

SYNTAX
sqlcmd <command-line option>

Syntax and command line options can be found at sqlcmd utility website.

1.  An example of how to connect to a SQL Server instance and run a query against a database:

Authentication SQLCMD

-S parameter should be followed by the instance name
-E uses a trusted connection
GO signals the execution of the SQL statement.

2.  This example specifies the user and password when a trusted connection cannot be made:

User andP PAssword SQL CMD

-U is the user login
-P is the password


3.  The QUIT control command causes sqlcmd to exit:

Quit SQL CMD

For more information see: https://learn.microsoft.com/en-us/sql/tools/sqlcmd/sqlcmd-use-utility?view=sql-server-ver16

Schneider Electric Canada

Explore more
Range:
Users group

Discuss this topic with experts

Visit our community and get advice from experts and peers on this topic and more
Explore more
Range:

Need help?

Need help?

Product Selector

Product Selector

Quickly and easily find the right products and accessories for your applications.

Get a Quote

Get a Quote

Start your sales inquiry online and en expert will connect with you.

Where to buy?

Where to buy?

Easily find the nearest Schneider Electric distributor in your location.

Help Center

Help Center

Find support resources for all your needs, in one place.

  • Help and Contact Center
  • Contact Sales
  • Find our Offices
  • Where to Buy
  • Careers
  • Company Profile
  • Investors
  • Newsroom
  • Report a Misconduct
  • Product Documentation
  • Product Selectors
  • Software and Firmware
  • Product Substitution and Replacement
  • Blog
  • Events
  • Schneider Electric Community
  • Sustainability
  • Legal Information
  • Privacy Policy
  • Cookie Notice
  • Terms of use
  • Change your cookie settings