Home

How to Export SQL Server Tables to CSV Using PowerShell – The Easiest Way to Migrate Data to Supabase (2025 Guide)



Migrating from SQL Server to cloud databases like Supabase is becoming more common — but exporting your tables into the correct CSV format can be tricky if you’re doing it manually.

That’s why I’m sharing a simple PowerShell script that I personally use to export SQL Server tables into CSV files. It’s lightweight, beginner-friendly, and works perfectly with Supabase imports.

Why Use PowerShell to Export SQL Server Tables?

Most people use SQL Server Management Studio (SSMS) to export data, but PowerShell offers several advantages:

  • ⚡ Faster and scriptable — perfect for automation

  • 📁 Generates clean CSV files ready for Supabase

  • 🧩 No additional software needed — just PowerShell and SQL Server

  • 🔁 Ideal for repeated exports or scheduled migrations

Step-by-Step: Export SQL Server Tables to CSV Using PowerShell

Follow these simple steps to export your data in just a few minutes:

Step 1 – Open PowerShell

Run PowerShell as Administrator on your computer or server.

Step 2 – Copy and Paste the PowerShell Script

Here’s the full script I use 👇(AI Generated one but it's work and save your time i tested work for me)



Step 3 – Update Connection Details

Change these variables in the script:

  • $serverName → Your SQL Server instance name

  • $databaseName → Your database name

  • $outputFolder → Folder path to save CSV files


Step 4 – Run the Script

Once updated, execute the script.
You’ll get one CSV file per table — ready to upload to Supabase or any cloud platform.


Why This Script Is Perfect for Supabase Migration

Supabase can easily import CSV files through its dashboard or CLI. The exported CSVs from this PowerShell script:

  • Are UTF-8 encoded

  • Contain headers compatible with Supabase’s schema

  • Maintain the same column structure as SQL Server

So you can directly drag and drop them into Supabase’s import section.

Pro Tips (From My Experience)

  • Always check date/time formats before importing.

  • Use the same table names in Supabase to speed up schema matching.

  • For large databases, export only specific tables by modifying the $query.


Final Thoughts

This PowerShell method is the fastest and cleanest way to export SQL Server data into CSV format — especially when preparing for a migration to Supabase.

You can use it for one-time exports or even automate it with Task Scheduler for regular backups.

I’ve also shared a video tutorial on my YouTube channel showing this process step-by-step — watch it if you want to see it in action!


FAQs – Export SQL Server Tables to CSV for Supabase

Q: Can I export only one table using this script?
A: Yes, modify the $query line to select a single table name.

Q: Does this script work with SQL Server 2025?
A: Yes, it’s fully compatible with SQL Server 2025 and earlier versions.

Q: What format does Supabase require for CSV imports?
A: UTF-8 encoded CSVs with header rows, exactly what this script produces.