Internet, Networking, & Security Web Development SQLCMD Step-by-Step Tutorial Use the Command Prompt to interact with SQL Server in a text environment by Mike Chapple Writer Former Lifewire writer Mike Chapple is an IT professional with more than 10 years' experience cybersecurity and extensive knowledge of SQL and database management. our editorial process Twitter Mike Chapple Updated on April 10, 2020 lechatnoir / Getty Images Web Development SQL CSS & HTML Web Design Tweet Share Email Microsoft SQL Server offers rich graphical user interfaces for retrieving and manipulating data and configuring SQL Server databases. However, sometimes it’s just easier to work from a text-based command interpreter. Whether you’re looking for a quick-and-dirty way to execute a SQL query or wish to include SQL statements in a Windows script file, SQLCMD supports this type of interaction. This procedure works for all versions of Windows and SQL Server. However, SQL Server runtimes must be installed on the Windows computer. On a server, this process is usually automatic. To connect to a remote SQL Server with a local Windows machine, use different connection procedures. 01 of 05 Open the Command Prompt SQLCMD—a text interface into SQL Server—requires a shell session. Run Command Prompt by pressing Win+R and typing CMD or launching it through the Start menu. SQL Server does not offer its own shell environment. Also, use Command Prompt rather than the newer PowerShell. 02 of 05 Connect to the Database Use the SQLCMD utility to connect to the database: sqlcm This command uses the default Windows credentials to connect to the database specified by databasename. You may also specify a username using the -U flag and a password using the -P flag. For example, connect to the HumanResources database using the username mike and password goirish with the following command: sqlcmd -U mike -P goirish 03 of 05 Enter a Query Begin typing a SQL statement at the 1> prompt. Use as many lines as you want for your query, pressing the Enter key after each line. SQL Server does not execute your query until explicitly instructed to do so.In this example, we enter this query: SELECT * FROM Hum 04 of 05 Execute the Query When you are ready to execute your query, type the command GO on a new command line within SQLCMD and press Enter. SQLCMD executes your query and displays the results on the screen. 05 of 05 Exit SQLCMD When you are ready to exit SQLCMD, type the command EXIT on a blank command line to return to the Windows command prompt.