• 1 year ago
In this DP-900 lecture, we explore how to query relational databases in Microsoft Azure using SQL. Whether you're preparing for the DP-900 certification or looking to improve your SQL query skills, this session provides a step-by-step guide to retrieving and manipulating data in Azure SQL Database, PostgreSQL, MySQL, and other relational services.

๐Ÿ” What Youโ€™ll Learn in This Session:
โœ… Introduction to SQL Queries & Relational Data in Azure
โœ… Understanding SELECT, INSERT, UPDATE & DELETE Commands
โœ… Using WHERE, ORDER BY, and GROUP BY Clauses for Data Filtering
โœ… Joins & Relationships โ€“ INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL JOIN
โœ… Aggregating Data with COUNT, SUM, AVG, MIN, MAX Functions
โœ… Executing Queries in Azure SQL Database & Other Relational Services
โœ… Best Practices for Query Optimization & Performance

๐Ÿ› ๏ธ Who Should Watch This?
Beginners & IT professionals learning SQL & Azure database queries
Students & aspiring data engineers preparing for DP-900 certification
Developers & database administrators working with Azure SQL, MySQL, or PostgreSQL
Business analysts & data professionals exploring querying techniques in cloud databases

๐Ÿ“Œ Key Highlights:
โœ… Step-by-step SQL query demonstrations in Azure
โœ… Live examples using Azure SQL Database
โœ… Best practices for writing optimized & efficient queries
โœ… DP-900 exam-focused insights

๐Ÿ’ก Master SQL queries & relational data management in Azure today!

