Vous êtes sur la page 1sur 29

Brian Alderman | MCT, CEO / Founder of MicroTechPoint

Tobias Ternstrom | Microsoft SQL Server Program Manager


Industry-recognized consultant
Noted author and conference speaker
Brians expertise and designs range across Microsoft
operating systems
Brian has been focused on helping IT Pros and Database Administrators (DBAs) better
understand core Microsoft technologies for over 25 years.
A frequent presenter at SharePoint Conferences around the world, he has authored or
contributed to several SharePoint, SQL Server, and other technical books, and is a MCSE, MCT,
and MCITP: SharePoint and SQL Server Administrator.
Brian has a BS and MS in Computer Information Systems where he graduated summa cum laude
from Regis University of Colorado Springs and lives in Scottsdale, AZ where he enjoys playing
golf year round and traveling around the world.



Meet Tobias Ternstrom

Principal Program Manager Lead in the SQL Server &
Windows Azure SQL DB product group
His team owns the development of the T-SQL language, type-
system and server-side libraries and performance
management in SQLDB

Tobias describes himself as a developer, instructor and
architect who has been using SQL Server since mid-90s
Querying Microsoft SQL Server 2012 Jump Start
01 | Introducing SQL Server 2012
SQL Server types of statements; other SQL statement elements; basic SELECT statements
02 | Advanced SELECT Statements
DISTINCT, Aliases, scalar functions and CASE, using JOIN and MERGE; Filtering and sorting data, NULL
values
03 | SQL Server Data Types
Introduce data types, data type usage, converting data types, understanding SQL Server function types
04 | Grouping and Aggregating Data
Aggregate functions, GROUP BY and HAVING clauses, subqueries; self-contained, correlated, and EXISTS; Views, inline-table
valued functions, and derived tables
| Lunch Break
Eat, drink, and recharge for the afternoon session
Querying Microsoft SQL Server 2012 Jump Start
05 | SET Operators, Windows Functions, and Grouping
SET operators, Windows functions, GROUPING sets (PIVOT, UNPIVOT, CUBE, ROLLUP)
06 | Modifying Data
INSERT, UPDATE, and DELETE statements, use of defaults, constraints, and triggers, OUTPUT
07 | Programming with T-SQL
Using T-SQL programming elements, implementing error handling, understanding and implementing transactions
08 | Retrieving SQL Server Metadata and Improving Query Performance
Querying system catalogs and dynamic management views, creating and executing stored procedures, improving SQL
Server query performance
01 | Introduction to Microsoft SQL Server
2012
Brian Alderman | MCT, CEO / Founder of MicroTechPoint
Tobias Ternstrom | Microsoft SQL Server Program Manager
Querying Microsoft SQL Server 2012 Jump Start
01 | Introducing SQL Server 2012
SQL Server types of statements; other SQL statement elements; basic SELECT statements
02 | Advanced SELECT Statements
DISTINCT, Aliases, scalar functions and CASE, using JOIN and MERGE; Filtering and sorting data, NULL
values
03 | SQL Server Data Types
Introduce data types, data type usage, converting data types, understanding SQL Server function types
04 | Grouping and Aggregating Data
Aggregate functions, GROUP BY and HAVING clauses, subqueries; self-contained, correlated, and EXISTS; Views, inline-table
valued functions, and derived tables
| Lunch Break
Eat, drink, and recharge for the afternoon session
Statements for
querying and
modifying data

SELECT, INSERT,
UPDATE, DELETE
Statements for object
definitions

CREATE, ALTER, DROP
Statements for security
permissions

GRANT, REVOKE, DENY
Data Manipulation
Language (DML*)
Data Definition
Language (DDL)
Data Control
Language (DCL)
* DML with SELECT is the primary focus of this course
Categories of T-SQL statements
Predicates and
Operators
Control of Flow Functions
Expressions
Variables
Comments
Batch Separators
T-SQL language elements
Elements: Predicates and Operators:
Predicates
IN, BETWEEN, LIKE
Comparison Operators
=, >, <, >=, <=, <>, !=, !>, !<
Logical Operators AND, OR, NOT
Arithmetic Operators +, -, *, /, %
Concatenation +
T-SQL enforces operator precedence
SUBSTRING
LEFT, RIGHT
LEN
DATALENGTH
REPLACE
REPLICATE
UPPER, LOWER
RTRIM, LTRIM
GETDATE
SYSTDATETIME
GETUTCDATE
DATEADD
DATEDIFF
YEAR
MONTH
DAY
SUM
MIN
MAX
AVG
COUNT
String Functions
Date and Time
Functions
Aggregate
Functions
T-SQL language elements: functions
DECLARE @MyVar int = 30;
T-SQL language elements: expressions
SELECT YEAR(OrderDate) + 1 ...
SELECT OrderQty * UnitPrice ...
TRY...CATCH
IF...ELSE
WHILE
BREAK
CONTINUE
BEGIN...END
BEGIN
TRANSACTION
COMMIT
TRANSACTION
ROLLBACK
TRANSACTION
Control of Flow Error Handling
Transaction Control
/*
This is a block
of commented code
*/
-- This line of text will be ignored
Logical query processing
5: SELECT <select list>
1: FROM <table source>
2: WHERE <search condition>
3: GROUP BY <group by list>
4: HAVING <search condition>
6: ORDER BY <order by list>
USE AdventureWorks2012;

SELECT SalesPersonID, YEAR(OrderDate) AS OrderYear
FROM Sales.SalesOrderHeader
WHERE CustomerID = 29974
GROUP BY SalesPersonID, YEAR(OrderDate)
HAVING COUNT(*) > 1
ORDER BY SalesPersonID, OrderYear;
Applying the logical order of operations
to writing SELECT statements
USE AdventureWorks2012;

SELECT SalesPersonID, YEAR(OrderDate) AS OrderYear
FROM Sales.SalesOrderHeader
WHERE CustomerID = 29974
GROUP BY SalesPersonID, YEAR(OrderDate)
HAVING COUNT(*) > 1
ORDER BY SalesPersonID, OrderYear;
Clause Expression
SELECT <select list>
FROM <table source>
WHERE <search condition>
GROUP BY <group by list>
ORDER BY <order by list>
SELECT CustomerID, StoreID
FROM Sales.Customer;
Keyword Expression
SELECT <select list>
FROM <table source>
SELECT unitprice, OrderQty, (unitprice * OrderQty)
FROM sales.salesorderdetail;
Operator Description
+ Add or concatenate
- Subtract
* Multiply
/ Divide
% Modulo
2013 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.