Create Go apps using SQL Server on Windows
In this section, you will get SQL Server 2017 on your Windows machine and then you will install the necessary dependencies to run GoLang.
Step 1.1 Install SQL Server
- If you don’t have SQL Server 2017 Developer (or above) installed, click here to download the SQL Server exe.
- Run it to start the SQL installer.
- Click Basic in Select an installation type.
- Click Accept after you have read the license terms.
- (Optional) if you need to, you can choose a custom installation location for SQL Server.
- Click Install to proceed with the installation.
You now have SQL Server installed and running locally on your Windows computer! Check out the next section to continue installing prerequisites.
Step 1.2 Install GoLang
If you already have Go installed on your machine, skip this step. To install GoLang, download the msi file for Windows at the Go Downloads page.
Step 1.3 Install the ODBC Driver and SQL Command Line Utility for SQL Server
SQLCMD is a command line tool that enables you to connect to SQL Server and run queries.
After installing SQLCMD, you can connect to SQL Server using the following command from a CMD session:
sqlcmd -S localhost -U sa -P your_password 1> # You're connected! Type your T-SQL statements here. Use the keyword 'GO' to execute each batch of statements.
This how to run a basic inline query. The results will be printed to STDOUT.
sqlcmd -S localhost -U sa -P yourpassword -Q "SELECT @@VERSION"
-------------------------------------------------------- Microsoft SQL Server 2016 (RTM) - 13.0.1601.5 (X64) Apr 29 2016 23:23:58 Copyright (c) Microsoft Corporation Developer Edition (64-bit) 1 rows(s) returned Executed in 1 ns.
You have successfully installed SQL Server Command Line Utilities on your Windows machine!
You have successfully installed and setup GoLang and mssql-tools on your Ubuntu computer. You now have everything you need to start writing your Go apps with SQL Server!