Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
133 views

Murachs SQL Server 2016 For Developers TOC

This document provides an overview of the contents and organization of the book "Murach's SQL Server 2016 for Developers". It includes 20 chapters organized into 4 sections that cover topics related to relational databases, SQL, database design and implementation, and advanced SQL skills. The chapters provide guidance on using SQL Server 2016 tools like the Management Studio to work with databases, write queries, and perform tasks such as retrieving, updating, and managing data.

Uploaded by

midowakil
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
133 views

Murachs SQL Server 2016 For Developers TOC

This document provides an overview of the contents and organization of the book "Murach's SQL Server 2016 for Developers". It includes 20 chapters organized into 4 sections that cover topics related to relational databases, SQL, database design and implementation, and advanced SQL skills. The chapters provide guidance on using SQL Server 2016 tools like the Management Studio to work with databases, write queries, and perform tasks such as retrieving, updating, and managing data.

Uploaded by

midowakil
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Murach’s SQL Server 2016

for Developers
Introduction xv

Section 1 An introduction to SQL


Chapter 1 An introduction to relational databases and SQL 3
Chapter 2 How to use the Management Studio 49

Section 2 The essential SQL skills


Chapter 3 How to retrieve data from a single table 85
Chapter 4 How to retrieve data from two or more tables 125
Chapter 5 How to code summary queries 159
Chapter 6 How to code subqueries 183
Chapter 7 How to insert, update, and delete data 215
Chapter 8 How to work with data types 239
Chapter 9 How to work with functions 261

Section 3 Database design and implementation


Chapter 10 How to design a database 303
Chapter 11 How to create a database and its tables with SQL statements 333
Chapter 12 How to create a database and its tables with the Management Studio 367

Section 4 Advanced SQL skills


Chapter 13 How to work with views 387
Chapter 14 How to code scripts 409
Chapter 15 How to code stored procedures, functions, and triggers 449
Chapter 16 How to manage transactions and locking 501
Chapter 17 How to manage database security 527
Chapter 18 How to work with XML 579
Chapter 19 How to work with BLOBs 611
Chapter 20 An introduction to CLR integration 639

Reference aids
Appendix A How to set up your computer for this book 649
Index 661
Expanded contents v

Expanded contents
Section 1 An introduction to SQL
Chapter 1 An introduction to relational databases and SQL
An introduction to client/server systems..........................................4
The hardware components of a client/server system.......................................................4
The software components of a client/server system.........................................................6
Other client/server system architectures..........................................................................8
An introduction to the relational database model.......................... 10
How a database table is organized.................................................................................10
How the tables in a relational database are related........................................................12
How the columns in a table are defined.........................................................................14
How relational databases compare to other data models...............................................16
An introduction to SQL and SQL-based systems.......................... 18
A brief history of SQL...................................................................................................18
A comparison of Oracle, DB2, MySQL, and SQL Server.............................................20
The Transact-SQL statements..........................................................22
An introduction to the SQL statements..........................................................................22
Typical statements for working with database objects...................................................24
How to query a single table............................................................................................26
How to join data from two or more tables.....................................................................28
How to add, update, and delete data in a table...............................................................30
SQL coding guidelines...................................................................................................32
How to work with other database objects.......................................34
How to work with views................................................................................................34
How to work with stored procedures, triggers, and user-defined functions...................36
How to use SQL from an application program...............................38
Common data access models.........................................................................................38
How to use ADO.NET from a .NET application...........................................................40
Visual Basic code that retrieves data from a SQL Server database................................42
C# code that retrieves data from a SQL Server database...............................................44

Chapter 2 How to use the Management Studio


An introduction to SQL Server 2016................................................50
A summary of the SQL Server 2016 tools.....................................................................50
How to start and stop the database engine.....................................................................52
How to enable remote connections................................................................................52
An introduction to the Management Studio....................................54
How to connect to a database server..............................................................................54
How to navigate through the database objects...............................................................56
How to manage the database files...................................................58
How to attach a database................................................................................................58
How to detach a database...............................................................................................58
How to back up a database.............................................................................................60
How to restore a database...............................................................................................60
How to set the compatibility level for a database..........................................................62
vi Expanded contents