Explore Our Other Courses and Additional Resources on: https://skilltech.club/
Transcript
00:00Okay, now in this video we are going to focus on how we can query relational data in Azure.
00:13Obviously we will see various kind of queries in this particular video and we will try these
00:19queries also in a demo with our Azure SQL Database which we have provisioned in the
00:24previous lecture. With querying relational data we will also describe what kind of query
00:32techniques we can use for SQL language. Now when you are using SQL language there are various
00:39options like we have transactional SQL queries, we have PL SQL queries, so we will see those
00:46different techniques and we will see that what are the usage of that. Now when it comes
00:53to writing query, SQL is the standard language for using the relational databases. So when
00:59you are using PostgreSQL or SQL server hosted on on-premise or Azure, you are going to use
01:06this query language. SQL standards are maintained by the NC and ISO. I am sure you heard about
01:12NC and ISO organizations, they maintain the standard of SQL. Propriety IRDBMS systems have
01:19their own extensions of SQL, such as TSQL, PL SQL and PGSQL. When you write queries for SQL
01:28server and when you write queries for PostgreSQL, they both use different varieties in the SQL
01:34language. Like Azure SQL or any normal SQL server use transactional SQL queries and while
01:42PostgreSQL use PSQL queries which are similar but not the same. When we talk about SQL statements,
01:49in that also we have three different variations. We have data manipulation language which is
01:55formerly known as DML. Same way we have data definition language DDL and data control language
02:03which is DCL. The purpose of your query and the statement is actually going to segregate
02:09them into these three different categories. Data manipulation language mostly focus on transactionals,
02:15obviously used to manipulate the data which is associated inside your tables and then you
02:21can manipulate the data. The most common statement of DMLs are select, insert, update, delete kind
02:27of statement so that you can insert a new data, you can update it, you can select some particular
02:32records or maybe one single record and then you can also delete it. But this is all about
02:37data manipulation. If you want to change the table structure, you want to add some extra columns
02:43or you want to change the data type of that or maybe you just want to rename the table or
02:48you want to drop the table then that is going to be your data definition language and the
02:54queries are obviously create, table, alter table, drop, rename. And not only tables, you can
03:01also do the similar kind of definition languages for store procedures and views also. Then we have
03:08final one which is DCL which is data control language and this focus on permissions and
03:14security. You want to grant or revoke permissions for a particular tables, views or store procedures
03:20or maybe you want to deny it then you can do this kind of controlling the access and the
03:26permission of your tables, views and store procedures with the help of DCL queries. As we discuss the
03:34description and the statement is mentioned here for DML, what purpose of select, insert, update
03:39and delete is going to do into this that is visible here. And if you ask me how it's going
03:45to look like, how this queries of DML looks like, then we are going to see some of them.
03:50When you start with select statement, I think select is one of the easiest as well as one of
03:55the most complex query can be also select query because it can have various customizations
04:01inside that. You can see we have clauses. These clauses are nothing but some kind of a keywords
04:06which you are going to use in your queries. And mostly all these keywords are going to
04:11appear in a blue color whenever you write query, in any IDE actually. And then you can see
04:17here the select statement is going to start with the select clause. Then we have from means
04:23from which table of view you want to select the data. Then we have where condition which can
04:29have one or more column values associated with that. And then if you want to organize your
04:35data properly then you have group by and order by kind of clause inside that. Which can be
04:40optional. Obviously where group by order by can be an optional clauses which you want to
04:46add to maybe get the proper data from your tables. The standard select statement looks like
04:53this. You can see I have a select clause. After that I'm just mentioning I want to focus on employee ID,
05:01the year which is going to associate with the order date column as order year. And it's like I'm trying
05:08to select two columns from my table actually. Then the name of the table is sales.orders. Sales is going
05:15to be the schema and then orders is going to be the table where I want a specific record not multiple. So I'm
05:21just specifying where customer ID which is logically going to be primary key ID for customer table.
05:27And that is equals to 71. And then I'm saying that when I'm getting this thing if I am getting
05:34more records for that particular year then I want to group by them by employee ID a year. So it's like
05:43for each employee and for each year I will get multiple records and then it will be grouped by into
05:49that group having the count greater than equals to no sorry having the crown greater than one. It means
05:56if I have minimum one record for that then only I'm going to take it and then the order by is actually
06:01given by employee ID and order year. Once you do this thing it's going to give you a record data coming
06:07from this kind of tables and then it's going to show you only employee ID and order year with this kind
06:13of group by condition. Same way if I show you some example of insert statement insert is going to
06:20have a clause insert and with that we will have one more keyword called into where you mention the table
06:26name then you have to provide the values for all the non-null columns actually. So if there is a null column
06:34it will be optional but if you have to provide value for the non-null columns then you can specify
06:40not knowing that column type. You can see we are providing values for order ID, product ID,
06:45unit price, quantity and discount and before providing values actually I'm just mentioning column name
06:52then values clause and then I'm just specifying value for each one by comma separated. So it's like
06:59the first one is my order ID which is 10255 then product ID is 39, unit price is 18, quantity is 2 and
07:08discount is 0.05 percent. Then you can see that table and rows constructors and multiple capabilities
07:17to insert values. So you can have multiple rows capability to insert values. So once I define
07:23an insert statement if I want to add two three or more records in one shot I can use this kind of query
07:29also where the first half is same up to column names but after values in spite of passing only one value
07:36you can add multiple. It's like you can see I have changed the value for my order ID and I have
07:43changed the value for my quantity and discount. The product ID is same, the unit price is same,
07:49but I just want to add some more records for multiple orders actually and that's what we are doing in the
07:55second query. Then if we focus on DDL which is going to take care of my create, alter, drop and rename
08:06kind of statement for my tables, views and store procedures then the similar kind of descriptions
08:11will be available there as we discuss and the example of this statement will be like create table.
08:18Remember this is not insert table. Insert table will work only once you create a table. So obviously
08:24these queries you have to execute first in order to do the proper configuration. This will create a table
08:30with whatever name I'm going to give there. Then my column names with data type with the properties
08:36like not null or primary key for each column I can specify and then I think all three columns here
08:42are having not null. My first column is having primary key so that it's going to be a uniquely identified
08:48column. Column 1 is integer while column 2 and column 3 both have wherecare with the different kind of size
08:57associated with that. Column 2 is wherecare50 so I can have fake characters can be stored inside that
09:03column 3 and column 3 is actually 10 so that it's going to have only 10 characters for that.
09:10Remember when you're dealing with this kind of SQL queries you can use different tools. Now depends
09:16upon your choice and your computer's configuration you can use any of these tools. You can write queries
09:23directly inside Azure portal which I'm going to show you very soon in my demo. You can use SQL Server
09:29Management Studio. Formally I call it SSMS. You can use SSDT, SQL Server Data Tools also. You can use Azure Data Studio, SQL Command Prompt or there is an in-browser command prompt which is known as Cloud Shell.
09:44You can use any of these six tools to execute query. Query syntax and structure will be same. The output is also going to be same.
09:52The performance time is also going to be same because it ultimately depends on where you have hosted your database
09:59and what kind of configuration you have with that. Query tools are just going to give you an environment
10:05where you put your queries. It can give you a syntax check kind of features associated with that and then
10:11you can execute with your choice of query tools. As we discussed you can see here we have some screenshot for
10:19p-sql queries of PostgreSQL and as I mentioned it looks similar but it's not same always. When you
10:27do create database, create table kind of options in PostgreSQL you can see that it's showing me some
10:34create table options then I can specify the name, text, not null, age, integer, not null kind of
10:42questions I've given, sorry kind of values I've given in that. Then we have some insert statement then
10:49we have another create table for locations and some insert statement for that. It looks similar and
10:55it will be easier for you to understand if you know one of them then that is going to be easier but
11:01yeah this is how we can try this thing with the p-sql queries in Azure Cloud Shell and same way if you
11:08want to query relational data using MySQL the MySQL queries are also going to be similar you just need
11:15to connect your database with any other tool where you can execute MySQL queries and then similarly you
11:21can do that thing. You'll get better idea when we see the demo of this thing very soon. In our demo we
11:27are going to focus on how to use SQL queries in our Azure SQL database which we have already hosted on
11:34Azure Cloud and that's what we are going to see now. Okay so now I'm there in my Azure portal and
11:42I'm there with the same database which we have created earlier in the previous lesson. You can see
11:48that my database server name is listed here. I have my set server firewall kind of column where we have
11:55already seen that we have an IP address added. I just got disconnected in between so I have a different
12:01client IP address. If this kind of thing happens for you also then you need to make sure that this
12:07database client IP you're going to add into this. All you need to do is just click on add client IP
12:12address here in the firewall settings of the database and then your new IP is going to be added here so
12:18that you can access to this particular SQL server. I'm going to click on save so that I can connect to
12:25the SQL server from anywhere from any tool like SQL server management studio or even the in browser tool
12:33which is available here in this portal called query editor. If you are struggling to find out this
12:38database you can go to your resource group and then you can find out the database with whatever name
12:44you have given there. I'm there inside my database it's showing me that I'm able to see the database
12:50inside this Azure portal. Let me try to connect with this so I'm going to click on query editor in the
12:56left side column and it's going to ask me what is your login credential? What is your username and
13:03password? Remember you have to give that username and password which you have given while provisioning
13:08this SQL server into Azure. I'm providing that password. I'm going to click on OK and if everything
13:18is valid if your IP address is also added and if this particular username and password is correct
13:23it will take you to this kind of a tool. This is what we call query editor and as you can mention here
13:29this is actually having limited facilities for writing queries and executing it here. For full capabilities
13:37of this you can use SSD which is SQL server data tool actually but yeah we are OK with this particular
13:45thing for demo. If I expand tables I don't have any tables. If I expand views I have some system views
13:52which are by default created for the firewall rules which we have configured and if I expand stored
13:57procedures I don't have any stored procedures right now. Let me execute some very basic query. Before
14:04proceeding I think I need some kind of tables, view, stored procedure kind of thing so I need to execute some
14:10data definition language first. So let me execute one query quickly. My first query which I'm showing
14:17you is this. You can see I have a create table query and I'm giving some schema name which is dbo database
14:25object and then the table name is actually going to be emp for employee and then I'm specifying that I'm
14:32going to have three columns id first name and last name where id is going to be integer and not null as well as
14:38primary key. With that I'm adding one more property, one more key there which is actually identity. This identity
14:45is going to make sure that my value for primary key is going to become automatically added into this and
14:52also it's going to do increment of one one one every time. So it's like first primary key record is going
14:57to be one then two then three. I can also give some initial starting value for that if I want to start from
15:03a specific number. First name and last name both are right now having where care 50 so it's going to be
15:09something like a string kind of thing we can add into this and yep that's fine. Let me click on run.
15:16I can see that it's just within few seconds it's even not very second zero second they are showing me
15:22query succeeded and if the query is actually succeeded then then this particular table it has to be created
15:29here. Let me click on refresh and then if I expand tables I should be able to see my table with the same
15:36kind of columns which I have given. It means successfully we are able to execute our first SQL query.
15:43Now obviously after this create table if I want to have some data inside that like right now let's say I'm
15:50firing one query which is select star star is for all the columns from the my table which is emp. If I try to
16:00select records from this I won't get much thing because there is no record here. They are showing me affected
16:06rows are zero. Query is executed but there are no rows there are no data to show you here inside this query.
16:12So that's why before we execute select we actually need to execute some insert statement. So let me just get rid of
16:19this line and if I want to insert only one record like I can put some record like this. You can see
16:26I have one query which is insert into this table name which is employee. I can put dbo.emp or only
16:32employee both will work fine. I am specific column names like first name last name. Id I don't need to
16:38enter because I have given it as a identity column and then values for this first name and last name I'm giving
16:45like Maruti and Makwana. So if I run this query it's going to show me that query succeeded affected
16:52rows is one it means that one record is actually successfully inserted and obviously now if I want
17:00to add few more records I can change my query I can just change the value for first name last name here
17:06also or maybe if I want to add more than one records in one insert query then as we have discussed earlier
17:13I can add on like this also insert into employee but this time let's say I'm adding few more employees
17:19where Rahul Sharma and Megha Singh is also going to be added here so two employees are going to be added
17:25you just have to separate them with comma and at the end I'm putting something like semi column let me run
17:31this and it's showing yes query succeeded affected rows are two and obviously now if I want to check whether
17:38the three records are actually inserted in this table or not all I have to do is I have to again
17:44execute my select star from my employee table and let me see if I run this query I am getting my three
17:55employees which are listed there this sounds very easy and quick right now I advise you that if you do
18:03not have any install tools available you can use the sequel database and this in browser query editor
18:09which is quite useful and quite easy to handle this thing here you can try some more queries by
18:17searching on this online otherwise in this video description you can find out the official lab for this
18:23particular training course also in those labs also there are a couple of official labs which are shared by
18:29Microsoft for this certification exam you can try those labs here now in spite of writing some more
18:36queries I just want you to showcase some more things here like because this is not a normal sql server
18:42database this is a cloud base assure cloud base equals or database you can see you're getting some
18:48additional options here in the left side section I have an options to directly connect with the power
18:54platform for better representation of my data like power bi and power apps can be connected with this
18:59data directly and I can visualize my data with that I can also configure my settings for this database
19:07that is fine but then you can see there is a section for data management where I have a section called
19:13replicas because we are on cloud right now and we know the thing that while creating this database
19:20I have deployed this thing in the east us region of microsoft as your cloud now if I want to take care of
19:27some kind of failover or I want to take care of my disaster recovery kind of scenarios
19:33then I do not want to put my data only in one region because there are chances because of some
19:39natural disasters or some human issues and power failure kind of thing maybe sometimes my data is
19:45not going to be available and if I do not want to have this kind of downtime I can just improve my
19:53high availability by creating multiple read-only replicas I can go to this replica sections I can
19:59create replica which will take me to another page where for the same database and for the same server
20:06you can see I can create one more server in some different part of the world so in spite of us maybe I
20:13can choose this time that I want to choose this maybe in the in the north europe region and then
20:19in that server I can give all together a different name different credentials it's my choice as I want to configure it
20:26and then it's going to create one more
20:28geographical replica which is going to be read-only replica for the same database the the one table and the records
20:36which we have inside this will come automatically into that if you want to try a few more things with sql database and all I
20:44advise you to go for my different courses on ensure like az204 course or dp203 course you can try this courses for
20:54getting more hands-on with this kind of things
20:58I hope you're getting it let's move forward to the next module
21:03well I think with this we are done with module number two also
21:06I seriously request you guys if you really want to get connected with us you can go to our official
21:13site mentorstech.com or you can just follow us on facebook and youtube we are available there also
21:20please be connected with us and happy learning
21:24so in this video we have seen how we can query relational data in azure cloud
21:29we have provision our azure sql database in the previous lesson but in this we have created some
21:35table we have added some records into that and we have also tried to get those records in that
21:41and we have also discussed about geographical replication available on azure sql database

Recommended