Create And Use SQL Database In Microsoft Azure

In this article, we will see how to create and use SQL database in Azure.
 
 In my next article, we will use the SQL database which we are going to create in this article.
 

Create SQL database in Azure 

 
To create SQL database in Azure, login to the Azure portal.
 
Then click the SQL database icon in the portal. Please refer to the screenshot below.
 
 
 
We will be navigated to the below screen
 
 
Click either Create SQL database button or Add to create a SQL database.
 
The below screen will load to fill the database details 
 
  
 
Here, we need to fill the database names and server. If we don't have a SQL server, we need to create a new server by clicking the Create new link highlighted in the above figure. 
 
The new section will be visible to fill the server details. Please refer to the screenshot below.
 
 
 
We need to fill the server name, admin name, password, location to create the SQL server. Then click the OK button to create the server.
 
Once the SQL server is created, the server name will be available in the dropdown box in the create database section.
 
Next, we need to configure the database to match our requirements. Otherwise, it will make our account empty.   
 
Click the Configure database  link highlighted in below screenshot
 
 
 
A new screen will load to select the cost plan for our database.
 
Based on the configuration we will be charged.
 
Since this is a learning activity, I am going to select the Serverless option. Please refer to the screenshot below.
 
We can see the cost summary based on our configuration selection.
 
 
 
After this navigate to the database creation section and click the Review + Create button  
 
Summary of the database details will be displayed under Review + Create tab 
 
Varify the values provided and click the Create button to create our database. 
 
 
 
This will take a few minutes to create the database.
 
Once the database creation is completed, click the Go to resource button. We will be navigated to our database home screen.
 
 
Next, we need to set the server firewall to restrict unauthorized access to the database.
 
We can provide the allowed client IP address range to access the database.
 
To do this click the Set server firewall button in the database home screen.
 
Please refer to the screenshot below.
 
 
 
The new section will be visible to set the IP address range as below.
 
Here I am allowing connection from all IPs by providing the start IP as 0.0.0.0 and End IP as 255.255.255.255.
 
In real-world scenarios, we should provide the correct IP range for security. 
 
After this, we can test the database by executing SQL queries.
 
For this, either we can use SQL Server Management Studio (SSMS) or we can use the Query editor in the Azure portal.
 
Let's create table using the  SSMS first.
 
Copy the Azure SQL server name from portal (you can find it in the above screenshot) and paste it in SSMS login popup. And provide the user name and password as below.
 
 
 
 We will be connected to the Azure SQL server. We can see the databases by expanding the databases section.
 
 
 
Next, we can execute a CREATE TABLE query to create a new table as below.
 
 
Let's try to INSERT a record using the query editor in the Azure portal.
 
Please refer to the screenshot below.
 
 
Then, we can execute a SELECT query in SSMS to fetch the records from the table.
 
 
To connect the server from an application, we can use the SQL connection string. Connection string will be available in the portal.
 
 
Finally, we created Azure SQL server and database and executed the queries successfully using both SSMS and Azure query editor. 
 
Happy Learning 


Similar Articles