How to set up SQLServer on mac in PostgreSQL

Galaxy Glossary

How do I set up SQL Server on a Mac?

Install and configure Microsoft SQL Server on macOS using Docker, sqlcmd, and a sample ecommerce schema.

Sign up for the latest in SQL knowledge from the Galaxy Team!

Description

Why install SQL Server on Mac?

Many macOS developers need to prototype against Microsoft SQL Server without maintaining a Windows VM. Docker lets you spin up an isolated, disposable SQL Server instance that behaves identically to production, enabling local testing, migration development, and cross-database comparisons with PostgreSQL.

Which tools are required?

Install Docker Desktop for Mac (v4.0+), the Microsoft ODBC driver, and the cross-platform sqlcmd CLI. Homebrew installs these quickly: brew install --cask docker and brew install mssql-tools.

How do I pull and run the container?

Use the official image. The command sets the SA password, exposes port 1433, and names the container for easy reference:

docker run -e 'ACCEPT_EULA=Y' \
-e 'MSSQL_SA_PASSWORD=Str0ng_P@ss!' \
-p 1433:1433 --name sqlserver \
-d mcr.microsoft.com/mssql/server:2022-latest

How can I verify SQL Server is running?

Run docker ps to confirm the container’s status. Then connect with sqlcmd -S localhost -U sa -P 'Str0ng_P@ss!'. A 1> prompt indicates success.

How do I create an ecommerce database?

Inside sqlcmd, execute the batch below to mimic a production schema:

CREATE DATABASE Ecommerce;
GO
USE Ecommerce;
GO
CREATE TABLE Customers (
id INT IDENTITY(1,1) PRIMARY KEY,
name NVARCHAR(100),
email NVARCHAR(255),
created_at DATETIME DEFAULT GETDATE()
);
CREATE TABLE Products(
id INT IDENTITY(1,1) PRIMARY KEY,
name NVARCHAR(100),
price DECIMAL(10,2),
stock INT
);
CREATE TABLE Orders(
id INT IDENTITY(1,1) PRIMARY KEY,
customer_id INT REFERENCES Customers(id),
order_date DATETIME DEFAULT GETDATE(),
total_amount DECIMAL(10,2)
);
CREATE TABLE OrderItems(
id INT IDENTITY(1,1) PRIMARY KEY,
order_id INT REFERENCES Orders(id),
product_id INT REFERENCES Products(id),
quantity INT
);
.

How do I persist data across restarts?

Mount a local volume when starting the container to keep database files: -v ~/mssql/data:/var/opt/mssql. Restart with docker start sqlserver to reuse the same data directory.

How do I automate start/stop?

Add --restart unless-stopped to docker run so the service starts with Docker. Use docker stop sqlserver when resources are tight.

Best practices for macOS developers

Use strong SA passwords, restrict the exposed port to localhost, and reset containers before sharing screenshots or logs. Build schema migrations with tools like Flyway and check them against both SQL Server and PostgreSQL to catch dialect issues early.

Why How to set up SQLServer on mac in PostgreSQL is important

How to set up SQLServer on mac in PostgreSQL Example Usage


-- Top 5 customers by lifetime spend
SELECT c.id, c.name, SUM(o.total_amount) AS lifetime_spend
FROM Orders o
JOIN Customers c ON c.id = o.customer_id
GROUP BY c.id, c.name
ORDER BY lifetime_spend DESC
OFFSET 0 ROWS FETCH NEXT 5 ROWS ONLY;

How to set up SQLServer on mac in PostgreSQL Syntax


# Docker command to launch SQL Server 2022 on macOS
docker run -e 'ACCEPT_EULA=Y' \
-e 'MSSQL_SA_PASSWORD=<StrongPassword>' \
-p 1433:1433 \
-v ~/mssql/data:/var/opt/mssql \
--name sqlserver \
--restart unless-stopped \
-d mcr.microsoft.com/mssql/server:2022-latest

# sqlcmd connection
sqlcmd -S localhost -U sa -P <StrongPassword>

# Sample T-SQL to create ecommerce schema
CREATE DATABASE Ecommerce;
GO
USE Ecommerce;
GO
-- Customers table
CREATE TABLE Customers (
  id INT IDENTITY(1,1) PRIMARY KEY,
  name NVARCHAR(100),
  email NVARCHAR(255),
  created_at DATETIME DEFAULT GETDATE()
);
-- Products table
CREATE TABLE Products(
  id INT IDENTITY(1,1) PRIMARY KEY,
  name NVARCHAR(100),
  price DECIMAL(10,2),
  stock INT
);
-- Orders table
CREATE TABLE Orders(
  id INT IDENTITY(1,1) PRIMARY KEY,
  customer_id INT REFERENCES Customers(id),
  order_date DATETIME DEFAULT GETDATE(),
  total_amount DECIMAL(10,2)
);
-- OrderItems table
CREATE TABLE OrderItems(
  id INT IDENTITY(1,1) PRIMARY KEY,
  order_id INT REFERENCES Orders(id),
  product_id INT REFERENCES Products(id),
  quantity INT
);

Common Mistakes

Frequently Asked Questions (FAQs)

Can I run SQL Server 2022 on Apple Silicon?

Yes. The 2022 image ships with an ARM64 variant that Docker Desktop automatically downloads for M-series chips.

Which GUI clients work on macOS?

Aqua Data Studio, Azure Data Studio, DBeaver, and Galaxy all connect over port 1433 using the same credentials.

How do I change the SA password later?

Connect with sqlcmd and run ALTER LOGIN sa WITH PASSWORD = 'N3w_Str0ng_P@ss!';. Restart the container to apply.

Want to learn about other SQL terms?

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie
BauHealth Logo
Truvideo Logo