How to Import SQL File in Power BI
Trying to import a .sql file directly into Power BI can feel like putting a key in the wrong lock - it seems like it should work, but it doesn't. That's because a .sql file isn't actually a data file, it's a script full of instructions. This guide will walk you through the correct process: running your SQL script on a database and then easily connecting Power BI to that new data source so you can start visualizing.
First Things First: Why You Can’t Directly Import a .sql File
Before jumping into the steps, it’s important to understand what a .sql file really is. Unlike a CSV or Excel file that contains rows and columns of data, a .sql file is a plain text file that contains a script of SQL (Structured Query Language) commands.
These commands tell a database a story. They might say things like:
CREATE TABLE Users ...(Build a new table called "Users")INSERT INTO Users (ID, Name) VALUES (1, 'Alice'),(Add a new row of data for Alice)SELECT * FROM Products WHERE Category = 'Electronics',(Show me all the products in the Electronics category)
Power BI is a data visualization tool, not a database management system. It's built to connect to existing databases and data sources, read the data from them, and help you build reports. It doesn't have the built-in capability to execute SQL scripts that create tables and insert data from scratch. So, the goal isn't to "import the file" itself, but to get the data out of the file by running it in the right environment first.
Free PDF · the crash course
AI Agents for Marketing Crash Course
Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.
The Two-Step Game Plan: Execute, Then Connect
Our overall strategy is simple. We first need a database environment where we can run the instructions in our .sql file. Once the script has run, it will create tables and populate them with data. This newly populated database becomes the data source that Power BI can then connect to.
- Execute the .sql Script: We'll use a database management tool to run the .sql file against a database instance. This creates the tables and data.
- Connect Power BI: We'll point Power BI at the database where our new tables now live.
Let’s walk through how to do this in practice.
Step 1: Set Up an Environment and Execute Your .sql File
To run your script, you need a SQL database server. If your company already has a development server, awesome. If not, don't worry - you can easily set up a free one right on your own computer. For this guide, we'll use SQL Server Express, a free version from Microsoft that works perfectly with Power BI.
Install SQL Server Express and SSMS
You need two pieces of free software from Microsoft:
- SQL Server Express Edition: This is the actual database engine that will store your data. You can download it here. During installation, the 'Basic' option is usually fine.
- SQL Server Management Studio (SSMS): This is the user interface you'll use to connect to your database and run the .sql file. You can download it here.
Once both are installed, you're ready to run your script.
Run the .sql File in SSMS
- Open SSMS: Launch SQL Server Management Studio. A "Connect to Server" window will pop up. Your newly installed local server should be listed in the "Server name" dropdown (it might be something like
localhost\SQLEXPRESSor your computer's name). Click Connect. - Create a New Database: In the Object Explorer on the left, right-click on the Databases folder and select New Database. Give it a simple name, like
MyPowerBIData, and click OK. This creates an empty container for your data. - Open Your .sql File: Go to File > Open > File... and navigate to your .sql file. This will open the script's content in the main query window.
- Execute the Script: At the top of the query window, make sure the dropdown menu is set to the new database you just created (e.g.,
MyPowerBIData). Then, click the Execute button (or press F5). - Verify Your Tables: SSMS will report "Commands completed successfully" in the Messages pane below. You can verify the data was created by expanding Databases > MyPowerBIData > Tables in the Object Explorer. You should see the new tables created by your script. You can right-click a table and select "Select Top 1000 Rows" to see the data inside.
That's it for the database part! You've successfully turned your .sql script into a real, queryable database.
Step 2: Connect Power BI to Your Database
Now for the easy part. With your data living happily in your new local SQL Server database, connecting Power BI is a breeze.
- Get Data: Open a new Power BI Desktop file. On the Home tab, click Get Data and then select SQL Server.
- Enter Server and Database Details: A new window will appear.
- Credentials: Power BI may ask for credentials. Since you're connecting to a local server on your machine, click the Windows tab on the left and select Use my current credentials. Then click Connect.
- Select Your Tables: The Power BI Navigator window will appear. On the left side, you'll see a list of all the tables in your
MyPowerBIDatadatabase. These are the tables that were created by your .sql script! Check the boxes next to the tables you want to analyze. Power BI will show you a preview of the data on the right. - Load or Transform: You now have two options:
And you're done! Your data is now in Power BI, ready to be turned into interactive charts, reports, and dashboards.
What if Your .sql File Only Contains a SELECT Statement?
Sometimes, a .sql file doesn't contain CREATE TABLE or INSERT commands. Instead, it might just have a single, complex SELECT query designed to pull a specific cut of data from an already existing database.
In this scenario, the process is even simpler. You don't need to run a script first. You can paste the query directly into Power BI.
- In Power BI, click Get Data > SQL Server.
- Enter the Server and Database details for the database the query is meant for.
- Important: Click on Advanced options to expand the dialog.
- Copy the entire
SELECTstatement from your .sql file and paste it into the SQL statement box. - Click OK.
Power BI will now execute that specific query against the database and return only the results of that query, which you can then load.
Free PDF · the crash course
AI Agents for Marketing Crash Course
Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.
Final Thoughts
So, while you can't import a .sql file into Power BI in one click, the correct process is quite manageable. By using a free database tool like SSMS to first execute your script and create a real data source, you give Power BI a place to connect and pull in your newly structured data. It just requires separating the "data creation" step from the "data visualization" step.
While this method is perfect for custom SQL databases, the manual setup - installing server software, running scripts, and managing credentials - is exactly the kind of friction we wanted to eliminate for common marketing and sales data. For connecting to data sources like Google Analytics, Shopify, Salesforce, or Facebook Ads, we made Graphed. It replaces the entire database setup process with one-click integrations, allowing you to centralize your platforms and build real-time dashboards just by describing what you want in plain English, getting you from data to insight in seconds, not hours.
Related Articles
Facebook Ads for Tutors: The Complete 2026 Strategy Guide
Learn how to run effective Facebook ads for tutors in 2026. Complete guide covering targeting, ad formats, budgets, and proven strategies that convert.
Facebook Ads for Bail Bonds: The Complete 2026 Strategy Guide
Learn the proven strategies bail bond agencies use to generate leads in 2026 despite Facebook and Google ad bans. Includes local SEO, review strategy, and Bing Ads tactics.
Facebook Ads for Security Companies: The Complete 2026 Strategy Guide
Learn how to run effective Facebook ads for security companies in 2026. Discover proven targeting strategies, ad copy templates, and campaign optimization tips for security businesses.