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

  1. Download the SSMS Tools package.
    1. Go to the Microsoft SQL Server Management Studio (SSMS) Download Page.
    2. Under "Utilities," select the "SSMS Tools" (Command Line and Scripting Tools) option.
    3. Run the installer as Administrator—this is required for SQL Server integration.
    If that did not work: Check your internet connection and try again. If you still get blocked, run the installer from an elevated command prompt: cmd /k runas /user:Administrator "%~dp0ssms-tools.exe" (replace the installer path).
  2. Install the package.
    1. Click "Next" through the setup wizard until you reach the installation options.
    2. Choose "Install" under SSMS Tools and click "Next".
    3. Select "Install" under SQL Server Data Tools (SSDT) if prompted (this is optional but enables additional scripting tools).
    4. Wait for the installation to complete (~1-5 minutes).
    If that did not work: Uninstall any previous SSMS Tools versions and reinstall cleanly. Use the Add-WindowsCapability method if the installer fails silently: powershell -Command "Add-WindowsCapability -Online -Name Microsoft.SqlServer.ManagementTools.CommandLine~~~~0.0.1.0"
  3. Verify SQL Server connection.
    1. Open a new PowerShell or Command Prompt window.
    2. Run (replace -U sa and password with your credentials).
    3. If successful, you’ll see a prompt for queries. If not, check your SQL Server services: sc query msssqlserver (ensure it’s running).
    If that did not work: Reboot your machine and confirm SQL Server services are active.
  4. Test the command-line tools.
    1. Use sqlcmd for direct queries: sqlcmd -d master -Q "SELECT @@version" (replace -d master with your database name).
    2. Use bcp for bulk data transfer: bcp your_table.dbo.table out c:\temp\export.txt -c -T -S localhost -U sa -P [password]
    If that did not work: Ensure your network allows SQL Server connections. Try sqlcmd -S .\SQLEXPRESS -U sa (local instance) first.

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 sqlcmd fails 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.sql and add error handling: try { sqlcmd -i script.sql } catch { Write-Host "Failed: $_" }
  • Avoid typos: Common errors include misspelling sqlcmd as sqlCMD or using incorrect credentials. Check your SQL Server instance name (e.g., .SQLEXPRESS).
  • Enable logging: Use sqlcmd -b -c -e -v -1 -w -1 -n to trace queries to debug performance issues.

Troubleshooting

  1. 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 (often C:\Program Files\Microsoft SQL Server\150\Tools\Shell).
  2. 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.
  3. 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).
  4. Bcp fails with "Operation not permitted": Add -y to bypass some checks: bcp table_name.dbo.schema out file.txt -y -c -T -S localhost -U sa -P pass
  5. 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).