How to view and modify the database.............................................64


How to view the database diagrams...............................................................................64
How to view the column definitions of a table...............................................................66
How to modify the column definitions...........................................................................66
How to view the data of a table......................................................................................68
How to modify the data of a table..................................................................................68
How to work with queries..................................................................70
How to enter and execute a query..................................................................................70
How to handle syntax errors..........................................................................................72
How to open and save queries........................................................................................74
An introduction to the Query Designer..........................................................................76
How to view the documentation for SQL Server............................78
How to display the MSDN website................................................................................78
How to look up information on the MSDN website......................................................78

Section 2 The essential SQL skills


Chapter 3 How to retrieve data from a single table
An introduction to the SELECT statement......................................86
The basic syntax of the SELECT statement...................................................................86
SELECT statement examples.........................................................................................88
How to code the SELECT clause......................................................90
How to code column specifications................................................................................90
How to name the columns in a result set........................................................................92
How to code string expressions......................................................................................94
How to code arithmetic expressions...............................................................................96
How to use functions......................................................................................................98
How to use the DISTINCT keyword to eliminate duplicate rows...............................100
How to use the TOP clause to return a subset of selected rows...................................102
How to code the WHERE clause....................................................104
How to use comparison operators................................................................................104
How to use the AND, OR, and NOT logical operators................................................106
How to use the IN operator..........................................................................................108
How to use the BETWEEN operator...........................................................................110
How to use the LIKE operator.....................................................................................112
How to use the IS NULL clause..................................................................................114
How to code the ORDER BY clause............................................... 116
How to sort a result set by a column name..................................................................116
How to sort a result set by an alias, an expression, or a column number.....................118
How to retrieve a range of selected rows.....................................................................120

Chapter 4 How to retrieve data from two or more tables


How to work with inner joins.......................................................... 126
How to code an inner join............................................................................................126
When and how to use correlation names......................................................................128
How to work with tables from different databases.......................................................130
How to use compound join conditions.........................................................................132
How to use a self-join..................................................................................................134
Inner joins that join more than two tables....................................................................136
How to use the implicit inner join syntax....................................................................138
Expanded contents vii

How to work with outer joins.......................................................... 140


How to code an outer join............................................................................................140
Outer join examples.....................................................................................................142
Outer joins that join more than two tables...................................................................144
Other skills for working with joins................................................. 146
How to combine inner and outer joins.........................................................................146
How to use cross joins..................................................................................................148
How to work with unions................................................................. 150
The syntax of a union...................................................................................................150
Unions that combine data from different tables...........................................................150
Unions that combine data from the same table............................................................152
How to use the EXCEPT and INTERSECT operators................................................154

Chapter 5 How to code summary queries


How to work with aggregate functions..........................................160
How to code aggregate functions.................................................................................160
Queries that use aggregate functions............................................................................162
How to group and summarize data................................................164
How to code the GROUP BY and HAVING clauses...................................................164
Queries that use the GROUP BY and HAVING clauses..............................................166
How the HAVING clause compares to the WHERE clause.........................................168
How to code complex search conditions......................................................................170
How to summarize data using SQL Server extensions............... 172
How to use the ROLLUP operator...............................................................................172
How to use the CUBE operator....................................................................................174
How to use the GROUPING SETS operator................................................................176
How to use the OVER clause.......................................................................................178

Chapter 6 How to code subqueries


An introduction to subqueries.......................................................184
How to use subqueries.................................................................................................184
How subqueries compare to joins................................................................................186
How to code subqueries in search conditions............................. 188
How to use subqueries with the IN operator................................................................188
How to compare the result of a subquery with an expression......................................190
How to use the ALL keyword......................................................................................192
How to use the ANY and SOME keywords.................................................................194
How to code correlated subqueries..............................................................................196
How to use the EXISTS operator.................................................................................198
Other ways to use subqueries........................................................200
How to code subqueries in the FROM clause..............................................................200
How to code subqueries in the SELECT clause...........................................................202
Guidelines for working with complex queries..............................204
A complex query that uses subqueries.........................................................................204
A procedure for building complex queries...................................................................206
How to work with common table expressions..............................208
How to code a CTE......................................................................................................208
How to code a recursive CTE.......................................................................................210
viii Expanded contents

