Microsoft SQL Server (Part 1)
Neil Haddley • March 14, 2021
Microsoft SQL Server 2019 Docker image.
Docker image
I downloaded and ran the amd64 Docker image from https://hub.docker.com/_/microsoft-mssql-server
$ docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=Passw0rd123" -p 1433:1433 --name sql -d mcr.microsoft.com/mssql/server:2019-latest

docker run

Azure Data Studio - New Connection

I connected to the database instance running on 192.168.68.109
RESTORE DATABASE
I opened a shell for the Docker image and downloaded the AdventureWorks2019.bak database backup.
$ cd /usr
$ wget https://github.com/Microsoft/sql-server-samples/releases/download/adventureworks/AdventureWorks2019.bak
I opened a database query window and ran this query.
SQL
1RESTORE DATABASE AdventureWorks2019 2FROM DISK = N'/usr/AdventureWorks2019.bak' 3WITH MOVE 'AdventureWorks2017' TO '/usr/AdventureWorks2019.mdf', 4MOVE 'AdventureWorks2017_Log' TO '/usr/AdventureWorks2019_Log.ldf'

RESTORE DATABASE

AdventureWorks Products
Product names in a .NET Core console app
BASH
1% dotnet new sln
BASH
1% dotnet new console -o dotnet-sql
BASH
1% dotnet sln add ./dotnet-sql/dotnet-sql.csproj
BASH
1% cd dotnet-sql 2% dotnet new gitignore
I added the NuGet package.
BASH
1% dotnet add package System.Data.SqlClient

dotnet add package System.Data.SqlClient
Program.cs
I wrote code to retrieve details from the Product table using C#.

dotnet run
Product names in a Node console app
$ node index.js
I wrote code to retrieve details from the Product table using JavaScript and the mssql node module.

node index.js
Product names in a Java console app
$ javac Program.java
then
$ java -cp ".:/Users/neilhaddley/sqljdbc_9.2/enu/mssql-jdbc-9.2.1.jre11.jar" Program
or
$ export CLASSPATH=.:/Users/neilhaddley/sqljdbc_9.2/enu/mssql-jdbc-9.2.1.jre11.jar
$ java Program
I wrote code to retrieve details from the Product table using Java.

java Program.java