Skip to content

Create a SQL Server database

Fill in the variables above and set the login’s password in the script:

sqlserver-init.sql
CREATE DATABASE ${{ DATABASE }};
GO
USE ${{ DATABASE }};
GO
CREATE LOGIN ${{ USERNAME }} WITH PASSWORD = 'put_your_password';
GO
CREATE USER ${{ USERNAME }} FOR LOGIN ${{ USERNAME }};
GO

Set the SA password in your shell, then run the script. SQL Server 2022 ships sqlcmd at /opt/mssql-tools18/bin/ and enforces TLS by default — -C trusts a self-signed server certificate (use -N to control encryption mode explicitly):

Terminal window
export SA_PASSWORD=put_your_sa_password
/opt/mssql-tools18/bin/sqlcmd -S "${{ HOSTNAME }},1433" -U SA -P "$SA_PASSWORD" -C -i /sqlserver-init.sql;

On older images the binary lives at /opt/mssql-tools/bin/sqlcmd (no TLS by default). Drop the -C flag and adjust the path:

Terminal window
/opt/mssql-tools/bin/sqlcmd -S "${{ HOSTNAME }},1433" -U SA -P "$SA_PASSWORD" -i /sqlserver-init.sql;