Chapter 7 How to insert, update, and delete data


How to create test tables................................................................ 216
How to use the SELECT INTO statement...................................................................216
How to use a copy of the database...............................................................................216
How to insert new rows................................................................... 218
How to insert a single row............................................................................................218
How to insert multiple rows.........................................................................................218
How to insert default values and null values................................................................220
How to insert rows selected from another table...........................................................222
How to modify existing rows..........................................................224
How to perform a basic update operation....................................................................224
How to use subqueries in an update operation.............................................................226
How to use joins in an update operation......................................................................228
How to delete existing rows............................................................230
How to perform a basic delete operation.....................................................................230
How to use subqueries and joins in a delete operation................................................232
How to merge rows..........................................................................234
How to perform a basic merge operation.....................................................................234
How to code more complex merge operations.............................................................234

Chapter 8 How to work with data types


A review of the SQL data types......................................................240
Data type overview.......................................................................................................240
The numeric data types................................................................................................242
The string data types....................................................................................................244
The date/time data types...............................................................................................246
The large value data types............................................................................................248
How to convert data.........................................................................250
How data conversion works.........................................................................................250
How to convert data using the CAST function............................................................252
How to convert data using the CONVERT function....................................................254
How to use the TRY_CONVERT function..................................................................256
How to use other data conversion functions................................................................258

Chapter 9 How to work with functions


How to work with string data..........................................................262
A summary of the string functions...............................................................................262
How to solve common problems that occur with string data.......................................266
How to work with numeric data......................................................268
A summary of the numeric functions...........................................................................268
How to solve common problems that occur with numeric data...................................270
How to work with date/time data....................................................272
A summary of the date/time functions.........................................................................272
How to parse dates and times.......................................................................................276
How to perform operations on dates and times............................................................278
How to perform a date search......................................................................................280
How to perform a time search......................................................................................282
Other functions you should know about.......................................284
How to use the CASE function....................................................................................284
How to use the IIF and CHOOSE functions................................................................286
Expanded contents ix

How to use the COALESCE and ISNULL functions..................................................288


How to use the GROUPING function..........................................................................290
How to use the ranking functions.................................................................................292
How to use the analytic functions................................................................................296

Section 3 Database design and implementation


Chapter 10 How to design a database
How to design a data structure......................................................304
The basic steps for designing a data structure..............................................................304
How to identify the data elements................................................................................306
How to subdivide the data elements.............................................................................308
How to identify the tables and assign columns............................................................310
How to identify the primary and foreign keys.............................................................312
How to enforce the relationships between tables.........................................................314
How normalization works............................................................................................316
How to identify the columns to be indexed..................................................................318
How to normalize a data structure.................................................320
The seven normal forms...............................................................................................320
How to apply the first normal form..............................................................................322
How to apply the second normal form.........................................................................324
How to apply the third normal form............................................................................326
When and how to denormalize a data structure...........................................................328

Chapter 11 How to create a database and its tables


with SQL Statements
An introduction to DDL...................................................................334
The SQL statements for data definition.......................................................................334
Rules for coding object names.....................................................................................336
How to create databases, tables, and indexes.............................338
How to create a database..............................................................................................338
How to create a table....................................................................................................340
How to create an index.................................................................................................342
How to use snippets to create database objects............................................................344
How to use constraints...................................................................346
An introduction to constraints......................................................................................346
How to use check constraints.......................................................................................348
How to use foreign key constraints..............................................................................350
How to change databases and tables............................................352
How to delete an index, table, or database...................................................................352
How to alter a table......................................................................................................354
How to work with sequences..........................................................356
How to create a sequence.............................................................................................356
How to use a sequence.................................................................................................356
How to delete a sequence.............................................................................................358
How to alter a sequence...............................................................................................358
The script used to create the AP database...................................360
How the script works....................................................................................................360
How the DDL statements work....................................................................................360
x Expanded contents

