Imagine you’re building an app that needs to store and manage loads of user data securely and efficiently. With Azure SQL Database, you can set up your database in minutes, scale it as you grow, and access powerful tools to run your first SQL queries with ease. Dive into our step-by-step guide and get started on transforming your app’s data handling today!
Getting Started with Azure SQL Database: A Step-by-Step Guide
Imagine you’re building an app that needs to store and manage loads of user data securely and efficiently. With Azure SQL Database, you can set up your database in minutes, scale it as you grow, and access powerful tools to run your first SQL queries with ease. Dive into our step-by-step guide and get started on transforming your app’s data handling today!
In this blog, we’re unlocking the potential of Azure SQL Database, guiding you through setup, configuration, and your first SQL commands. Whether you’re developing or deploying, this guide has you covered for a smooth start in Azure
What's covered in this blog
- Setting up azure SQL database on Azure
- Running Your First SQL Commands i.e. performing CRUD functionalities (Create, Read, Update, Delete)
When Do You Need Azure SQL Database?
Azure SQL Database is ideal when you need a managed, scalable, and secure database solution that minimizes administrative tasks. It’s a great choice for applications requiring high availability, disaster recovery, and automatic scaling. Azure SQL Database simplifies data management for businesses with unpredictable workloads or those that benefit from on-demand resources, offering cost-effective storage, advanced security features, and integration with Azure services. Use it for web applications, enterprise solutions, or analytics when you need flexible, cloud-based SQL capabilities that support dynamic business needs.
Introduction:
In today’s data-driven world, managing, securing, and scaling data are essential for any organization. Microsoft Azure SQL Database, a fully managed database service, offers these capabilities and more, freeing users from hardware management while providing built-in scalability, high availability, and security.
Creating Azure SQL Database in Azure portal
Prerequisites
- Azure account – Click to create an account: Create Azure Account
- Azure subscription – More about subscriptions: more on subscriptions
Let’s Create an Account
- On your azure portal, search for SQL databases
Create Azure SQL Database
This is the repository that holds all your tables, records, indexes, and queries.
Under create Azure SQL Database page
- Choose your subscription.
- Choose or create a resource group.
- Create the database name (make it unique).
- Choose the Server. (choose a server near to your users)
- Choose development (optional) Choose Production for if you are not testing or on development.
Create a new SQL database server
SQL Server helps you to manage resources (CPU, Memory and storage), security for authentication, connectivity to your database, performance and maintenance.
Follow the steps to create SQL server:
- Choose your server name. (make it unique)
- Choose location of your server according to the available data centers.
- Choose use both SQL and Microsoft Entra for Authentication method (you can choose SQL authentication option if you want)
Set up Microsoft Entra Admin
Microsoft Entra Admin is a web-based portal for overseeing identity. It helps admins control user identities, access policies, and security settings in a centralized, efficient way.
To set up your Microsoft Entra Admin, follow these steps:
- Click on "Set Admin": Begin by clicking on the "Set Admin" option in your Azure portal.
- Enter Your Microsoft Entra ID: A page will appear on your right with the heading "Enter your Microsoft Entra ID." Here, you'll find a search bar to help locate your Azure account.
- Search and Select Your Account: In the search bar, type your account username. This will bring up relevant accounts. Select your Azure account from the search results to designate it as the Microsoft Entra Admin.
- After setting up Microsoft Entra Admin, go to the Server Admin Login section. Set your Admin Login Username and create a strong, unique password. Confirm the password—be sure to remember these credentials, as you'll need them to access and manage your Azure SQL Database later.
Compute and storage
- Choose either Production or Development based on your specific needs and demand.
Backup storage redundancy
- Ensures that your data is protected against accidental loss or corruption by creating multiple copies of your backups across different geographic regions. This feature provides high availability and durability, allowing for quick recovery in the event of a failure.
- By leveraging geo-redundant or locally redundant storage, you can choose the appropriate level of redundancy based on your business needs, ensuring that your critical data remains safe and accessible even during unexpected outages.
Configure database (as shown in the image above)
- To configure your Azure SQL Database, click on Configure Database to select your Service Tier and Compute Tier based on your project needs. Choose the Basic tier for a budget-friendly option. Use the Pricing Calculator to estimate costs and ensure optimal resource allocation.
- For the networking part leave it as it is. (we will later configure this to allow your IP address to access your database)
Security
- You can choose to secure your database with Microsoft Defender for SQL, which offers advanced threat protection and security alerts, although it's not mandatory.
Create Tags
Tags play a crucial role in Azure by enabling resource organization, management, and cost tracking through metadata that categorizes resources for easier identification and billing analysis.
Review and create
Check the progress of your deployment in the notification section. After successful completion Go to resource button.
Configure access (go to query editor preview)
- Enter your Admin username and password you had set earlier for SQL server authentication or choose to continue with your azure account email.
Fix authentication error
If you encounter the error the following error, Failure to update firewall settings, here is how you can resolve it.
- Click on Allow IP Address to allow your IP Address to access your database
After a successful login, you see query editor where you can create tables.
Running Your First SQL Commands.
Create a table and insert values
CODE
CREATE TABLE Blogs (
id INT PRIMARY KEY IDENTITY(1,1), -- Unique identifier for each blog, auto-incremented
title NVARCHAR(255) NOT NULL, -- Title of the blog
content TEXT NOT NULL, -- Main content of the blog
author NVARCHAR(100) -- Author's name
);
INSERT INTO Blogs (title, content, author)
VALUES
('Introduction to Azure SQL Database', 'This blog covers the basics of setting up and using Azure SQL Database.', 'Gideon Ngetich'),
('Advanced Features of Azure SQL Database', 'Exploring advanced functionalities and optimizations in Azure SQL Database.', 'Lilian Wanjiku');
Output:
- After running the query:
SELECT * FROM Blogs;
- You will see the output displayed below the query editor once your query succeeds.
- This output will include all rows and columns from the specified table, allowing you to review the data stored within it easily. If there are no results, ensure that your table name is correct, and that data exists within the table.
Perform CRUD Operations
Create
- To insert a new blog
CODE
INSERT INTO Blogs (title, content, author)
VALUES
('Exploring Azure Functions', 'An in-depth guide to serverless computing with Azure Functions.', 'Gideon Ngetich'),
('Getting Started with Kubernetes', 'A beginner’s guide to container orchestration with Kubernetes.', 'Lilian Wanjiku');
Read
- Retrieve all entries(data)
SELECT * FROM Blogs;
Output
Update
- Modify existing data
CODE
UPDATE Blogs
SET title = 'Updated Title', content = 'Updated content here.', author = 'Updated Author'
WHERE id = 1;
Output
- This command will only update the row with the specified id.
SELECT * FROM Blogs;
Delete
- Delete a specific entry by id
CODE
DELETE FROM Blogs
WHERE id = 1;
Output
- Delete all rows in the table
CODE
DELETE FROM Blogs;
This command removes all rows from the Blogs table but keeps the table structure intact.
- Drop the entire table (if you want to delete the table itself, not just the rows)
CODE
DROP TABLE Blogs;
Congratulations, you have created your Azure SQL Database and run your first SQL commands!
Read More
Microsoft SQL documentation - SQL Server
SDKs
Use Node.js to query a database - Azure SQL
Use .NET (C#) to query a database - Azure SQL
Connect to and query Azure SQL Database using Python
Use Java and JDBC with Azure SQL Database