Identify Considerations for Relational Data on Azure · Topic 2 of 3

SQL Statements and Database Objects

DP-900 SQL basics: DDL, DML and DCL statements, the clauses of a SELECT query, joins, and database objects such as views, indexes and stored procedures.

  • 5 min
In a nutshell
  • DDL defines structure, DML works with rows, DCL controls permissions.
  • WHERE filters rows. HAVING filters groups after GROUP BY.
  • A view is a saved query with no stored data. An index speeds lookups. A stored procedure is saved SQL you call.

What it is

Structured query language, or SQL, is the standard language for working with relational databases. Its statements fall into groups by purpose. Some define structure, some work with data and some control access.

Alongside tables, a database holds other objects such as views, indexes and stored procedures that make data easier or faster to use.

DDLdefine structureDMLwork with rowsDCLcontrol access

How it works

Statement groups

GroupPurposeMain statements
DDL, data definition languageCreate or change the structureCREATE, ALTER, DROP
DML, data manipulation languageRead or change the rowsINSERT, UPDATE, DELETE, SELECT
DCL, data control languageControl who can do whatGRANT, REVOKE, DENY
CREATE TABLE Products (ProductID INT PRIMARY KEY, Name VARCHAR(50), Price DECIMAL(8,2));
INSERT INTO Products VALUES (1, 'Pen', 1.20);
UPDATE Products SET Price = 1.50 WHERE ProductID = 1;
DELETE FROM Products WHERE ProductID = 1;
GRANT SELECT ON Products TO analyst1;

An UPDATE or DELETE without a WHERE clause changes every row in the table, which is a classic mistake.

The parts of a query

A SELECT statement reads data. Each clause has one job.

SELECT Region, SUM(Total) AS Revenue
FROM Orders
WHERE OrderDate >= '2025-01-01'
GROUP BY Region
HAVING SUM(Total) > 10000
ORDER BY Revenue DESC;
ClauseJob
SELECTLists the columns or calculations to return
FROMNames the table or tables
WHEREFilters individual rows before grouping
GROUP BYGroups rows so an aggregate runs for each group
HAVINGFilters the groups after aggregation
ORDER BYSorts the result, ascending unless DESC is given

Common aggregate functions are COUNT, SUM, AVG, MIN and MAX. The database applies FROM first, then WHERE, GROUP BY, HAVING, SELECT and ORDER BY last.

Joins

A join combines rows from two tables using a matching column, usually a foreign key.

SELECT c.Name, o.Total
FROM Customers AS c
INNER JOIN Orders AS o ON o.CustomerID = c.CustomerID;

An INNER JOIN returns only rows that match on both sides. A LEFT JOIN keeps every row of the left table and fills in nulls where there is no match. A RIGHT JOIN does the same for the right table, and a FULL JOIN keeps unmatched rows from both.

Database objects

ObjectWhat it is
TableHolds the rows
ViewA saved query that behaves like a virtual table and holds no data of its own
IndexA structure that speeds up lookups on chosen columns, at a small cost for writes
Stored procedureA named, saved block of SQL that you run by calling it, often with parameters
FunctionA saved routine that returns a value or a table
TriggerCode that runs automatically when a row is inserted, updated or deleted

A clustered index decides the physical order of the rows in a table, so a table can have only one. A table can have many non clustered indexes, each a separate structure that points back to the rows.

A worked scenario

Managers keep asking for last month's revenue by region. A DBA saves the query as a view named MonthlyRevenue, so managers run a simple SELECT and never see the underlying joins. To make it fast, an index is added on OrderDate. For month end closing, a stored procedure runs the same steps every time with a date as its parameter. The users of each object need only the permission for that object, which a GRANT statement provides.

Reading a query step by step

Take the query that totals revenue by region. The database first reads Orders, then keeps only rows from 2025 onward, then forms one group for each region. It adds up Total in each group, discards groups of 10,000 or less, and finally sorts what remains from highest to lowest. Reading in this order, rather than top to bottom, explains why WHERE cannot use a total and HAVING can.

Handy operators and NULL

OperatorUse
=, <>, <, >Compare values
AND, OR, NOTCombine conditions
IN (...)Match any value in a list
BETWEEN a AND bMatch a range, including both ends
LIKE 'Ab%'Match a text pattern, where % stands for any characters
IS NULLTest for a missing value

NULL means unknown or missing. It is not zero and it is not an empty string, and = NULL never matches. You must write IS NULL.

Aggregate functions

FunctionReturns
COUNTThe number of rows
SUMThe total of a numeric column
AVGThe average
MIN and MAXThe smallest and largest value

COUNT(*) counts all rows in a group, while COUNT(Column) counts only rows where that column is not NULL.

Why use a view?

A view hides complexity and protects data. It can join several tables so users see one simple object, and it can expose only some columns. You can then GRANT access to the view without granting access to the tables behind it.

What to remember for the exam

  • DDL defines structure, DML works with rows, DCL controls permissions.
  • WHERE filters rows. HAVING filters groups after GROUP BY.
  • A view is a saved query with no stored data. An index speeds lookups. A stored procedure is saved SQL you call.
  • Only one clustered index per table, but many non clustered indexes.
  • An INNER JOIN returns only matching rows.
Exam tip

When a question shows a statement, find the first keyword. CREATE, ALTER and DROP are DDL. INSERT, UPDATE, DELETE and SELECT are DML. GRANT, REVOKE and DENY are DCL.

How the exam asks about this

  • "Which clause filters the groups?" HAVING.
  • "Which object is a saved query that behaves like a table?" A view.
  • "Which statement group does GRANT belong to?" DCL.
  • "Which object speeds up searches on a column?" An index.

Common mistakes

Putting an aggregate condition in WHERE. WHERE runs before grouping. Use HAVING for conditions on totals.

Thinking a view stores a copy of the data. It stores only the query. The data comes from the base tables each time.

Forgetting WHERE on UPDATE or DELETE. Every row is changed or removed.

Believing indexes are free. They speed reads but add work to every insert, update and delete.

Check yourself

  • Which statement group does CREATE TABLE belong to?

    DDL, data definition language.

  • Which clause filters rows after GROUP BY has formed groups?

    HAVING.

  • What does a view store?

    Only a saved query. The data stays in the underlying tables.

Topic 2 of 3 in Identify Considerations for Relational Data on Azure

Test yourself on Identify Considerations for Relational Data on Azure

The full Microsoft DP-900 question bank has 503 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by Microsoft. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.