You’ll install SQL Server Command Line tools to run queries, scripts, and administrative commands directly in the Windows command line or PowerShell. With just the SQL Server Management Studio (SSMS) Tools package, you gain access to T-SQL tools, query execution, and basic database automation—no heavy GUI needed. This guide walks you through the fastest way to get them up and running.
What You'll Need
- Windows 10/11 or Server 2019/2022 (SSMS Tools works only on these)
- An existing SQL Server instance (local or remote) configured for authentication
- Admin or database user permissions to connect and run scripts
- A 64-bit Windows build (32-bit won’t work with the latest tools)
Step-by-Step Installation
-
Download the SSMS Tools package.
- Go to the Microsoft SQL Server Management Studio (SSMS) Download Page.
- Under "Utilities," select the "SSMS Tools" (Command Line and Scripting Tools) option.
- Run the installer as Administrator—this is required for SQL Server integration.
cmd /k runas /user:Administrator "%~dp0ssms-tools.exe"(replace the installer path). -
Install the package.
- Click "Next" through the setup wizard until you reach the installation options.
- Choose "Install" under SSMS Tools and click "Next".
- Select "Install" under SQL Server Data Tools (SSDT) if prompted (this is optional but enables additional scripting tools).
- Wait for the installation to complete (~1-5 minutes).
Add-WindowsCapabilitymethod if the installer fails silently:powershell -Command "Add-WindowsCapability -Online -Name Microsoft.SqlServer.ManagementTools.CommandLine~~~~0.0.1.0" -
Verify SQL Server connection.
- Open a new PowerShell or Command Prompt window.
- Run (replace -U sa and password with your credentials).
- If successful, you’ll see a prompt for queries. If not, check your SQL Server services:
sc query msssqlserver(ensure it’s running).
-
Test the command-line tools.
- Use
sqlcmdfor direct queries:sqlcmd -d master -Q "SELECT @@version"(replace-d masterwith your database name). - Use
bcpfor bulk data transfer:bcp your_table.dbo.table out c:\temp\export.txt -c -T -S localhost -U sa -P [password]
sqlcmd -S .\SQLEXPRESS -U sa(local instance) first. - Use
Common Mistakes
-
Missing SQL Server services: The installer won’t work without SQL Server running. Check via
net start msssqlserver. If missing, install SQL Server Express (free) from Microsoft's site. -
Firewall blocking connections: If
sqlcmdfails with "Cannot connect to SQL Server," allow SQL Server ports (default 1433) in Windows Firewall or your router settings. - Admin rights required: The installer and command-line tools need elevated permissions. If prompted, always choose "Yes" or run as Administrator.
-
Outdated tools: If SSMS Tools fails to install, you’re likely on an older OS. Update to Windows 10/11 or Server 2019/2022 via
Settings > Windows Update.
Tips
-
Automate with aliases: Add this to your PowerShell profile to simplify commands:
Set-Alias sql "sqlcmd" -
Use PowerShell as a wrapper: Run scripts from PowerShell with
sqlcmd -i C:\path\to\script.sqland add error handling:try { sqlcmd -i script.sql } catch { Write-Host "Failed: $_" } -
Avoid typos: Common errors include misspelling
sqlcmdassqlCMDor using incorrect credentials. Check your SQL Server instance name (e.g.,.SQLEXPRESS). -
Enable logging: Use
sqlcmd -b -c -e -v -1 -w -1 -nto trace queries to debug performance issues.
Troubleshooting
-
Command-line tools not found: Ensure SSMS Tools is installed and added to PATH. Run this to verify:
where sqlcmd. If empty, reinstall SSMS Tools and check the installation directory (oftenC:\Program Files\Microsoft SQL Server\150\Tools\Shell). -
Login failed: Double-check your credentials. Try:
sqlcmd -S localhost -U sa -P "" -A(empty password) to test basic connection. If this works, your credentials are incorrect. -
Remote connections blocked: For remote servers, ensure:
- SQL Server Browser service is running (required for named instances).
- Firewall allows port 1433 and TCP port 1434 (for named instances).
- You’re using the correct instance name (e.g.,
.\SQLEXPRESS). -
Bcp fails with "Operation not permitted": Add
-yto bypass some checks:bcp table_name.dbo.schema out file.txt -y -c -T -S localhost -U sa -P pass -
SSMS Tools won’t open: Right-click the desktop shortcut or launch it via:
C:\Program Files\Microsoft SQL Server\150\Tools\Shell\sqlcmd.exe. If this fails, reinstall the tools and check for missing dependencies via:Get-WindowsCapability -Online | Where-Object Name -like "*sqlcmd*"
Frequently Asked Questions
1. Can I use these tools on a 32-bit Windows system?
No. The latest SSMS Tools (since SQL Server 2016) require a 64-bit Windows OS. If you’re stuck with 32-bit, you’ll need to use older command-line tools or upgrade your system.
2. What if I don’t have SQL Server installed yet?
Download SQL Server Express (free) from Microsoft’s site. Install it first, then install SSMS Tools. The tools will connect to your local or remote instance.
3. How do I run a script without a password?
Use -P "" (empty password) or store credentials securely in SQL Server authentication files (not recommended for production). For scripts, use environment variables or a connection string.
4. Can I use these tools on Linux/macOS?
No. This guide is for Windows only. For Linux, use tools like psql or mysql from the command line. macOS users can install Homebrew’s mssql-tools package.
5. What’s the difference between SQLcmd and bcp?
sqlcmd is for running queries interactively or with scripts. bcp is for bulk copy operations (import/export data). Use bcp for large datasets.
6. Why does my script fail with "Login failed for user"?
Most common causes: incorrect password, wrong username, or SQL Server not running. Verify:
- Your username is sa or a logged-in database user.
- SQL Server services are active via net start msssqlserver.
- You’re connecting to the correct instance (e.g., .SQLEXPRESS).