Chapter 12 How to create a database and its tables


with the Managment Studio
How to work with a database..........................................................368
How to create a database..............................................................................................368
How to delete a database..............................................................................................368
How to work with tables..................................................................370
How to create, modify, or delete a table.......................................................................370
How to work with foreign key relationships................................................................372
How to work with indexes and keys.............................................................................374
How to work with check constraints............................................................................376
How to examine table dependencies............................................................................378
How to generate scripts..................................................................380
How to generate scripts for databases and tables.........................................................380
How to generate a change script when you modify a table..........................................382

Section 4 Advanced SQL skills


Chapter 13 How to work with views
An introduction to views.................................................................388
How views work...........................................................................................................388
Benefits of using views................................................................................................390
How to create and manage views..................................................392
How to create a view....................................................................................................392
Examples that create views..........................................................................................394
How to create an updatable view.................................................................................396
How to delete or modify a view...................................................................................398
How to use views.............................................................................400
How to update rows through a view.............................................................................400
How to insert rows through a view..............................................................................402
How to delete rows through a view..............................................................................402
How to use the catalog views.......................................................................................404
How to use the View Designer........................................................406
How to create or modify a view...................................................................................406
How to delete a view....................................................................................................406

Chapter 14 How to code scripts


An introduction to scripts............................................................... 410
How to work with scripts.............................................................................................410
The Transact-SQL statements for script processing.....................................................412
How to work with variables and temporary tables....................... 414
How to work with scalar variables...............................................................................414
How to work with table variables.................................................................................416
How to work with temporary tables.............................................................................418
A comparison of the five types of Transact-SQL table objects....................................420
How to control the execution of a script.......................................422
How to perform conditional processing.......................................................................422
How to test for the existence of a database object.......................................................424
How to perform repetitive processing..........................................................................426
How to use a cursor......................................................................................................428
How to handle errors....................................................................................................430
How to use surround-with snippets..............................................................................432
Expanded contents xi

Advanced scripting techniques.....................................................434


How to use the system functions..................................................................................434
How to change the session settings..............................................................................436
How to use dynamic SQL............................................................................................438
A script that summarizes the structure of a database...................................................440
How to use the SQLCMD utility.................................................................................444

Chapter 15 How to code stored procedures, functions,


and triggers
Procedural programming options in Transact-SQL.....................450
Scripts...........................................................................................................................450
Stored procedures, user-defined functions, and triggers..............................................450
How to code stored procedures.....................................................452
An introduction to stored procedures...........................................................................452
How to create a stored procedure.................................................................................454
How to declare and work with parameters...................................................................456
How to call procedures with parameters......................................................................458
How to work with return values...................................................................................460
How to validate data and raise errors...........................................................................462
A stored procedure that manages insert operations......................................................464
How to pass a table as a parameter..............................................................................470
How to delete or change a stored procedure................................................................472
How to work with system stored procedures...............................................................474
How to code user-defined functions.............................................476
An introduction to user-defined functions....................................................................476
How to create a scalar-valued function........................................................................478
How to create a simple table-valued function..............................................................480
How to create a multi-statement table-valued function...............................................482
How to delete or change a function..............................................................................484
How to code triggers.......................................................................486
How to create a trigger.................................................................................................486
How to use AFTER triggers.........................................................................................488
How to use INSTEAD OF triggers..............................................................................490
How to use triggers to enforce data consistency..........................................................492
How to use triggers to work with DDL statements......................................................494
How to delete or change a trigger................................................................................496

Chapter 16 How to manage transactions and locking


How to work with transactions.......................................................502
How transactions maintain data integrity.....................................................................502
SQL statements for handling transactions....................................................................504
How to work with nested transactions.........................................................................506
How to work with save points......................................................................................508
An introduction to concurrency and locking................................ 510
How concurrency and locking are related....................................................................510
The four concurrency problems that locks can prevent...............................................512
How to set the transaction isolation level.....................................................................514
How SQL Server manages locking................................................ 516
Lockable resources and lock escalation.......................................................................516
Lock modes and lock promotion..................................................................................518
Lock mode compatibility.............................................................................................520
xii Expanded contents

