Update cookies preferences

E-book: T-SQL Fundamentals

4.45/5 (149 ratings by Goodreads)
  • Format: EPUB+DRM
  • Series: Developer Reference
  • Pub. Date: 03-Mar-2023
  • Publisher: Addison Wesley
  • Language: eng
  • ISBN-13: 9780138102081
  • Format - EPUB+DRM
  • Price: 38,60 €*
  • * the price is final i.e. no additional discount will apply
  • Add to basket
  • Add to Wishlist
  • This ebook is for personal use only. E-Books are non-refundable.
  • Format: EPUB+DRM
  • Series: Developer Reference
  • Pub. Date: 03-Mar-2023
  • Publisher: Addison Wesley
  • Language: eng
  • ISBN-13: 9780138102081

DRM restrictions

  • Copying (copy/paste):

    not allowed

  • Printing:

    not allowed

  • Usage:

    Digital Rights Management (DRM)
    The publisher has supplied this book in encrypted form, which means that you need to install free software in order to unlock and read it.  To read this e-book you have to create Adobe ID More info here. Ebook can be read and downloaded up to 6 devices (single user with the same Adobe ID).

    Required software
    To read this ebook on a mobile device (phone or tablet) you'll need to install this free app: PocketBook Reader (iOS / Android)

    To download and read this eBook on a PC or Mac you need Adobe Digital Editions (This is a free app specially developed for eBooks. It's not the same as Adobe Reader, which you probably already have on your computer.)

    You can't read this ebook with Amazon Kindle

Query and modify data effectively with the latest T-SQL features

Master Transact-SQL's fundamentals, and write correct, robust code for querying and modifying data with modern Microsoft data technologies, including SQL Server 2022, Azure SQL Database, and Azure SQL Managed Instance. Long-time Microsoft Data Platform MVP Itzik Ben-Gan explains key T-SQL concepts, helping you apply your knowledge with hands-on exercises. Ben-Gan first introduces T-SQL’s theory and underlying logic, illuminating it as both a language and a way of thinking. Next, he walks through core topics, including logical query processing, single table queries, joins, subqueries, table expressions, set operators, data analysis, data modifications, temporal tables, and transactions and concurrency. Building on this foundation, you'll enhance your coding capabilities, from programmatic constructs to the powerful new SQL Graph. Throughout, Ben-Gan presents reusable T-SQL sample code that works in cloud, on-premises, and hybrid environments.

Microsoft Data Platform MVP Itzik Ben-Gan helps you:

  • Understand why T-SQL works as it does, so you can write better code
  • Review relational theory elements and modern SQL Server architecture
  • Create tables and defi ne data integrity
  • Build single-table SELECT queries, multiple-table joins, and subqueries
  • Utilize derived tables, Common Table Expressions, views, inline table-valued functions, and APPLY
  • Make the most of UNION, INTERSECT, and EXCEPT set operators
  • Perform data analysis with window functions, pivoting, grouping sets, and time series
  • Insert, update, delete, and merge data
  • Get started with system-versioned temporal tables
  • Understand and apply transactions and concurrency, including concurrent user connections, locks, blocking, isolation levels, and more
  • Use SQL Graph to model, create, modify, and query graph-based data
  • Explore SQL Server programmable objects and programming capabilities
  • Set up your environment, install sample databases, and fi nd even more help

For IT Professionals and Consultants

  • For T-SQL developers, DBAs, BI practitioners, data scientists, report writers, analysts, architects, and SQL Server power users
  • For anyone else who needs to write queries or develop T-SQL code for SQL Server, Azure SQL Database, or Azure SQL Managed Instance
Acknowledgments xxi
About the Author xxii
Introduction xxiv
Chapter 1 Background to T-SQL querying and programming
1(26)
Theoretical background
1(12)
SQL
2(1)
Set theory
3(1)
Predicate logic
4(1)
The relational model
5(6)
Types of database workloads
11(2)
SQL Server architecture
13(7)
On-premises and cloud RDBMS flavors
13(2)
SQL Server instances
15(1)
Databases
16(3)
Schemas and objects
19(1)
Creating tables and defining data integrity
20(6)
Creating tables
21(1)
Defining data integrity
22(4)
Conclusion
26(1)
Chapter 2 Single-table queries
27(90)
Elements of the SELECT statement
27(23)
The FROM clause
29(2)
The WHERE clause
31(1)
The GROUP BY clause
32(4)
The HAVING clause
36(1)
The SELECT clause
37(5)
The ORDER BY clause
42(2)
The TOP and OFFSET-FETCH filters
44(5)
A quick look at window functions
49(1)
Predicates and operators
50(3)
CASE expressions
53(3)
NULLs
56(6)
The GREATEST and LEAST functions
62(1)
Ali-at-once operations
63(1)
Working with character data
64(19)
Data types
64(2)
Collation
66(2)
Operators and functions
68(13)
The Like predicate
81(2)
Working with date and time data
83(20)
Date and time data types
84(1)
Literals
84(4)
Working with date and time separately
88(2)
Filtering date ranges
90(1)
Date and time functions
90(13)
Querying metadata
103(3)
Catalog views
104(1)
Information schema views
105(1)
System stored procedures and functions
105(1)
Conclusion
106(1)
Exercises
107(4)
Exercise 1
107(1)
Exercise 2
107(1)
Exercise 3
108(1)
Exercise 4
108(1)
Exercise 5
109(1)
Exercise 6
109(1)
Exercise 7
109(1)
Exercise 8
110(1)
Exercise 9
110(1)
Exercise 10
111(1)
Solutions
111(6)
Exercise 1
111(1)
Exercise 2
112(1)
Exercise 3
112(1)
Exercise 4
112(1)
Exercise 5
113(1)
Exercise 6
114(1)
Exercise 7
115(1)
Exercise 8
115(1)
Exercise 9
116(1)
Exercise 10
116(1)
Chapter 3 Joins
117(32)
Cross joins
117(4)
SQL-92 syntax
118(1)
SQL-89 syntax
118(1)
Self cross joins
119(1)
Producing tables of numbers
120(1)
Inner joins
121(3)
SQL-92 syntax
121(1)
SQL-89 syntax
122(1)
Inner join safety
123(1)
More join examples
124(4)
Composite joins
124(1)
Non-equi joins
125(2)
Multi-join queries
127(1)
Outer joins
128(9)
Outer joins, described
128(2)
Including missing values
130(2)
Filtering attributes from the nonpreserved side of an outer join
132(1)
Using outer joins in a multi-join query
133(3)
Using the COUNT aggregate with outer joins
136(1)
Conclusion
137(1)
Exercises
137(5)
Exercise 1-1
137(1)
Exercise 1-2
138(1)
Exercise 2
139(1)
Exercise 3
140(1)
Exercise 4
140(1)
Exercise 5
141(1)
Exercise 6
141(1)
Exercise 7
141(1)
Exercise 8
142(1)
Exercise 9
142(7)
Solutions
143(1)
Exercise 1-1
143(1)
Exercise 1-2
143(1)
Exercise 2
144(1)
Exercise 3
144(1)
Exercise 4
145(1)
Exercise 5
145(1)
Exercise 6
145(1)
Exercise 7
146(1)
Exercise 8
146(1)
Exercise 9
147(2)
Chapter 4 Subqueries
149(28)
Self-contained subqueries
149(6)
Self-contained scalar subquery examples
149(2)
Self-contained multivalued subquery examples
151(4)
Correlated subqueries
155(4)
The EXISTS predicate
158(1)
Returning previous or next values
159(1)
Using running aggregates
160(1)
Dealing with misbehaving subqueries
161(5)
NULL trouble
161(2)
Substitution errors in subquery column names
163(3)
Conclusion
166(1)
Exercises
166(4)
Exercise 1
166(1)
Exercise 2
166(1)
Exercise 3
167(1)
Exercise 4
168(1)
Exercise 5
168(1)
Exercise 6
168(1)
Exercise 7
169(1)
Exercise 8
169(1)
Exercise 9
170(1)
Exercise 10
170(1)
Solutions
170(7)
Exercise 1
170(1)
Exercise 2
170(1)
Exercise 3
171(1)
Exercise 4
171(1)
Exercise 5
172(1)
Exercise 6
172(1)
Exercise 7
172(1)
Exercise 8
173(1)
Exercise 9
173(1)
Exercise 10
174(3)
Chapter 5 Table expressions
177(34)
Derived tables
177(6)
Assigning column aliases
179(2)
Using arguments
181(1)
Nesting
181(1)
Multiple references
182(1)
Common table expressions
183(5)
Assigning column aliases in CTEs
184(1)
Using arguments in CTEs
185(1)
Defining multiple CTEs
185(1)
Multiple references in CTEs
186(1)
Recursive CTEs
186(2)
Views
188(2)
Views and the ORDER BY clause
190(2)
View options
192(4)
Inline table-valued functions
196(1)
The APPLY operator
197(3)
Conclusion
200(1)
Exercises
201(5)
Exercise 1
201(1)
Exercise 2-1
201(1)
Exercise 2-2
202(1)
Exercise 3-1
202(1)
Exercise 3-2
203(1)
Exercise 4
203(1)
Exercise 5-1
203(1)
Exercise 5-2
204(1)
Exercise 6-1
205(1)
Exercise 6-2
205(1)
Solutions
206(5)
Exercise 1
206(1)
Exercise 2-1
206(1)
Exercise 2-2
206(1)
Exercise 3-1
207(1)
Exercise 3-2
207(1)
Exercise 4
207(1)
Exercise 5-1
208(1)
Exercise 5-2
208(1)
Exercise 6-1
209(1)
Exercise 6-2
209(2)
Chapter 6 Set operators
211(20)
The Union operator
212(2)
The Union All operator
213(1)
The Union (Distinct) operator
213(1)
The Intersect operator
214(3)
The Intersect (Distinct) operator
215(1)
The Intersect ALL operator
215(2)
The Except operator
217(3)
The Except (Distinct) operator
218(1)
The Except All operator
219(1)
Precedence
220(1)
Circumventing unsupported logical phases
221(2)
Conclusion
223(1)
Exercises
223(4)
Exercise 1
223(1)
Exercise 2
223(1)
Exercise 3
224(1)
Exercise 4
225(1)
Exercise 5
225(1)
Exercise 6
226(1)
Solutions
227(4)
Exercise 1
227(1)
Exercise 2
227(1)
Exercise 3
228(1)
Exercise 4
228(1)
Exercise 5
229(1)
Exercise 6
230(1)
Chapter 7 T-SQL for data analysis
231(62)
Window functions
231(15)
Ranking window functions
234(3)
Offset window functions
237(5)
Aggregate window functions
242(2)
The WINDOW clause
244(2)
Pivoting data
246(5)
Pivoting with a grouped query
248(1)
Pivoting with the P/VOf operator
249(2)
Unpivoting data
251(5)
Unpivoting with the APPLY operator
253(2)
Unpivoting with the UNPIVO Toperator
255(1)
Grouping sets
256(6)
The GROUPING SETS subclause
258(1)
The CUBE subclause
258(1)
The ROLLUP subclause
258(2)
The GROUPING and GROUPINGJD functions
260(2)
Time series
262(18)
Sample data
263(3)
The DATE_BUCKET function
266(2)
Custom computation of start of containing bucket
268(2)
Applying bucket logic to sample data
270(5)
Gap filling
275(5)
Conclusion
280(1)
Exercises
280(5)
Exercise 1
280(1)
Exercise 2
281(1)
Exercise 3
282(1)
Exercise 4
282(1)
Exercise 5
282(1)
Exercise 6
283(1)
Exercise 7
284(1)
Exercise 8
285(1)
Solutions
285(8)
Exercise 1
285(1)
Exercise 2
286(1)
Exercise 3
286(1)
Exercise 4
286(1)
Exercise 5
287(1)
Exercise 6
288(1)
Exercise 7
289(1)
Exercise 8
290(3)
Chapter 8 Data modification
293(50)
Inserting data
293(14)
The INSERT VALUES statement
293(2)
The INSERT SELECT statement
295(1)
The INSERT EXEC statement
296(1)
The SELECT INTO statement
297(1)
The BULK INSERT statement
298(1)
The identity property and the sequence object
298(9)
Deleting data
307(4)
The DELETE statement
308(1)
The TRUNCATE statement
309(1)
DELETE based on a Join
310(1)
Updating data
311(6)
The UPDATE statement
313(1)
UPDATE based on a join
314(2)
Assignment UPDATE
316(1)
Merging data
317(4)
Modifying data through table expressions
321(3)
Modifications with TOP and OFFSET-FETCH
324(2)
The OUTPUT clause
326(7)
INSERT with OUTPUT
326(2)
DELETE with OUTPUT
328(1)
UPDATE with OUTPUT
329(1)
MERGE with OUTPUT
330(1)
Nested DML
331(2)
Conclusion
333(1)
Exercises
333(4)
Exercise 1
333(1)
Exercise 2
334(1)
Exercise 3
334(1)
Exercise 4
334(2)
Exercise 5
336(1)
Exercise 6
336(1)
Solutions
337(6)
Exercise 1
337(1)
Exercise 2
338(1)
Exercise 3
339(1)
Exercise 4
340(1)
Exercise 5
340(1)
Exercise 6
341(2)
Chapter 9 Temporal tables
343(24)
Creating tables
344(4)
Modifying data
348(5)
Querying data
353(7)
Conclusion
360(1)
Exercises
360(2)
Exercise 1
360(1)
Exercise 2
360(1)
Exercise 3
361(1)
Exercise 4
362(1)
Solutions
362(5)
Exercise 1
362(2)
Exercise 2
364(1)
Exercise 3
365(1)
Exercise 4
366(1)
Chapter 10 Transactions and concurrency
367(42)
Transactions
367(3)
Locks and blocking
370(10)
Locks
371(2)
Troubleshooting blocking
373(7)
Isolation levels
380(14)
The READ UNCOMMITTED isolation level
381(1)
The READ COMMITTED isolation level
382(2)
The REPEATABLE READ isolation level
384(2)
The SERIALIZABLE isolation level
386(1)
Isolation levels based on row versioning
387(7)
Summary of isolation levels
394(1)
Deadlocks
394(3)
Conclusion
397(1)
Exercises
397(12)
Exercise 1
397(3)
Exercise 2
400(7)
Exercise 3
407(2)
Chapter 11 SQL Graph
409(82)
Creating tables
410(28)
Traditional modeling
411(6)
Graph modeling
417(21)
Querying data
438(36)
Using the MATCH clause
438(12)
Recursive queries
450(4)
Using the SHORTESTPATH option
454(17)
SQL Graph querying features that are still missing
471(3)
Data modification considerations
474(6)
Deleting and updating data
474(3)
Merging data
477(3)
Conclusion
480(1)
Exercises
481(3)
Exercise 1
481(1)
Exercise 2
482(1)
Exercise 3
483(1)
Exercise 4
483(1)
Solutions
484(6)
Exercise 1
484(1)
Exercise 2
485(2)
Exercise 3
487(1)
Exercise 4
488(2)
Cleanup
490(1)
Chapter 12 Programmable objects
491(36)
Variables
491(3)
Batches
494(3)
A batch as a unit of parsing
494(1)
Batches and variables
495(1)
Statements that cannot be combined in the same batch
495(1)
A batch as a unit of resolution
496(1)
The GO n option
496(1)
Flow elements
497(3)
The IF... ELSE flow element
497(1)
The WHILE flow element
498(2)
Cursors
500(5)
Temporary tables
505(5)
Local temporary tables
505(2)
Global temporary tables
507(1)
Table variables
508(1)
Table types
509(1)
Dynamic SQL
510(3)
The EXEC command
511(1)
The sp_executesql stored procedure
511(1)
Using PIVOT with Dynamic SQL
512(1)
Routines
513(8)
User-defined functions
514(1)
Stored procedures
515(2)
Triggers
517(4)
Error handling
521(4)
Conclusion
525(2)
Appendix: Getting started 527(20)
Index 547
Itzik Ben-Gan is a mentor with and co-founder of SolidQ. A Microsoft Data Platform MVP since 1999, Itzik has taught numerous training events around the world focused on T-SQL querying, query tuning, and programming. Itzik is the author of several books about T-SQL. He has written many articles for SQL Server Pro as well as articles and white papers for MSDN and The SolidQ Journal. Itzik's speaking engagements include Tech-Ed, SQL PASS, SQL Server Connections, presentations to various SQL Server user groups, and SolidQ events.

Itzik is a subject-matter expert within SolidQ for its T-SQL related activities. He authored SolidQ's Advanced T-SQL and T-SQL Fundamentals courses and delivers them regularly worldwide. You can learn more about Itzik at http://tsql.solidq.com/.