Database Reference
In-Depth Information
C H A P T E R 5
Querying Databases
In this chapter, you will learn about coding queries in SQL Server 2012. SQL Server uses T-SQL as its
language, and it has a wide variety of functions and constructs for querying. You will see how to use SQL
Server Management Studio and the AdventureWorks database to submit queries for various scenarios of
querying data. This chapter covers the following:
•
Retrieving data
•
Using the
GROUP BY
clause
•
Pattern matching
•
Using aggregate functions
•
Using
DATETIME
functions
•
Using the list operator
•
Using the range operator
•
Finding null values
•
Using joins
Retrieving Data
A SQL query retrieves data from a database. Data is stored as
rows
in
tables.
Rows are composed of
columns.
In its simplest form, a query consists of two parts:
•
A
SELECT
list, where the columns to be retrieved are specified
•
A
FROM
clause, where the table or tables to be accessed are specified