How to prevent deadlocks..............................................................522


Two transactions that deadlock....................................................................................522
Coding techniques that prevent deadlocks...................................................................524

Chapter 17 How to manage database security


How to work with SQL Server login IDs........................................528
An introduction to SQL Server security.......................................................................528
How to change the authentication mode......................................................................530
How to create login IDs...............................................................................................532
How to delete or change login IDs or passwords.........................................................534
How to work with database users.................................................................................536
How to work with schemas..........................................................................................538
How to work with permissions.......................................................540
How to grant or revoke object permissions..................................................................540
The SQL Server object permissions.............................................................................542
How to grant or revoke schema permissions................................................................544
How to grant or revoke database permissions..............................................................546
How to grant or revoke server permissions..................................................................548
How to work with roles....................................................................550
How to work with the fixed server roles......................................................................550
How to work with user-defined server roles................................................................552
How to display information about server roles and role members..............................554
How to work with the fixed database roles..................................................................556
How to work with user-defined database roles............................................................558
How to display information about database roles and role members..........................560
How to deny permissions granted by role membership...............................................562
How to work with application roles.............................................................................564
How to manage security using the Management Studio.............566
How to work with login IDs.........................................................................................566
How to work with the server roles for a login ID........................................................568
How to assign database access and roles by login ID..................................................570
How to assign user permissions to database objects....................................................572
How to work with database permissions......................................................................574

Chapter 18 How to work with XML


An introduction to XML...................................................................580
An XML document......................................................................................................580
An XML schema..........................................................................................................582
How to work with the xml data type...............................................584
How to store data in the xml data type.........................................................................584
How to work with the XML Editor..............................................................................586
How to use the methods of the xml data type..............................................................588
An example that parses the xml data type....................................................................592
Another example that parses the xml data type...........................................................594
How to work with XML schemas....................................................596
How to add an XML schema to a database..................................................................596
How to use an XML schema to validate the xml data type..........................................598
How to view an XML schema......................................................................................600
How to drop an XML schema......................................................................................600
Two more skills for working with XML...........................................602
How to use the FOR XML clause of the SELECT statement......................................602
How to use the OPENXML statement.........................................................................606
Expanded contents xiii

Chapter 19 How to work with BLOBs


An introduction to BLOBs............................................................... 612
Pros and cons of storing BLOBs in files......................................................................612
Pros and cons of storing BLOBs in a column..............................................................612
When to use FILESTREAM storage for BLOBs.........................................................612
How to use SQL to work with a varbinary(max) column............. 614
How to create a table with a varbinary(max) column..................................................614
How to insert, update, and delete binary data..............................................................614
How to retrieve binary data..........................................................................................614
A .NET application that uses a varbinary(max) column.............. 616
The user interface for the application...........................................................................616
The event handlers for the form...................................................................................618
A data access class that reads and writes binary data..................................................620
How to use FILESTREAM storage..................................................626
How to enable FILESTREAM storage on the server...................................................626
How to create a database with FILESTREAM storage................................................628
How to create a table with a FILESTREAM column..................................................630
How to insert, update, and delete FILESTREAM data................................................630
How to retrieve FILESTREAM data............................................................................630
A data access class that uses FILESTREAM storage..................................................632

Chapter 20 An introduction to CLR integration


An introduction to CLR integration................................................640
How CLR integration works........................................................................................640
The five types of CLR objects......................................................................................642
When to use CLR objects.............................................................................................642
How to enable CLR integration...................................................................................644
How to use SQL to work with CLR objects...................................646
How to deploy an assembly.........................................................................................646
How to deploy a CLR object........................................................................................646
How to drop an assembly.............................................................................................646

Appendix A How to set up your computer for this book


Three editions of SQL Server 2016 Express................................................................650
The tool for working with all editions of SQL Server.................................................650
How to install SQL Server 2016 Express.....................................................................652
How to install SQL Server Management Studio..........................................................652
How to install the files for this book............................................................................654
How to create the databases for this book....................................................................656
How to restore the databases for this book..................................................................656
How to install Visual Studio Express...........................................................................658

You might also like