How to Generate an ER Diagram from a Microsoft SQL Server Schema File with Dbeaver| Sabbirz | Blog

How to Generate an ER Diagram from a Microsoft SQL Server Schema File with Dbeaver

MSSQL to DBeaver Diagram

Visualise Your Database: Turn Microsoft SQL Scripts into Clear ER Diagrams

So, youโ€™ve just received a .sql file. ๐Ÿ“‚

Maybe itโ€™s from a legacy project, a colleague who left the company, or an open-source repo. You open it up, and itโ€™s thousands of lines of CREATE TABLE, ALTER TABLE, and CONSTRAINT statements. Itโ€™s a wall of text.

You need to understand how this system works. You need to see the relationships, the foreign keys, the data flow. You need a map. ๐Ÿ—บ๏ธ

In this guide, Iโ€™m going to act as your senior lead and walk you through exactly how to turn that raw code into a beautiful, functional Entity Relationship Diagram (ERD). Weโ€™ll use the industry-standard Microsoft SQL Server and compare two powerful tools for visualization: the native SSMS and the versatile DBeaver.

Letโ€™s dive in! ๐Ÿš€


๐Ÿ› ๏ธ What Youโ€™ll Need (Your Toolkit)

Before we start hacking away, ensure you have the following:

  • The Payload: Your schema.sql file (exported from MSSQL).
  • The OS: A Windows machine (standard for MSSQL).
  • Admin Rights: Youโ€™ll need to tweak some network settings later.
  • Coffee: Optional, but recommended. โ˜•

Step 1: Install the Engine (SQL Server Developer Edition)

First, we need the engine to run the code. Microsoft SQL Server Developer Edition is full-featured and completely free for development purposes.

SQL Server Downloads

๐Ÿ‘‰ Download here: SQL Server Downloads

When you run the installer, youโ€™ll face a choice:

  • Basic
  • Custom
  • Download Media

๐Ÿ’ก Pro Tip: Choose Basic. It installs the Database Engine with sensible defaults, which is exactly what we need to just load a schema and inspect it.

Once it finishes, it might ask for a restart. Do it. Don't fight the Windows Update gods. ๐Ÿง˜โ€โ™‚๏ธ


Step 2: Install the Control Center (SSMS)

The engine is the muscle; now you need the brain. SQL Server Management Studio (SSMS) is the primary interface for managing your SQL infrastructure.

Download SSMS

๐Ÿ‘‰ Download here: Download SSMS

Install it. Itโ€™s a hefty install, so maybe grab that coffee now. โ˜•


Step 3: Connect and Configure ๐Ÿ”Œ

Open SSMS. Youโ€™ll be greeted by the "Connect to Server" dialog.

Create new connection

  • Server name: localhost (or . represents local)
  • Authentication: Windows Authentication

โš ๏ธ The "Certificate Chain" Gothca

If you see an error screaming about Encryption or Certificate Chain Not Trusted, take a breath. This is a common security feature in newer SQL Server versions.

The Fix:

  1. On the connection popup, click Options >>
  2. Check the box: โœ… Trust Server Certificate
  3. Hit Connect.

Step 4: Create a Clean Sandbox Database

We don't want to mess with system tables. Let's make a fresh home for your schema.

  1. In the Object Explorer (left sidebar), right-click Databases.
  2. Select New Database... Create a new database
  3. Name it AnalysisDB (or whatever project name suits you). Create a new database and set the name
  4. Click OK.

Step 5: The Import (Running the Script)

This is the moment of truth. Weโ€™re going to hydrate our empty database with the schema.

  1. File โ†’ Open โ†’ File... (Ctrl+O) Open File
  2. Select your schema.sql.. SQL file opened in SSMS

๐Ÿ›‘ STOP! Check the USE Statement

Most exported scripts are hardcoded. Look at the very top of the file. Do you see this?

USE [SomeOldProductionDB]
GO

If you run this, SSMS will yell at you: "Database 'SomeOldProductionDB' does not exist."

The Fix: Change it to your new DB name:

USE [AnalysisDB]
GO

...or simply delete those lines and ensure the dropdown menu in the SSMS toolbar says AnalysisDB.

Action: Press F5 (or click Execute).

If you see Commands completed successfully, youโ€™re in. ๐ŸŽ‰ Refresh the Tables folder in Object Explorer to confirm they are there.

Execute the script

SQL File Generated all tables


Step 6: Visualization Method A - SSMS Native Diagrams ๐ŸŽจ

SSMS has a built-in diagram tool. Itโ€™s old-school, but it works natively.

  1. Expand AnalysisDB.
  2. Right-click Database Diagrams โ†’ New Database Diagram.
    • Note: If it asks to install diagram support objects, click Yes. Create a new Database Diagram in SSMS
  3. Select the tables you want and click Add. Select Tables to generate an ER Diagram in SSMS
  4. The generated ER Diagram will look like this: ER Diagram in SSMS

๐Ÿข Performance Warning

If you have 100+ tables, do NOT add them all at once. SSMS will hang, and you will be sad.

The Expert Strategy:

  • Create small, focused diagrams (e.g., Auth_Module, Inventory_Module).
  • Add just one key table (e.g., Orders).
  • Right-click the table โ†’ Add Related Tables.
  • Let SSMS organically build the web for you. Itโ€™s cleaner and faster.

Step 7: Visualization Method B - DBeaver (The Modern Powerhouse) ๐Ÿฆซ

I personally prefer DBeaver. Itโ€™s cross-platform, looks better, and handles large schemas like a champ. Plus, the auto-layout is superior.

๐Ÿ‘‰ Download here: DBeaver Community

Connecting DBeaver to Local SQL Server

Select the Database and start the connection configuration s

  1. New Connection โ†’ SQL Server.
  2. Host: localhost
  3. Port: 1433
  4. Try fetching data: If it works, great! If not... read on.

๐Ÿ’€ The Dreaded "Connection Refused" Error

By default, SQL Server Developer Edition often has TCP/IP disabled. SSMS connects via "Shared Memory" (because it's Microsoft), but DBeaver uses JDBC (Java), which needs TCP.

The Fix (Enable TCP/IP):

  1. Press Win + R, type SQLServerManager15.msc (or 16.msc/17.msc depending on version) to open SQL Server Configuration Manager. Open SQL Server Configuration Manager
  2. Expand SQL Server Network Configuration.
  3. Select Protocols for MSSQLSERVER.
  4. Right-click TCP/IP โ†’ Enable. ๐ŸŸข Enable TCP IP
  5. Crucial Step: Double-click TCP/IP, go to the IP Addresses tab.
    • Scroll to the bottom IPAll.
    • Ensure TCP Port is set to 1433.
    • Delete anything in TCP Dynamic Ports. TCP IP Configuration
  6. Restart the SQL Server Service (Tables need to be re-served!). Restart MSSQL Server

Now, DBeaver connects. Boom. ๐Ÿ’ฅ

Generating the ERD in DBeaver

  1. Navigate to AnalysisDB โ†’ Schemas โ†’ dbo โ†’ Tables.
  2. Select your desired tables (Ctrl+Click).
  3. Right-click โ†’ View Diagram (or Create ER Diagram). DBeaver View Table & Diagram

This gives you a crisp, zoomable vector diagram that you can export as SVG or PNG for your documentation.

DBeaver Database Diagram


Reverse engineering a database is a superpower. Whether you stick with the native SSMS diagrams or upgrade to DBeaver, you now have the skills to turn raw SQL code into actionable intelligence.

Got questions? You can contact me and share your queries! Happy diagramming! ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป