Your Microsoft Technology Development and Consulting Experts - Operating since 2000

Location
Australia WideSydney, NSWMelbourne, VicBrisbane, QldPerth, WAAdelaide, SACanberra, ACTNorthern Rivers, NSWWollongong, NSWRichmond, VicDarwin, NT
emailconsult@officeexperts.com.au
Phone1300 102 810
Office experts logo
Contact Us

Getting Started with Power Apps and Microsoft SQL Database

Moving beyond SharePoint lists is one of the biggest steps in a Power Apps developer’s journey. This guide shows you how to set up an Azure SQL database, link two tables together, and show the results in a Power App, using a small stock and orders system as the example.

By Marcello BrocchiUpdated · 13 min read

A Power App reading data from an Azure SQL databaseA canvas app showing a gallery of stock orders sends a request through a Power Automate flow to a stored procedure called GetOrders in an Azure SQL database. The database holds two linked tables, Stock and Orders, and sends the rows back to the app.OrdersRefreshResistor10K Ohmx20Capacitor10uF Electrolyticx15Diode1N4007x30ResistorEmergency orderx25Power AutomateRows come backGetOrdersAzure SQLStockIDNameStockLevelOrdersIDStockIDAmount

2linked tables

Stock and Orders, joined by a foreign key.

1stored procedure

Joins them into one tidy result for your app.

1flow

Power Automate carries the data between app and database.

Introduction

Just as our prehistoric ancestors evolved by adopting tools like fire and stone axes, your journey as a Power Apps developer must also evolve. As your experience grows, you’ll need to reach further and build more complex applications. One of the most significant milestones in this evolution is moving beyond SharePoint lists and connecting your apps to enterprise-level storage solutions like Microsoft SQL Server.

In this guide, I’ll walk you through the process of:

  • Setting up an Azure SQL database
  • Creating tables and relationships
  • Connecting Power Apps to SQL using stored procedures and Power Automate
  • Building a simple inventory and order management application

Let’s take our first steps into this bigger world of enterprise-level data management!

Prefer to Watch the Video?

Head over to my YouTube channel Chino Does Stuff to watch the video tutorial, there you will see a variety of videos with loads of tricks and tips on the entire Power Platform suite.

Why move beyond SharePoint lists?

SharePoint lists are a fantastic place to start, and for plenty of apps they’re all you’ll ever need. (If you’re curious how far they can stretch, see using SharePoint lists like a relational database.) But sooner or later an app outgrows them, and a proper database starts to earn its keep.

Real relationships

A foreign key makes the database check that every order belongs to a real stock item, instead of relying on lookup columns and good habits.

Room to grow

Databases are built for large, busy tables with indexes, so a list that keeps growing stops being a worry.

Rules in one place

Data types, constraints and procedures apply to every app and report that touches the data, not just the one you built first.

Finer security

Firewall rules, database users and permissions give you more precise control over who and what can reach the data.

How the pieces fit together

Three pieces do the work. The Power App is what people see. The Azure SQL database stores the data. Power Automate sits in the middle and carries requests and results between them. Power Apps can also talk to SQL directly, which we’ll cover below.

How data moves between Power Apps, Power Automate and Azure SQLThe Power App runs a Power Automate flow. The flow executes the GetOrders stored procedure in the Azure SQL database, parses the result and responds to the app. A dashed route underneath shows the alternative of connecting the app straight to the database for tables, views and stored procedures.Power AppCanvas appRefreshPower Automate flowInstant flowPower Apps triggerExecute stored procedureParse JSONRespond to Power AppsAzure SQL databaseTables and proceduresGetOrdersStockIDNameLevelOrdersIDStockIDAmountRun flowCallRowsJSON backOr connect directly: tables, views, stored procedures
Two routes from the app to the data: through a flow, or directly.

Microsoft’s documentation describes calling SQL Server stored procedures straight from Power Fx, so a flow is no longer the only way in. We’ll still use one here, because a flow is the natural home for multi-step processes and it’s the approach shown in the video. Later on you’ll see the direct version too.

Works well

  • Reading tables and views straight into galleries and forms
  • Calling stored procedures for joins and business rules
  • Using a flow when a process has several steps
  • Keeping the rules in SQL, where every app can reuse them

Needs care

  • Complex joins written in Power Fx. SQL is better at them
  • Pulling very large tables whole into the app
  • Shared connections, because users typically share one set of credentials
  • Premium licensing, so confirm before you build

Which data source fits your app?

SQL isn’t always the right answer. Work through the two questions below, then check the comparison table for the detail.

Which data source should your Power App use?A two-question decision flow. If you do not need enforced relationships, larger tables or data shared with other systems, a SharePoint list is enough. If you do, and the app stays inside the Power Platform with built-in security roles, consider Dataverse. Otherwise an Azure SQL database is the recommended choice.Choosing adata sourceDo you need enforcedrelationships, biggertables, or data sharedwith other systems?SharePoint listSimple data, small teamsNoYesWill the app stay insidePower Platform, using itsbuilt-in security roles?DataverseBuilt-in roles and tablesYesNoAzure SQLdatabaseRecommended hereStart with the simplest option that meets the need. Licensing differs for each, so check before you build.
A quick way to choose between SharePoint, Dataverse and Azure SQL.
Comparing SharePoint lists, Dataverse and Azure SQL
FeatureSharePoint listDataverseAzure SQL database
Best forSimple data and small teams already in Microsoft 365Apps that live entirely inside the Power PlatformData shared with other systems, larger tables, or existing SQL skills
RelationshipsLookup columns, with limited enforcementBuilt-in tables and relationshipsForeign keys, constraints and joins in SQL
Security modelSharePoint permissionsDataverse security rolesFirewall rules, database users and permissions
Skills neededLowMediumSQL knowledge helps a lot
LicensingOften covered by Microsoft 365 for standard useUsually needs premium Power Apps licensingSQL Server connector is generally premium, plus Azure costs

Licensing and limits change, so treat this table as a starting point and confirm the current details with Microsoft.

Setting Up Your Azure SQL Database

The first step is to set up an Azure SQL database. If you’re new to Azure, you can sign up for a free trial which gives you plenty of credits to explore the platform.

Creating a SQL Server and Database

In the Azure Portal:

  1. Find SQL databases

    In the Azure Portal, search for “SQL databases” and select Create (older versions of the portal say Add).

  2. Choose a resource group

    Select an existing resource group or create a new one.

    Pro tipA dedicated resource group keeps everything for this project together and makes clean-up easy.

  3. Name your database

    Give your database a name (for example, “ChinoDB”).

  4. Create a SQL server

    Create a new SQL server (for example, “ChinoDBSRV”). The server name becomes part of the address you connect to.

    Pro tipServer names have to be unique across Azure, so pick something distinctive.

  5. Set the admin credentials

    Set up the server admin login and password.

    Pro tipTreat this login as a setup tool. Your app gets its own limited user later in this guide.

  6. Create it

    Take the default options for the other settings and click Create.

    Pro tipWhile you’re learning, choose a low-cost compute tier. You can scale up later.

Configuring Server Firewall Rules

Once your server and database are created, you need to configure the firewall:

  1. Open your SQL server

    Navigate to your SQL server in the Azure Portal.

  2. Open Networking

    Click on “Networking” under “Security”.

  3. Allow Azure services

    Set “Allow Azure services and resources to access this server” to “Yes”.

    Pro tipThis setting admits connections from Azure services generally, not only yours. It suits learning, and it’s worth reviewing before production.

  4. Add your client IP

    Add your client IP address so you can connect from your desktop.

    Pro tipRemove your IP again when you no longer need it.

Azure Portal
// Azure SQL Server Configuration
// 1. Create SQL Server
Server name: your-server-name.database.windows.net
Server admin login: YourAdminUsername
Password: YourSecurePassword

// 2. Configure Firewall
- Set "Allow Azure services and resources to access this server" to YES
- Add your client IP address for local development

This firewall configuration is crucial as it allows Power Apps and Power Automate to connect to your database, while also letting you manage the database from your local computer.

Creating Your Database Structure

For this tutorial, we’ll create a simple inventory management system with two tables: a Stock table for inventory items and an Orders table for tracking restock orders.

Connecting to Your Database

To manage your database, you’ll need SQL Server Management Studio (SSMS):

  1. Download and install SQL Server Management Studio
  2. Connect to your database using the server name, admin username, and password

Creating Tables

We’ll create two tables with a simple relationship:

sql
-- Create Stock Table
CREATE TABLE Stock (
    ID int IDENTITY(1,1) PRIMARY KEY,
    Name varchar(100) NOT NULL,
    Description varchar(255),
    StockLevel int
);

-- Create Orders Table
CREATE TABLE Orders (
    ID int IDENTITY(1,1) PRIMARY KEY,
    StockID int NOT NULL,
    OrderDate datetime,
    Amount int,
    Description varchar(255),
    CONSTRAINT FK_Orders_Stock FOREIGN KEY (StockID) REFERENCES Stock (ID)
);

Let’s break down what we’ve done:

  • Stock Table: Stores inventory items with a name, description, and current stock level
  • Orders Table: Tracks order history with references to stock items
  • Relationships: The StockID in Orders refers to the ID in Stock, creating a one-to-many relationship. The FOREIGN KEY line is what makes the database enforce it
The Stock and Orders tables and how they are linkedThe Stock table has an ID primary key, a Name, a Description and a StockLevel. The Orders table has its own ID, a StockID foreign key that must match a Stock ID, an OrderDate, an Amount and a Description. One stock item can have many orders. Four numbered pins explain the primary key, data types, the foreign key and dates stored as dates.StockIDintNamevarchar(100)Descriptionvarchar(255)StockLevelintOrdersIDintStockIDintOrderDatedatetimeAmountintDescriptionvarchar(255)onetomany1Primary keyIDENTITY numberseach row for you.2Real data typesint keeps numbersas numbers.3Foreign keyMust match a StockID, or SQL rejects it.4Dates as datesdatetime sorts andfilters correctly.
The two tables, annotated. One stock item can have many orders.

Populating Sample Data

To make testing easier, let’s add some sample data to our tables:

sql
-- Insert sample stock items
INSERT INTO Stock (Name, Description, StockLevel)
VALUES
    ('Resistor', '10K Ohm Resistor', 50),
    ('Capacitor', '10uF Electrolytic Capacitor', 30),
    ('Diode', '1N4007 Diode', 25);

-- Insert sample orders
INSERT INTO Orders (StockID, OrderDate, Amount, Description)
VALUES
    (1, GETDATE(), 20, 'Monthly resistor order'),
    (2, GETDATE(), 15, 'Low stock capacitor order'),
    (3, GETDATE(), 30, 'Diode replacement order'),
    (1, DATEADD(day, -7, GETDATE()), 25, 'Emergency resistor order');

Creating a Stored Procedure

Here’s where things get interesting. Power Fx can’t express everything SQL can, so rather than asking the app to stitch two related tables together, we’ll create a stored procedure that joins the data for us:

sql
CREATE PROCEDURE GetOrders
AS
BEGIN
    SET NOCOUNT ON;

    SELECT
        t2.Name AS StockName,
        t2.Description AS StockDescription,
        t1.Amount AS OrderedAmount,
        t1.Description AS OrderDescription,
        t1.OrderDate AS OrderDate
    FROM Orders t1
    JOIN Stock t2 ON t1.StockID = t2.ID
    ORDER BY t1.OrderDate DESC;
END

This stored procedure joins the Orders and Stock tables, giving us a flattened view that’s perfect for displaying in Power Apps. Two small additions to the version in the video: SET NOCOUNT ON stops SQL sending row-count messages the app doesn’t need, and ORDER BY puts the newest orders first. Because every order must have a stock item, a plain JOIN is right. Use LEFT JOIN if orders could exist without one.

Giving the app its own database user

Before the flow connects, create a limited user so the app never needs the admin login:

sql
-- Run in your database (not master). Adjust to your security policy.
CREATE USER PowerAppsUser WITH PASSWORD = 'Use-a-long-random-password-here';

-- Give the app user only what it needs
GRANT EXECUTE ON OBJECT::dbo.GetOrders TO PowerAppsUser;

Connecting Power Apps to SQL Using Power Automate

Power Apps can now call SQL stored procedures directly, but Power Automate is still a reliable bridge between an app and a database, especially when a process has more than one step. Here we’ll use it as that bridge.

Creating a Power Automate Flow

Here’s how to set up the flow:

  1. Create an instant flow

    Create a new instant flow with the Power Apps trigger.

  2. Add Execute stored procedure

    Add an “Execute stored procedure” action from the SQL Server connector.

    Pro tipIf you see more than one version of the action, choose the newest (V2).

  3. Point it at GetOrders

    Configure it to connect to your database and call the “GetOrders” procedure.

    Pro tipCreate the connection with the limited app user from the previous section, not the admin login.

  4. Parse the response

    Add a “Parse JSON” action to format the response.

    Pro tipRun the flow once, copy the JSON output, and use Generate from sample to build the schema for you.

  5. Respond to Power Apps

    Add a “Respond to PowerApps” action to return the data.

    Pro tipIf the action only offers simple outputs, return the rows as text with string() and convert them in the app with ParseJSON.

portal
// Power Automate Flow Steps:

1. Trigger: PowerApps
   - Initialize flow from Power Apps

2. Execute Stored Procedure
   - Server name: your-server-name.database.windows.net
   - Database name: YourDatabaseName
   - Procedure name: GetOrders

3. Parse JSON
   - Content: Body from Execute Stored Procedure step
   - Schema: (Use the output schema from a test run)

4. Respond to PowerApps
   - Return the parsed JSON result to Power Apps

The key here is the “Parse JSON” step. When you execute the flow for the first time, you can copy the JSON output from the stored procedure execution and use it to generate the schema automatically.

Building Your Power App

With the database and flow set up, we can now build our Power App:

Create a New Canvas App

  1. Create a blank canvas app

    Start from a blank canvas app.

  2. Add a gallery control

    The gallery will list your orders.

  3. Add a button to refresh data from SQL

    The button runs the flow and loads the results.

Setting Up Data Retrieval

Configure the button to call your flow and store the results:

portal
// Power Apps Gallery Setup

// 1. Create a variable to store SQL data
Set(
    SQLOrderData,
    PowerAutomateFlow.Run('GetOrders').ResultSet.Table1
);

// 2. Set Gallery.Items property
Gallery1.Items = SQLOrderData;

// 3. In gallery controls, use ThisItem properties:
// - ThisItem.StockName
// - ThisItem.StockDescription
// - ThisItem.OrderedAmount
// - ThisItem.OrderDescription
// - ThisItem.OrderDate

The names after .Run() depend on how your flow responds, so use the suggestions in the formula bar to match your own flow. If you’d rather skip the flow, add the SQL Server connection to your app and call the procedure directly:

portal
// Option B: call the stored procedure directly
// (add the SQL Server connection to the app first)
Set(
    SQLOrderData,
    ChinoDB.dboGetOrders().ResultSets.Table1
);

The connection name and procedure name will appear in the formula bar suggestions, so you don’t need to guess them.

Displaying the Data

In your gallery, add labels to display the data:

  1. Add a label for the stock name
  2. Add a label for the order description
  3. Add a label for the order amount
  4. Add a date picker (in view mode) for the order date

Common mistakes to avoid

Most problems with a first SQL-backed app come from the same handful of habits. Here’s what to avoid, and what to do instead.

Connecting with the admin login

One leaked or over-trusted login then opens the whole server.

InsteadCreate a dedicated database user for the app and grant only what it needs, such as EXECUTE on GetOrders.

Skipping the foreign key

Without it, nothing stops an order pointing at a stock item that doesn’t exist.

InsteadDeclare the FOREIGN KEY so the database refuses orphan rows for every app and report.

Opening the firewall to everyone

A wide-open rule is convenient while testing and easy to forget.

InsteadAllow only the Azure services you need and your own IP address, and remove old test IPs.

Pulling the whole table into the app

Every extra row makes the app slower and the screen harder to use.

InsteadJoin, filter and sort in the stored procedure, and return only what the screen shows.

Storing dates and numbers as text

Text sorts alphabetically, so “10” lands before “9” and dates drift out of order.

InsteadUse real data types such as datetime and int so sorting, filtering and maths behave.

Before you go live

  • The app connects with a limited database user, not the admin login
  • Firewall rules allow only what you need, and old test IPs are gone
  • Every relationship has a FOREIGN KEY constraint
  • Columns use proper data types
  • Stored procedures return only the rows and columns the app needs
  • You’ve tested empty results and a large number of rows
  • Passwords live in a password manager, not in screenshots or flow notes
  • You’ve confirmed licensing for everyone who will use the app

Beyond the Basics: Creating a Complete Application

While we’ve covered the fundamentals of connecting Power Apps to SQL, a complete application would include:

  • Create/Edit Forms

    Screens to add and update stock items and orders. Call a stored procedure or flow for each save, so the rules stay in SQL.

  • Data Validation

    Ensuring data integrity before saving to SQL. Check in the app for fast feedback, and again in the database as the safety net.

  • Automatic Reordering

    Triggering orders when stock levels fall below thresholds. A scheduled flow can compare StockLevel with a minimum and raise the order.

  • User Authentication

    Ensuring only authorised users can access certain functions. Control who can open the app, and keep the database user’s permissions tight.

Key Takeaways for Working with SQL in Power Apps

As you continue to develop with SQL and Power Apps, remember these important points:

  • Use Stored Procedures

    They’re the key to working effectively with SQL, especially with related tables.

  • Power Automate is Your Bridge

    Use it to connect Power Apps with SQL stored procedures, especially when a process has several steps.

  • Secure Your Database

    Create specific database users for your apps rather than using admin credentials.

  • Plan Your Data Model

    A well-designed database schema makes app development much easier.

  • Learn SQL Basics

    Understanding SQL queries and joins will dramatically expand what you can do with Power Apps.

Want a hand with Power Apps and SQL?

Office Experts Group is an Australian Microsoft consultancy, established in 2000. If you’d like help designing the database, building the app or tidying up an existing one, tell us about your project.

Talk to our team

Frequently asked questions

Do I need a premium licence to use SQL with Power Apps?

The SQL Server connector is generally classed as a premium connector, which usually means the people using the app need a Power Apps or Power Automate plan that includes premium connectors. Licensing changes over time, so confirm with Microsoft or your licensing partner before you build.

Can Power Apps call a SQL stored procedure without Power Automate?

Yes. Microsoft documents calling SQL Server stored procedures directly from Power Fx through the SQL Server connector. A flow is still a good bridge when a process has several steps, such as saving a record, emailing someone and updating a second system.

Why use a stored procedure instead of connecting to the tables?

Power Fx is great for simple queries but it can’t express everything SQL can. A stored procedure (or a view) lets the database do the joins, filtering and sorting, so the app receives one tidy result. Procedures are also the usual place for create, update and delete logic.

Can I use an on-premises SQL Server instead of Azure SQL?

Yes, but the connection is different. An on-premises SQL Server is normally reached through an on-premises data gateway, and the firewall steps in this guide won’t apply. Your IT team will need to set up and maintain the gateway.

Is it safe to use the admin login in my app?

No. Create a dedicated database user with the minimum permissions the app needs. As a rule, the connection’s credentials are shared by everyone who uses the app, so control who can open the app and what that database user is allowed to do.

Conclusion

Moving from SharePoint lists to SQL databases is a significant evolution in your Power Apps journey. While there’s certainly a learning curve, the benefits are substantial:

  • More sophisticated data relationships
  • Better performance with large datasets
  • Advanced data validation and business logic at the database level
  • Enterprise-grade security and scalability

This tutorial covered the core functionality of using SQL with Power Apps, but there’s much more to explore. In future tutorials, we’ll build on this foundation to create more complete applications with full CRUD (Create, Read, Update, Delete) capabilities.

If you’d like to see more Power Apps development tutorials using SQL, please head over to the YouTube channel and leave a comment there. I actively monitor and respond to all YouTube comments!

About the author

Marcello Brocchi is a lead developer at Office Experts Group, an expert in computer science and Power Platform integration, and the founder of the YouTube channel ChinoDoesStuff. If you have any questions, please get in touch using the form below.

Case Studies

Business app and database projects from Office Experts

2500+ Happy Clients

Read all case studies

Contact Us

Get in touch with our team for general enquiries and support. We're here to help with any questions you might have about our services.

Need to attach a file?

Need pricing for a specific project? Fill out our quote form and we'll provide you with a detailed estimate tailored to your needs.