Querying With T-SQL - 01
Querying With T-SQL - 01
Querying With T-SQL - 01
Course Topics
Querying with Transact-SQL
01 | Introduction to Transact-SQL
09 | Modifying Data
Setting Expectations
Target Audience
Aspiring database professionals
Application developers
Anyone preparing for SQL Server certification exams
Course Materials
Online video presentations
Downloadable labs
Suggested Approach
Complete each module and lab in turn
Engage with fellow students at Born To Learn
DEMO
Using Azure SQL Database
Microsoft Press
www.microsoftpressstore.com
Born to Learn
borntolearn.mslearn.net
Click to edit
Master subtitle
style
01 | Introduction to Transact-SQL
Graeme Malcolm | Senior Content Developer,
Microsoft
Geoff Allix | Principal Technologist, Content Master
Module Overview
What is Transact-SQL?
Relational Databases
Schemas and Object Names
SQL Statement Types
The SELECT Statement
Working with Data Types
Working with NULLs
What is Transact-SQL?
Structured Query Language (SQL)
Developed by IBM in 1970s
Adopted as a standard by ANSI and ISO standards bodies
Widely used in industry
Relational Databases
Entities are represented as relations (tables), in
which their attributes are represented as domains
(columns)
Most relational databases are normalized, with
relationships defined between tables
through primary
SalesOrderDetail
Customer
OrderI LineItem
ProductI Quantit
and
foreign
keys
D
No
D
y
Customer FirstNam LastNa
ID
me
Dan
Drayton
Aisha
Witt
Rosie
Reeves
SalesOrderHeader
Product
OrderI
D
OrderDa
te
Customer
ID
ProductI
D
Name
ListPrice
1/1/2015
Widget
2.99
1/1/2015
Gizmo
1.79
1/2/2015
Thingyb
3.49
Production
Product
Sales.Order
Sales.Customer
Custome
r
Order
Production.Product
Production.Order
Statements for
assigning security
permissions:
GRANT
REVOKE
DENY
Focus of this
course
1
2 FROM
3 WHERE
4
GROUP BY
6
HAVING
ORDER BY
Expression
<select list>
Role
Defines which columns to
return
Defines table(s) to query
Filters rows using a predicate
<table source>
<search
condition>
<group by list>
Arranges rows by groups
<search
Filters groups using a
condition>
predicate
SELECT
OrderDate, COUNT(OrderID)
FROM
Sales.SalesOrder
<order
by list>
Sorts the output
WHERE Status = 'Shipped'
GROUP BY OrderDate
HAVING COUNT(OrderID) > 1
ORDER BY OrderDate DESC;
Specific columns
SELECT Name, ListPrice
FROM Production.Product;
DEMO
Basic SELECT Queries
Approximate
Numeric
Character
Date/Time
Binary
Other
tinyint
float
char
date
binary
cursor
smallint
real
varchar
time
varbinary
hierarchyid
int
text
datetime
image
sql_variant
bigint
nchar
datetime2
table
bit
nvarchar
smalldatetim
e
timestamp
decimal/nume
ric
ntext
datetimeoffs
et
uniqueidenti
fier
numeric
xml
money
geography
smallmoney
geometry
Explicit Conversion
Requires an explicit conversion function
CAST / TRY_CAST
CONVERT / TRY_CONVERT
PARSE / TRY_PARSE
STR
DEMO
Converting Data Types
ISNULL(column/variable, value)
Returns value if the column or variable is NULL
NULLIF(column/variable, value)
Returns NULL if the column or variable is value
DEMO
Working with NULLs
Introduction to Transact-SQL
What is Transact-SQL?
Relational Databases
Schemas and Object Names
SQL Statement Types
The SELECT Statement
Working with Data Types
Working with NULLs
Lab: Introduction to Transact-SQL
2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, Office, Azure, System Center, Dynamics and other product names are or may be registered
trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of
Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a
commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT
MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.