10776A ENU Companion
10776A ENU Companion
10776A ENU Companion
10776A
Developing Microsoft ®
SQL Server 2012 ®
Databases
Companion Content
2 Developing Microsoft® SQL Server® 2012 Databases
Information in this document, including URL and other Internet Web site references, is subject to change
without notice. Unless otherwise noted, the example companies, organizations, products, domain names,
e-mail addresses, logos, people, places, and events depicted herein are fictitious, and no association with
any real company, organization, product, domain name, e-mail address, logo, person, place or event is
intended or should be inferred. Complying with all applicable copyright laws is the responsibility of the
user. Without limiting the rights under copyright, no part of this document may be reproduced, stored in
or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical,
photocopying, recording, or otherwise), or for any purpose, without the express written permission of
Microsoft Corporation.
Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property
rights covering subject matter in this document. Except as expressly provided in any written license
agreement from Microsoft, the furnishing of this document does not give you any license to these
patents, trademarks, copyrights, or other intellectual property.
The names of manufacturers, products, or URLs are provided for informational purposes only and
Microsoft makes no representations and warranties, either expressed, implied, or statutory, regarding
these manufacturers or the use of the products with any Microsoft technologies. The inclusion of a
manufacturer or product does not imply endorsement of Microsoft of the manufacturer or product. Links
may be provided to third party sites. Such sites are not under the control of Microsoft and Microsoft is not
responsible for the contents of any linked site or any link contained in a linked site, or any changes or
updates to such sites. Microsoft is not responsible for webcasting or any other form of transmission
received from any linked site. Microsoft is providing these links to you only as a convenience, and the
inclusion of any link does not imply endorsement of Microsoft of the site or the products contained
therein.
© 2012 Microsoft Corporation. All rights reserved.
Microsoft, and Windows are either registered trademarks or trademarks of Microsoft Corporation in the
United States and/or other countries.
All other trademarks are property of their respective owners.
Released: 05/2012
Developing Microsoft® SQL Server® 2012 Databases 3
4 Developing Microsoft® SQL Server® 2012 Databases
Developing Microsoft® SQL Server® 2012 Databases 5
6 Developing Microsoft® SQL Server® 2012 Databases
Developing Microsoft® SQL Server® 2012 Databases 7
Module 1
Introduction to SQL Server® 2012 and its Toolset
Contents:
Lesson 1: Introduction to the SQL Server Platform 8
Lesson 1
Introduction to the SQL Server Platform
Contents:
Question and Answers 9
Developing Microsoft® SQL Server® 2012 Databases 9
Answer: Different database applications might need to meet different service level
agreements, particularly in relation to recovery time objectives (RTO) and recovery point
objectives (RPO).
Answer: Startup companies. (Purchase too many servers and go broke. Purchase too little
and go broke).
Lesson 2
Working with SQL Server Tools
Contents:
Question and Answers 11
10. Note the use of Intellisense while entering it, and then click Execute on the toolbar. Note how the
results can be returned.
11. From the File menu click Save SQLQuery1.sql. Note this saves the query to a file. In the Save File As
window click Cancel.
12. In the Results tab, right-click on the cell for ProductID 1 (first row and first cell) and click Save
Results As…. In the FileName textbox, type Demonstration2AResults and click Save. Note this
saves the query results to a file.
13. From the Query menu, click Display Estimated Execution Plan. Note that SSMS is capable of more
than simply executing queries.
14. From the Tools menu, click Options.
15. In the Options pane, expand Query Results, expand SQL Server, and expand General. Review the
available configuration options and click Cancel.
16. From the File menu, click Close. In the Microsoft SQL Server Management Studio window, click
No.
17. In the File menu, click Open, and click Project/Solution.
18. In the Open Project window, open the project
D:\10776A_Labs\10776A_02_PRJ\10776A_02_PRJ.ssmssln.
19. From the View menu, click Solution Explorer. Note the contents of Solution Explorer. SQL Server
projects have been supplied for each module of the course and contain demonstration steps and
suggested lab solutions, along with any required setup/shutdown code for the module.
20. In the Solution Explorer, click the X to close it.
21. In Object Explorer, from the Connect toolbar icon, note the other SQL Server components that
connections can be made to:
• Database Engine, Analysis Services, Integration Services, Reporting Services
Developing Microsoft® SQL Server® 2012 Databases 13
22. From the File menu, click New, and click Database Engine Query to open a new connection.
23. In the Connect to Database Engine window, type (local) in the Server name text box.
24. In the Authentication drop-down list, select Windows Authentication, and click Connect.
25. In the Available Databases drop-down list, click tempdb database. Note this will change the
database that the query is executed against.
26. Right-click in the query window and click Connection, and click Change Connection… Note: this will
reconnect the query to another instance of SQL Server. In the Connect to Database Engine window,
click Cancel.
27. From the View menu, click Registered Servers.
28. In the Registered Servers window, expand Database Engine, right-click Local Server Groups, and
click New Server Group…
29. In the New Server Group Properties window type Dev Servers in the Group name textbox and
click OK.
30. Right-click Dev Servers and click New Server Registration…
31. In the New Server Registration window, click the Server name drop-down list, type (local) and click
Save.
32. Right-click Dev Servers and click New Server Registration…
33. In the New Server Registration window, click the Server name drop-down list, type .\MKTG and
click Save.
34. In the Registered Servers window, right-click the Dev Servers group and choose New Query.
35. Type the query as shown in the snippet below and click the Execute toolbar icon.
SELECT @@version;
10. Click the name of the function SUBSTRING, then hit the F1 key to open the BOL topic for
SUBSTRING.
11. Note the content of the page and scroll to the bottom to see the examples then close the Microsoft
Help Viewer window.
12. Close SQL Server Management Studio, without saving any changes.
13. If your host system has Internet access available, open Internet Explorer in the host system and
browse to the SQL Server Books Online page: http://go.microsoft.com/fwlink/?LinkID=233780
and note the available online options.
Developing Microsoft® SQL Server® 2012 Databases 15
Lesson 3
Configuring SQL Server Services
Contents:
Question and Answers 16
Answer: Because client applications (including tools and utilities) need to connect to the
server and to other servers.
USE AdventureWorks;
GO
SELECT * FROM Person.Contact ORDER BY FirstName;
GO
11. Switch to SQL Server Profiler. Note the statement trace occurring in SQL Server Profiler then from
the File menu and click Stop Trace.
12. In the Results grid, click individual statements to see the detail shown in the lower pane.
13. Close SQL Server Management Studio and SQL Server Profiler without saving any changes.
18 Developing Microsoft® SQL Server® 2012 Databases
Answer: Versions are releases of the product. Editions are levels of the product with differing
capabilities.
Answer: It adds templates to Visual Studio for constructing and testing business intelligence
projects.
Answer: No, SQL Server installation will install the partner edition of Visual Studio if Visual
Studio is not already present.
Best Practices
1. Ensure that developer edition licenses are not used in production environments.
2. Develop using the least privileges possible, to avoid accidentally building applications that will not
run for standard users.
3. If using an offline version of Books Online, ensure it is kept up to date.
4. Ensure that service accounts are provisioned with the least workable permissions.
Developing Microsoft® SQL Server® 2012 Databases 19
Answer: Reporting Services encrypts sensitive information such as connection details and
this key is needed if the RS databases ever need to be restored on another server.
Answer: SQL Server Configuration Manager network configuration provides the ability to
configure ports for protocols.
20 Developing Microsoft® SQL Server® 2012 Databases
Module 2
Working with Data Types
Contents:
Lesson 1: Using Data Types 21
Lesson 1
Using Data Types
Contents:
Question and Answers 22
Answer: Because the number of bytes needing to be compared is much less. And no
collation or sorting rules need to be considered, as is needed for most string values.
Answer: Because the Gregorian Calendar was introduced by Pope Gregory XIII in 1582.
Unique Identifiers
Question: The slide mentions that a common error is to store GUIDs as strings. What would
be wrong with this?
Lesson 2
Working with Character Data
Contents:
Question and Answers 25
Answer: To minimize the amount of change required to scripts should the sysname data
type ever change in SQL Server.
Understanding Collations
Question: What are the code page and sensitivity values for the collation
SQL_Scandinavian_Cp850_CI_AS?
• In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click
SQL Server Management Studio. In the Connect to Server window, type Proseware in the
Server name text box and click Connect. From the File menu, click Open, click
Project/Solution, navigate to D:\10776A_Labs\10776A_02_PRJ\10776A_02_PRJ.ssmssln and
click Open.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
Lesson 3
Converting Data Types
Contents:
Question and Answers 28
Answer: Where strict formatting of the output is required, particularly if the number is being
concatenated within a string value.
Answer: First SET: @Annual is an integer and is being implicitly converted to a decimal(18,2)
value at the point where it is assigned to @Salary.
Second SET: @Annual is an integer and is being implicitly converted to a decimal(18,2) value
at the point where it is added to the @Salary value.
Third SET: The constant is a string and is being cast to xml at the point that it is being
assigned to @XmlData.
Developing Microsoft® SQL Server® 2012 Databases 29
Lesson 4
Working with Specialized Data Types
Contents:
Detailed Demonstration Step 31
Developing Microsoft® SQL Server® 2012 Databases 31
• In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click
SQL Server Management Studio. In the Connect to Server window, type Proseware in the
Server name text box and click Connect. From the File menu, click Open, click
Project/Solution, navigate to D:\10776A_Labs\10776A_02_PRJ\10776A_02_PRJ.ssmssln and
click Open.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
Question: What are common errors that can occur during data type conversion?
Answer: Many but perhaps truncation, rounding, range errors, inappropriate values
Question: What date is present in a datetime data type if a value is assigned to it that only
contains a time?
Answer: A. 1-1-1900
Best Practices
1. Always choose an appropriate data type for columns and variables rather than using generic data
types such as string or xml except where they are necessary.
2. When defining columns, always specify the nullability rather than leaving it to the system default
settings.
3. Avoid the use of any of the deprecated data types.
4. In the majority of situations, do not store currency values in approximate numeric data types such as
real or float.
5. Use the unicode-based data types where there is any chance of needing to store non-English
characters.
6. Use sysname data type in administrative scripts involving database objects rather than nvarchar(128).
Developing Microsoft® SQL Server® 2012 Databases 33
Answer: Even though it is time related, it's likely you would use an integer here. (Values can
also exceed smallint)
Question: Which of the following columns are likely to be nullable: YTD_Sales, DateOfBirth?
Answer:
A. YTD_Sales would rarely make sense as nullable. Why would you not know the YTD_Sales value? (It
should be zero if no sales)
B. DateOfBirth might be nullable. It is possible to have regulations that might disallow you to store
people's ages.
34 Developing Microsoft® SQL Server® 2012 Databases
Module 3
Designing and Implementing Tables
Contents:
Lesson 1: Designing Tables 35
Lesson 1
Designing Tables
Contents:
Question and Answers 36
Answer: A human can look at the value and has a chance of knowing if it is correct or not.
Question: What might be an appropriate primary key for the Owner table mentioned in the
previous demonstration?
Answer: It is very difficult to come up with anything natural to describe a person, particularly
anything that will not ever change. National ID numbers are useful but are very country-
specific. The aim here is to get the students to realize that there isn't a good answer.
Foreign Keys
Question: What would be an example of multiple foreign keys in a table referencing the
same table?
Answer: A Pet table might have both Owner and Handler columns that both refer to a
Person table or a ResellerSales table might have an OrderDateKey, a DueDateKey, and a
ShipDateKey.
Developing Microsoft® SQL Server® 2012 Databases 37
Lesson 2
Working with Schemas
Contents:
Question and Answers 39
Answer: The table Article would be created in the user's default schema which will not likely
be the KnowledgeBase schema.
40 Developing Microsoft® SQL Server® 2012 Databases
• In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click
SQL Server Management Studio. In the Connect to Server window, type Proseware in the
Server name text box and click Connect. From the File menu, click Open, click
Project/Solution, navigate to D:\10776A_Labs\10776A_03_PRJ\10776A_03_PRJ.ssmssln and
click Open.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
3. Follow the instructions contained within the comments of the script file.
Developing Microsoft® SQL Server® 2012 Databases 41
Lesson 3
Creating and Altering Tables
Contents:
Question and Answers 42
Answer: It would be a poor choice as two owners could easily have the same name.
Dropping Tables
Question: Why would a reference to a table stop it from being dropped?
Answer: References need to be maintained. As an example, you could then end up with
Orders that referred to non-existent Customers.
Answer: To make sure your DDL scripts are reliable in that you don't have the outcome
change depending upon the system settings.
Developing Microsoft® SQL Server® 2012 Databases 43
• In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click
SQL Server Management Studio. In the Connect to Server window, type Proseware in the
Server name text box and click Connect. From the File menu, click Open, click
Project/Solution, navigate to D:\10776A_Labs\10776A_03_PRJ\10776A_03_PRJ.ssmssln and
click Open.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
3. Follow the instructions contained within the comments of the script file.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
3. Follow the instructions contained within the comments of the script file.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
3. Follow the instructions contained within the comments of the script file.
Developing Microsoft® SQL Server® 2012 Databases 45
Answer: A key made up of one or more columns that can uniquely identify a row in the
table. It cannot be NULL.
Answer: A key in one table that references a candidate key (normally a primary key) from
another table.
Best Practices
1. All tables should have primary keys.
2. Foreign keys should be declared within the database in almost all circumstances. Often developers
will suggest that the application will ensure referential integrity. Experience shows that this is a poor
option. Databases are often accessed by multiple applications. Bugs are also easy to miss when they
first start to occur.
46 Developing Microsoft® SQL Server® 2012 Databases
Answer: Yes, they might represent distinct attributes of an object such as a customer. This is
different to the example of Owner1, Owner2. As an example, the addresses might represent
different lines on a form.
Question: How would this differ from fields called PhoneNumber1, PhoneNumber2,
PhoneNumber3?
Answer: While it's not possible to precisely know the answer, it is likely that these really
represent different phone numbers eg: HomeNumber, WorkNumber, etc.
Developing Microsoft® SQL Server® 2012 Databases 47
Module 4
Ensuring Data Integrity through Constraints
Contents:
Lesson 1: Enforcing Data Integrity 48
Lesson 1
Enforcing Data Integrity
Contents:
Question and Answers 49
Developing Microsoft® SQL Server® 2012 Databases 49
Answer: Prompt the students for examples. An example to bring up would be an employee
database where the date of birth cannot be null or in the future (domain integrity) and the
employee id enforces entity integrity (deleting the employee record in one table should
delete references in the other tables).
Answer: Prompt the students to discuss the scenarios in their organizations where data
integrity is currently implemented, or could be implemented.
50 Developing Microsoft® SQL Server® 2012 Databases
Lesson 2
Implementing Domain Integrity
Contents:
Detailed Demonstration Steps 51
Developing Microsoft® SQL Server® 2012 Databases 51
Lesson 3
Implementing Entity and Referential Integrity
Contents:
Question and Answers 53
Answer: Prompt the students to come up with scenarios and how they will affect the tables.
You can suggest an employee retiring, or an employee getting married and changing the
family name as examples.
54 Developing Microsoft® SQL Server® 2012 Databases
• In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click
SQL Server Management Studio. In the Connect to Server window, type Proseware in the
Server name text box and click Connect. From the File menu, click Open, click
Project/Solution, navigate to D:\10776A_Labs\10776A_04_PRJ\10776A_04_PRJ.ssmssln and
click Open.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
2. Open the 31 – Demonstration 3A.sql script file.
3. Follow the instructions contained within the comments of the script file.
• In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click
SQL Server Management Studio. In the Connect to Server window, type Proseware in the
Server name text box and click Connect. From the File menu, click Open, click
Project/Solution, navigate to D:\10776A_Labs\10776A_04_PRJ\10776A_04_PRJ.ssmssln and
click Open.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
2. Open the 32 – Demonstration 3B.sql script file.
3. Follow the instructions contained within the comments of the script file.
Developing Microsoft® SQL Server® 2012 Databases 55
Answer: Even if an application checks that data conforms in the user interface or backend
code, error conditions may arise that cause fields to become corrupt or null. Also, procedures
for archiving, backing up, and triggers may attempt to copy bad data into the table, which
can then cause an application to fail. Multiple applications may be accessing the same data.
Question: What are some scenarios in which you may want to temporarily disable constraint
checking?
Answer: Since constraint checking can impact performance, you might want to disable it
when performing large inserts, such as in a restore procedure or copying large number of
records for an archive. In addition, you may know that duplicate or invalid data exists in your
source or destination and have a plan to deal with cleaning up the data afterwards, such as
with a script or other procedure.
Best Practices
When you create a constraint on a column, if you do not specify a name for the constraint, SQL will
generate a unique name for the constraint. However, you may want to be sure to always name constraints
to adhere to your naming conventions.
56 Developing Microsoft® SQL Server® 2012 Databases
Answer: In Object Explorer, expand the database, right-click Tables, and then choose
Refresh.
Answer: The Default value specifies a default value for the column for new records.
Question: What requirement does a primary key constraint have that a unique constraint
doesn’t?
Module 5
Planning for SQL Server® 2012 Indexing
Contents:
Lesson 1: Core Indexing Concepts 58
Lesson 1
Core Indexing Concepts
Contents:
Question and Answers 59
Answer: An example would be when all the data in a table needs to be accessed in no
particular order.
Answer: Author name (and potentially multiple authors), book name, category, ISBN, release
date and many more.
Index Fragmentation
Question: Why does fragmentation affect performance?
Answer: If pages are only half full, twice as many pages need to be read to access the same
amount of data.
Answer: Concerns about external fragmentation are largely based on the assumption that
accessing adjacent data is faster than accessing data elsewhere on a drive. SSDs start to
challenge this assumption.
60 Developing Microsoft® SQL Server® 2012 Databases
Lesson 2
Data Types and Indexes
Contents:
Question and Answers 62
62 Developing Microsoft® SQL Server® 2012 Databases
Answer: Comparisons work fastest when the processor architecture is at least as big as the
data type. For example, 32 bit values compare quickly on 32 bit systems but 64 bit values
comparisons are much more work for 32 bit systems. Most SQL Server installations today
should be 64 bit.
Answer: Create a calculated column that holds the number if the column is numeric but
NULL otherwise. Then index the computed column.
Developing Microsoft® SQL Server® 2012 Databases 63
Lesson 3
Single Column and Composite Indexes
Contents:
Question and Answers 64
Answer: Selectivity is important and the two columns might differ greatly in terms of
selectivity. Usually, you want the most selective column first when designing an index in the
absence of any other criteria. Once you understand the pattern of your data (the number of
orders per customer is high or low) and the query you need to satisfy, you can start to decide
on an appropriate indexing strategy.
Index Statistics
Question: Before starting to perform your lookup in a physical library, how would you know
which way was quicker?
Answer: You would need to know how many books there were for each author and also
need to know what percentage of the author list you are traversing.
• In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click
SQL Server Management Studio. In the Connect to Server window, type Proseware in the
Server name text box and click Connect. From the File menu, click Open, click
Project/Solution, navigate to D:\10776A_Labs\10776A_05_PRJ\10776A_05_PRJ.ssmssln and
click Open.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
3. Follow the instructions contained within the comments of the script file.
66 Developing Microsoft® SQL Server® 2012 Databases
Best Practices
1. Design indexes to maximize sensitivity which leads to lower I/O.
2. In absence of other requirements, aim to have the most selective columns first in composite indexes.
Developing Microsoft® SQL Server® 2012 Databases 67
Question: If you have an equality predicate and a LIKE predicate in your most important
query, which predicate would you try to satisfy as the first column of a composite index?
Module 6
Implementing Table Structures in SQL Server® 2012
Contents:
Lesson 1: SQL Server Table Structures 69
Lesson 1
SQL Server Table Structures
Contents:
Question and Answers 70
Answer: The row might now be larger and there might be insufficient space on the existing
page.
Operations on Heaps
Question: What would be involved in finding a book in a library structured as a heap? (This
would simulate a SELECT operation).
Answer: You would have to scan all the books in the library. Note that queries don't only
return the first row that matches unless you specify that. They return all matching rows. So
even once you've found a matching book, you would keep scanning the whole library.
2. In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click SQL
Server Management Studio. In the Connect to Server window, type Proseware in the Server
name text box and click Connect. From the File menu, click Open, click Project/Solution, navigate
to D:\10776A_Labs\10776A_06_PRJ\10776A_06_PRJ.ssmssln and click Open.
3. From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file from
within Solution Explorer.
5. Follow the instructions contained within the comments of the script file.
72 Developing Microsoft® SQL Server® 2012 Databases
Lesson 2
Working with Clustered Indexes
Contents:
Question and Answers 73
Answer: A uniqueifier
Answer: Reading the whole table would now need twice as many pages to be read. I/O is
typically the biggest bottleneck in SQL Server systems today so this might be very counter-
productive.
Answer: It was quick to find the row to update because of the index.
74 Developing Microsoft® SQL Server® 2012 Databases
• In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click
SQL Server Management Studio. In the Connect to Server window, type Proseware in the
Server name text box and click Connect. From the File menu, click Open, click
Project/Solution, navigate to D:\10776A_Labs\10776A_06_PRJ\10776A_06_PRJ.ssmssln and
click Open.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
3. Follow the instructions contained within the comments of the script file.
Developing Microsoft® SQL Server® 2012 Databases 75
Lesson 3
Designing Effective Clustered Indexes
Contents:
Question and Answers 76
76 Developing Microsoft® SQL Server® 2012 Databases
Answer: Because the values are normally generated by other application tiers.
Developing Microsoft® SQL Server® 2012 Databases 77
Question: Where are newly inserted rows placed when a table is structured as a heap?
Best Practices
1. Unless specific circumstances arise, most tables should have a clustered index.
2. The clustered index may or may not be placed on the table's primary key.
3. When using GUID primary keys in the logical data model, consider avoiding their use throughout the
physical implementation of the data model.
78 Developing Microsoft® SQL Server® 2012 Databases
Answer: When significant insert operations are expected in the order of the key.
Question: Which table structure is automatically assigned when a table is assigned a primary
key during the table creation, without specifying a structure?
Module 7
Reading SQL Server® 2012 Execution Plans
Contents:
Lesson 1: Execution Plan Core Concepts 80
Lesson 1
Execution Plan Core Concepts
Contents:
Question and Answers 81
Answer: You can double-click (or right-click and Open) a .sqlplan file and it will
automatically open up in SSMS.
Answer: The query optimizer works out how to execute the query. Logically, these two
queries are identical so they should have the same plan.
82 Developing Microsoft® SQL Server® 2012 Databases
2. In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click SQL
Server Management Studio. In the Connect to Server window, type Proseware in the Server
name text box and click Connect. From the File menu, click Open, click Project/Solution, navigate
to D:\10776A_Labs\10776A_07_PRJ\10776A_07_PRJ.ssmssln and click Open.
3. From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file from
within Solution Explorer.
5. Follow the instructions contained within the comments of the script file.
Developing Microsoft® SQL Server® 2012 Databases 83
Lesson 2
Common Execution Plan Elements
Contents:
Question and Answers 84
Answer: The number of rows, the data type, the collation (if string data) and the length of
the data.
Data Modification
Question: Can you think of an example where an INSERT statement in T-SQL need to
perform more than an INSERT operation in an execution plan?
• In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click
SQL Server Management Studio. In the Connect to Server window, type Proseware in the
Server name text box and click Connect. From the File menu, click Open, click
Project/Solution, navigate to D:\10776A_Labs\10776A_07_PRJ\10776A_07_PRJ.ssmssln and
click Open.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
3. Follow the instructions contained within the comments of the script file.
86 Developing Microsoft® SQL Server® 2012 Databases
Lesson 3
Working with Execution Plans
Contents:
Question and Answers 87
• In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click
SQL Server Management Studio. In the Connect to Server window, type Proseware in the
Server name text box and click Connect. From the File menu, click Open, click
Project/Solution, navigate to D:\10776A_Labs\10776A_07_PRJ\10776A_07_PRJ.ssmssln and
click Open.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
3. Follow the instructions contained within the comments of the script file.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
3. Follow the instructions contained within the comments of the script file.
Developing Microsoft® SQL Server® 2012 Databases 89
Answer: A graphical plan is a rendering of an XML plan that contains the most important
information in an easy to read format.
Question: Give an example of why a T-SQL DELETE statement could have a complex
execution plan?
Answer: There might be referential integrity checks to be done (ie: foreign keys)
Best Practices
1. Avoid capturing execution plans for large numbers of statements when using SQL Profiler.
2. If you need to capture plans using Profiler, make sure the trace is filtered to reduce the number of
events being captured.
90 Developing Microsoft® SQL Server® 2012 Databases
Answer: yes
Module 8
Improving Performance through Nonclustered Indexes
Contents:
Lesson 1: Designing Effective Nonclustered Indexes 92
Lesson 1
Designing Effective Nonclustered Indexes
Contents:
Question and Answers 93
Answer: Finding a data row is quick once the index has been accessed.
Question: What is the downside of having multiple indexes pointing to data pages via
RowID?
Answer: The data row might need to move to another location during update activity.
Question: What is the upside of holding clustering keys in the leaf nodes of a nonclustered
index instead of RowIDs?
Answer: Nonclustered indexes do not need to be modified when rows move within the
clustered index. Row movement could relate to data changes or index rebuild/reorganize
operations.
Lesson 2
Implementing Nonclustered Indexes
Contents:
Question and Answers 96
Answer: Students will often suggest numbers like 10% but the reality is that it is more likely
to be a value like 1/3 of one percent.
Question: Is there any situation where there is no need for the lookups?
Answer: Yes, when the index entry already contains all the necessary data.
INCLUDE Clause
Question: For an index to cover a single table query, which columns would need to be
present in the index?
Filtered Indexes
Question: What is the downside of having an entry at the leaf level for every transaction
row, whether finalized or not?
Answer: Maintenance operations are much more complex and long running.
• In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click
SQL Server Management Studio. In the Connect to Server window, type Proseware in the
Server name text box and click Connect. From the File menu, click Open, click
Project/Solution, navigate to D:\10776A_Labs\10776A_08_PRJ\10776A_08_PRJ.ssmssln and
click Open.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
2. Open the 21 – Demonstration 2A.sql script file.
3. Follow the instructions contained within the comments of the script file.
98 Developing Microsoft® SQL Server® 2012 Databases
Lesson 3
Tracing and Tuning Queries
Contents:
Question and Answers 99
Answer: In load testing and when testing queries against upgraded versions of SQL Server.
Answer: Because the statements in the loop were all part of the same batch.
Answer: Because a single query might not be executed very often and have little impact on
the overall server load. Also, changes to improve the performance of one query might
impact the performance of other queries adversely.
Answer: No, each recommendation should be reviewed first. For example, when DETA
suggests new statistics, often this is an indication of missing or inappropriate indexes.
100 Developing Microsoft® SQL Server® 2012 Databases
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
2. Open the 32 – Demonstration 3B.sql script file.
3. Follow the instructions contained within the comments of the script file.
Developing Microsoft® SQL Server® 2012 Databases 101
Answer: An index that provides all columns needed by SQL Server when executing a query
without the need to perform lookups to the base table.
Answer: A clustered index contains all columns at the leaf level of its index so, by definition,
it covers any query on the table. However, the INCLUDE clause only makes sense for
nonclustered indexes and a targeted covering nonclustered index can almost always be
designed to outperform the clustered index on a given query. Consideration needs to be
given, however, to the performance impacts of maintaining nonclustered indexes.
Best Practices
1. Never apply Database Engine Tuning Advisor recommendations without further reviewing what is
being suggested.
2. Record details of why and when you create any indexes. DBAs are hesitant to ever remove indexes
without this knowledge.
3. When DETA suggests new statistics, this should be taken as a hint to investigate the indexing
structure of the table.
102 Developing Microsoft® SQL Server® 2012 Databases
Answer: The leaf level of a nonclustered index always includes the clustering key anyway.
Question: If so, why? If not, why not and should you include it anyway?
Answer: You should include it anyway in case the clustering key ever gets changed. There is
no downside to including it as SQL Server will not store it twice within the leaf pages of the
index.
Developing Microsoft® SQL Server® 2012 Databases 103
Module 9
Designing and Implementing Views
Contents:
Lesson 1: Introduction to Views 104
Lesson 1
Introduction to Views
Contents:
Question and Answers 105
Answer: Users may not be permitted to view the data in all the columns.
Types of Views
Question: What advantages would you assume that views would provide?
Advantages of Views
Question: If tables can be replaced by views (and vice-versa) during maintenance, what does
that suggest to you about the naming of views and tables?
Answer: Tables and views should be named based on their contents, not on how they are
implemented. Prefixes are a problem with this. You don’t want to end up with views named
tblSomething or tables named vSomething.
Answer: Answers will vary based on experience and backgrounds of the students. Examples
would be the fragmentation level of indexes or details of recent expensive query executions.
Lesson 2
Creating and Managing Views
Contents:
Question and Answers 108
Answer: It is needed to implement the selection logic for the TOP clause.
Answer: Most students should see that it is not usually worth the effort as it does not
achieve the desired outcome anyway and it complicates work on the system.
• In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click
SQL Server Management Studio. In the Connect to Server window, type Proseware and click
Connect. From the File menu, click Open, click Project/Solution, navigate to
D:\10776A_Labs\10776A_09_PRJ\10776A_09_PRJ.ssmssln and click Open.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
3. Follow the instructions contained within the comments of the script file.
110 Developing Microsoft® SQL Server® 2012 Databases
Lesson 3
Performance Considerations for Views
Contents:
Question and Answers 111
Answer: LEFT OUTER JOINS where no columns from the joined table are used.
• In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click
SQL Server Management Studio. In the Connect to Server window, type Proseware and click
Connect. From the File menu, click Open, click Project/Solution, navigate to
D:\10776A_Labs\10776A_09_PRJ\10776A_09_PRJ.ssmssln and click Open.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
3. Follow the instructions contained within the comments of the script file.
• In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click
SQL Server Management Studio. In the Connect to Server window, type Proseware in the
Server name text box and click Connect. From the File menu, click Open, click
Project/Solution, navigate to D:\10776A_Labs\10776A_06_PRJ\10776A_06_PRJ.ssmssln and
click Open.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
3. Follow the instructions contained within the comments of the script file.
Developing Microsoft® SQL Server® 2012 Databases 113
Answer: Standard views combine data from one or more base tables (or views) into a new
virtual table, and is materialized at run time.
Answer: When the same user owns the source object, the view, stored procedure, or user-
defined function, and all target objects (underlying tables, views, or other objects), the
ownership chain is said to be unbroken.
Best Practices
1. Use views to focus data for users.
2. Avoid nesting many layers within views.
3. Avoid ownership chain problems within views.
4. Ensure consistent connection SET options when intending to index views.
114 Developing Microsoft® SQL Server® 2012 Databases
Answer: If the view is updatable, only data from a single table can be updated in any
UPDATE statement.
Question: What is required for columns in views that are created from expressions?
Module 10
Designing and Implementing Stored Procedures
Contents:
Lesson 1: Introduction to Stored Procedures 116
Lesson 1
Introduction to Stored Procedures
Contents:
Question and Answers 117
Answer: It can help avoid round trips to the server to obtain additional data. For example, an
order header and all the detail lines could be returned in a single call.
Answer: Tables might need to reference each other. Delayed name binding does not work
for tables.
Lesson 2
Working with Stored Procedures
Contents:
Question and Answers 120
Answer: Significant intellectual property might be contained within the definition of the
stored procedure.
Answer: By adding a parameter and making it work for any selected color.
Developing Microsoft® SQL Server® 2012 Databases 121
• In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click
SQL Server Management Studio. In the Connect to Server window, type Proseware in the
Server name text box and click Connect. From the File menu, click Open, click
Project/Solution, navigate to D:\10776A_Labs\10776A_10_PRJ\10776A_10_PRJ.ssmssln and
click Open.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
2. Open the 21 – Demonstration 2A.sql script file.
3. Follow the instructions contained within the comments of the script file.
122 Developing Microsoft® SQL Server® 2012 Databases
Lesson 3
Implementing Parameterized Stored Procedures
Contents:
Question and Answers 123
Answer: You would assign a value that it typical of the values supplied in most executions.
• In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click
SQL Server Management Studio. In the Connect to Server window, type Proseware in the
Server name text box and click Connect. From the File menu, click Open, click
Project/Solution, navigate to D:\10776A_Labs\10776A_10_PRJ\10776A_10_PRJ.ssmssln and
click Open.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
2. Open the 31 – Demonstration 3A.sql script file.
3. Follow the instructions contained within the comments of the script file.
Developing Microsoft® SQL Server® 2012 Databases 125
Lesson 4
Controlling Execution Context
Contents:
Question and Answers 126
Answer: One principal that vouches for the identity of another principal.
Developing Microsoft® SQL Server® 2012 Databases 127
• In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click
SQL Server Management Studio. In the Connect to Server window, type Proseware in the
Server name text box and click Connect. From the File menu, click Open, click
Project/Solution, navigate to D:\10776A_Labs\10776A_10_PRJ\10776A_10_PRJ.ssmssln and
click Open.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
2. Open the 41 – Demonstration 4A.sql script file.
3. Follow the instructions contained within the comments of the script file.
128 Developing Microsoft® SQL Server® 2012 Databases
Answer: It causes a new execution plan to be generated every time the procedure is executed.
Question: What does the WITH RECOMPILE option do when used with an EXECUTE statement?
Answer: It causes a new execution plan to be generated for this particular execution of the procedure
and for the plan to be discarded after execution.
Best Practices
1. Use the EXECUTE AS clause to override the execution context of stored procedures that use dynamic
SQL, rather than granting permissions on the underlying tables to users.
2. Design procedures to perform individual tasks. Avoid designing procedures that perform a large
number of tasks, unless those tasks are performed by executing other stored procedures.
3. Keep consistent ownership of stored procedures, views, tables and other objects within databases.
Developing Microsoft® SQL Server® 2012 Databases 129
Answer: Both when declaring the parameters in the stored procedure and when calling the
stored procedure in the EXEC statement.
Answer: All tokens associated with the login, including the login itself and server role
membership
130 Developing Microsoft® SQL Server® 2012 Databases
Module 11
Merging Data and Passing Tables
Contents:
Lesson 1: Using the MERGE Statement 131
Lesson 1
Using the MERGE Statement
Contents:
Question and Answers 132
2. In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click SQL
Server Management Studio. In the Connect to Server window, type Proseware in the Server
name text box and click Connect. From the File menu, click Open, click Project/Solution, navigate
to D:\10776A_Labs\10776A_11_PRJ\10776A_11_PRJ.ssmssln and click Open.
3. From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file from
within Solution Explorer.
5. Follow the instructions contained within the comments of the script file.
134 Developing Microsoft® SQL Server® 2012 Databases
Lesson 2
Implementing TABLE Types
Contents:
Question and Answers 135
Answer: By sending more than one piece of information in each call to the server.
Answer: Difficulties with passing and parsing multiple columns and with checking data
types.
• In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click
SQL Server Management Studio. In the Connect to Server window, type Proseware in the
Server name text box and click Connect. From the File menu, click Open, click
Project/Solution, navigate to D:\10776A_Labs\10776A_11_PRJ\10776A_11_PRJ.ssmssln and
click Open.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
3. Follow the instructions contained within the comments of the script file.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
3. Follow the instructions contained within the comments of the script file.
Developing Microsoft® SQL Server® 2012 Databases 137
Lesson 3
Using TABLE Types As Parameters
Contents:
Question and Answers 138
Answer: You'd need a table-valued parameter for the sales headers and another for the sales
details. the sales details would also have to include a column for the sales number.
Answer: It returns the last IDENTITY value that has been allocated in the same scope.
Developing Microsoft® SQL Server® 2012 Databases 139
• In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click
SQL Server Management Studio. In the Connect to Server window, type Proseware in the
Server name text box and click Connect. From the File menu, click Open, click
Project/Solution, navigate to D:\10776A_Labs\10776A_11_PRJ\10776A_11_PRJ.ssmssln and
click Open.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
3. Follow the instructions contained within the comments of the script file.
140 Developing Microsoft® SQL Server® 2012 Databases
Answer: The source is the input table, the target is the table being modified.
Best Practices
1. Use multi-row inserts when the rows being inserted are related in some way, for example, the detail
rows of an invoice.
Answer: Allows returning relevant rows of data as a side-effect of a statement that modifies
data in the database
Question: In the values returned by an OUTPUT clause, how can we tell if an INSERT,
UPDATE or DELETE occurred?
Module 12
Designing and Implementing User-Defined Functions
Contents:
Lesson 1: Overview of Functions 143
Lesson 1
Overview of Functions
Contents:
Question and Answers 144
144 Developing Microsoft® SQL Server® 2012 Databases
System Functions
Question: Have you used any of the functions apart from data type and date time when
writing code?
Lesson 2
Designing and Implementing Scalar Functions
Contents:
Detailed Demonstration Steps 146
146 Developing Microsoft® SQL Server® 2012 Databases
Lesson 3
Designing and Implementing Table-valued Functions
Contents:
Question and Answers 148
Answer: Because it also includes TOP. The ORDER BY is used only for selection of rows, not
for ordering the output.
Answer: Where you need to use complex logic that cannot be expressed in a single SELECT
statement, such as iterating through counters.
• In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click
SQL Server Management Studio. In the Connect to Server window, type Proseware in the
Server name text box and click Connect. From the File menu, click Open, click
Project/Solution, navigate to D:\10776A_Labs\10776A_12_PRJ\10776A_12_PRJ.ssmssln and
click Open.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
3. Follow the instructions contained within the comments of the script file.
150 Developing Microsoft® SQL Server® 2012 Databases
Lesson 4
Considerations for Implementing Functions
Contents:
Detailed Demonstration Steps 151
Developing Microsoft® SQL Server® 2012 Databases 151
• In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click
SQL Server Management Studio. In the Connect to Server window, type Proseware in the
Server name text box and click Connect. From the File menu, click Open, click
Project/Solution, navigate to D:\10776A_Labs\10776A_12_PRJ\10776A_12_PRJ.ssmssln and
click Open.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
3. Follow the instructions contained within the comments of the script file.
152 Developing Microsoft® SQL Server® 2012 Databases
Answer: For the login or user being impersonated, specify a login or user that has the least privileges
required to perform the operations required.
in the session. For example, do not specify a login name with server-level permissions, if only
database-level permissions are required; or do not specify a database owner account unless those
permissions are required.
Question: When using the EXECUTE AS clause, what privileges should the login or user creating the
code have?
Best Practices
1. Avoid calling multi-statement TVFs for each row of a query. In many cases, you can dramatically
improve performance by extracting the code from the query into the surrounding query.
2. Use the WITH EXECUTE AS clause to override the security context of code that needs to perform
actions that the user that is executing the code, does not have.
Developing Microsoft® SQL Server® 2012 Databases 153
Answer: You could create a function that takes one input parameter, a customer (store) ID,
and returns the columns ProductID, Name, and the aggregate of year-to-date sales as YTD
Total for each product sold to the store.
Question: What is the biggest concern about the use of scalar functions?
Module 13
Creating Highly Concurrent SQL Server® 2012 Applications
Contents:
Lesson 1: Introduction to Transactions 155
Lesson 1
Introduction to Transactions
Contents:
Question and Answers 156
Answer: Answers will vary, but any place where integrity of the data is mission critical.
Answer: Answers can vary; discuss applications that might require a great deal of control
over transactions.
Explicit Transactions
Question: When might you want to use a savepoint?
Answer: A savepoint can be useful in a long transaction with several components. Instead of
rolling back the entire transaction, it may make more sense to roll back only certain portions
of a transaction by using a savepoint.
Implicit Transactions
Question: Can you think of an application in your organization where implicit transactions
might be appropriate?
Transaction Recovery
Question: A server crash occurs while two transactions are running. Transaction A is an
autocommit transaction that has been written to the transaction log, but not written to the
disk. Transaction B is an explicit transaction that has not been committed, though a
checkpoint was written while Transaction B was running. What will happen to each
transaction when the server is recovered?
Answer: Transaction A will be rolled forward because it already appears in the transaction
log. Transaction B will be rolled back because it was not explicitly committed, but it will only
be rolled back to the checkpoint.
2. In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click SQL
Server Management Studio. In the Connect to Server window, type Proseware in the Server
name text box and click Connect. From the File menu, click Open, click Project/Solution, navigate
to D:\10776A_Labs\10776A_13_PRJ\10776A_13_PRJ.ssmssln and click Open.
3. From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file from
within Solution Explorer.
6. Follow the instructions contained within the comments of the script files.
158 Developing Microsoft® SQL Server® 2012 Databases
Lesson 2
Introduction to Locks
Contents:
Question and Answers 159
Developing Microsoft® SQL Server® 2012 Databases 159
Answer: There could be a variety of ways locks are used, but a common use for locks would
be to ensure that two simultaneous updates to patient records could not occur; one update
would have to occur before the other.
Lockable Resources
Question: If a database needs to lock several rows of data at once, what resources might be
locked?
Answer: For locking several rows at once, there are different possibilities, but the most likely
resources to be locked are Pages and Extents.
Types of Locks
Question: What happens if a query tries to read data from a row that is currently locked by
an exclusive (X) lock?
Answer: Even though the lock is exclusive, a SELECT statement will still be able to read data
from the locked row.
Lock Compatibility
Question: Can you think of situations where lock compatibility is important?
Answer: Answers will vary, but any situation in which data might be updated and read from
different sources at the same time should be analyzed for lock compatibility.
160 Developing Microsoft® SQL Server® 2012 Databases
Lesson 3
Management of Locking
Contents:
Question and Answers 161
Answer: Possible situations involve deleting archival rows. If they are locked, it is no problem
and they would be deleted the next time the archive deletion runs.
Lock Escalation
Question: Why do you imagine that SQL Server might find escalating locks worthwhile?
Answer: Taking and releasing large numbers of locks is time-consuming. Sometimes it's
better to just get the work done.
Answer: When you know you are the only process accessing the table and that locking
overhead would slow your operation down.
162 Developing Microsoft® SQL Server® 2012 Databases
• In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click
SQL Server Management Studio. In the Connect to Server window, type Proseware in the
Server name text box and click Connect. From the File menu, click Open, click
Project/Solution, navigate to D:\10776A_Labs\10776A_13_PRJ\10776A_13_PRJ.ssmssln and
click Open.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
5. Follow the instructions contained within the comments of the script files.
Developing Microsoft® SQL Server® 2012 Databases 163
Answer: The most common benefit is minimizing the number of times that readers block writers.
Question: What is the difference between a shared lock and an exclusive lock?
Answer: Multiple processes can hold a shared lock on the same resource.
Question: Why would you use read committed snapshot rather than snapshot isolation level?
Best Practices
1. Always use the lowest transaction isolation level possible to avoid blocking and to avoid the chance of
deadlocks.
2. Many Microsoft-supplied components default to Serializable transactional isolation level but do not
need to be run at that level. Common examples are Component Services and BizTalk adapters.
3. Before spending too much time investigating blocking issues, make sure that all the queries that are
involved are executing quickly. This usually involves making sure that appropriate indexes are in
place. Often when query performance issues are resolved, blocking issues disappear.
164 Developing Microsoft® SQL Server® 2012 Databases
Module 14
Handling Errors in T-SQL Code
Contents:
Lesson 1: Understanding T-SQL Error Handling 166
Lesson 1
Understanding T-SQL Error Handling
Contents:
Question and Answers 167
Answer: The errors returned by the database engine are often too cryptic for end users to
understand.
What's in an Error?
Question: Why is it useful to be able to localize error messages?
Answer: Because users that speak different languages might need to run the same
application. Localization allows the users to see versions of the error messages in their own
languages.
2. In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click SQL
Server Management Studio. In the Connect to Server window, type Proseware in the Server
name text box and click Connect. From the File menu, click Open, click Project/Solution, navigate
to D:\10776A_Labs\10776A_14_PRJ\10776A_14_PRJ.ssmssln and click Open.
3. From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file from
within Solution Explorer.
5. Follow the instructions contained within the comments of the script file.
Developing Microsoft® SQL Server® 2012 Databases 169
Lesson 2
Implementing T-SQL Error Handling
Contents:
Question and Answers 170
Answer: Because you often need to know which object the error applies to.
Developing Microsoft® SQL Server® 2012 Databases 171
• In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click
SQL Server Management Studio. In the Connect to Server window, type Proseware in the
Server name text box and click Connect. From the File menu, click Open, click
Project/Solution, navigate to D:\10776A_Labs\10776A_14_PRJ\10776A_14_PRJ.ssmssln and
click Open.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
Lesson 3
Implementing Structured Exception Handling
Contents:
Question and Answers 173
• In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click
SQL Server Management Studio. In the Connect to Server window, type Proseware in the
Server name text box and click Connect. From the File menu, click Open, click
Project/Solution, navigate to D:\10776A_Labs\10776A_14_PRJ\10776A_14_PRJ.ssmssln and
click Open.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
Answer: Because it is desirable to stop the end user from seeing these errors if they can be handled
in code.
Question: Give an example of an error that retries would not be useful for.
Best Practices
When designing client-side database access code, do not assume that database operations will always
occur without error. Instead of a pattern like:
• Start a transaction
• Do some work
• Commit the transaction
• While the transaction is not committed and the retry count is not exhausted, attempt to perform the
work and commit the transaction.
• If an error occurs and it is an error that retries could apply to, retry. Otherwise, return the error to the
calling code.
176 Developing Microsoft® SQL Server® 2012 Databases
Answer: Because we need to rollback the transaction only if there is one that is doomed.
Question: Why do we insert a delay within the retry logic for a deadlock?
Answer: To give the situation that caused the deadlock time to clear.
Developing Microsoft® SQL Server® 2012 Databases 177
Module 15
Responding to Data Manipulation via Triggers
Contents:
Lesson 1: Designing DML Triggers 178
Lesson 1
Designing DML Triggers
Contents:
Question and Answers 179
Developing Microsoft® SQL Server® 2012 Databases 179
Answer: Triggers allow for more complex logic than is possible in the definition of a
constraint.
Answer: INSERT, UPDATE and DELETE statements only permit modifications to a single table
in a single statement.
180 Developing Microsoft® SQL Server® 2012 Databases
Lesson 2
Implementing DML Triggers
Contents:
Question and Answers 181
Answer: Prompt the students for scenarios. As an example, you may suggest a trigger that
checks to make sure the credit rating for the vendor is good when an attempt is made to
insert a new purchase order into the PurchaseOrderHeader table. To obtain the credit rating
of the vendor corresponding to the purchase order that was just inserted, the Vendor table
must be referenced and joined with the inserted table. If the credit rating is too low, a
message is displayed and the insertion does not execute.
Answer: Is it often better for performance and archival to simply mark records as inactive by
using a column reserved for that purpose. You can use an instead of trigger to mark records
as inactive when a delete statement is executed. You can then schedule regular archival to
remove those records when necessary. This also makes it easier for applications to undo
accidental deletions and ensures that business rules which require archival of information are
easily upheld. In addition, you can enforce primary key uniqueness when uniqueness also
applies to archived records (for example, instead of creating a duplicate record to what is in
the archive when rehiring a vendor, you can simply restore the record to active status.)
2. In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click SQL
Server Management Studio. In the Connect to Server window, type Proseware in the Server
name text box and click Connect. From the File menu, click Open, click Project/Solution, navigate
to D:\10776A_Labs\10776A_15_PRJ\10776A_15_PRJ.ssmssln and click Open.
3. From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file from
within Solution Explorer.
5. Follow the instructions contained within the comments of the script file.
• In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click
SQL Server Management Studio. In the Connect to Server window, type Proseware in the
Server name text box and click Connect. From the File menu, click Open, click
Project/Solution, navigate to D:\10776A_Labs\10776A_15_PRJ\10776A_15_PRJ.ssmssln and
click Open.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
3. Follow the instructions contained within the comments of the script file.
• In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click
SQL Server Management Studio. In the Connect to Server window, type Proseware in the
Server name text box and click Connect. From the File menu, click Open, click
Project/Solution, navigate to D:\10776A_Labs\10776A_15_PRJ\10776A_15_PRJ.ssmssln and
click Open.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
Developing Microsoft® SQL Server® 2012 Databases 183
3. Follow the instructions contained within the comments of the script file.
184 Developing Microsoft® SQL Server® 2012 Databases
Lesson 3
Advanced Trigger Concepts
Contents:
Question and Answers 185
Answer: Prompt the students for scenarios from their organizations and how they could
implement INSTEAD OF triggers. The most common response is that they would use them to
allow for updatable views. Another option would be that in a view, an aggregate might be
formed from multiple columns. This could allow the underlying columns to be updated.
Answer: Because the row is contained within a single table and only accessed by the
CustomerID
Answer: There are multiple scenarios where multiple tables may be updated using nested
triggers. You might suggest what happens when an employee is hired or promoted and how
that impacts benefits, contact details, payroll, etc.
Answer: A recursive UPDATE trigger can be used to keep the parentID column up-to-date as
new records are inserted. The INSERT trigger ParentID column of the child record, which
recursively updates the parents column of other records down the hierarchy
186 Developing Microsoft® SQL Server® 2012 Databases
• In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click
SQL Server Management Studio. In the Connect to Server window, type Proseware in the
Server name text box and click Connect. From the File menu, click Open, click
Project/Solution, navigate to D:\10776A_Labs\10776A_15_PRJ\10776A_15_PRJ.ssmssln and
click Open.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
3. Follow the instructions contained within the comments of the script file.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
3. Follow the instructions contained within the comments of the script file.
Developing Microsoft® SQL Server® 2012 Databases 187
Answer: Constraints fire before data modification. AFTER triggers fire after the data modification.
Question: Why would you use the UPDATE function rather than the COLUMNS_UPDATED function
when designing a trigger?
Best Practices
1. In many business scenarios, it makes sense to mark records as deleted with a status column and use a
trigger or stored procedure to update an audit trail table. The changes can then be audited, the data
is not lost, and the IT staff can perform purges or archival of the deleted records.
Question: What did you need to specify as well as the trigger’s name when altering it?
Module 16
Implementing Managed Code in SQL Server® 2012
Contents:
Lesson 1: Introduction to SQL CLR Integration 190
Lesson 1
Introduction to SQL CLR Integration
Contents:
Question and Answers 191
Answer: Answers will vary but many will suggest a desire to extend the tools in SQL Server
Management Studio
192 Developing Microsoft® SQL Server® 2012 Databases
2. In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click SQL
Server Management Studio. In the Connect to Server window, type Proseware in the Server
name text box and click Connect. From the File menu, click Open, click Project/Solution, navigate
to D:\10776A_Labs\10776A_16_PRJ\10776A_16_PRJ.ssmssln and click Open.
3. From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file from
within Solution Explorer.
Lesson 2
Importing and Cataloging Assemblies
Contents:
Question and Answers 194
Answer: UNSAFE
Answer: A good example would be the need to access COM-based code. (The SQL Server
Spatial assembly does this). Only in very rare circumstances should this be permitted and
with a very solid justification.
Developing Microsoft® SQL Server® 2012 Databases 195
• In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click
SQL Server Management Studio. In the Connect to Server window, type Proseware in the
Server name text box and click Connect. From the File menu, click Open, click
Project/Solution, navigate to D:\10776A_Labs\10776A_16_PRJ\10776A_16_PRJ.ssmssln and
click Open.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
3. Follow the instructions contained within the comments of the script file.
196 Developing Microsoft® SQL Server® 2012 Databases
Lesson 3
Implementing SQL CLR Integration
Contents:
Question and Answers 197
Answer: It could return a table of environment variable names and their current values.
Answer: Will vary but examples would be external access of the filesystem (listing files in a
folder), reading or writing file data (output an XML file to a folder), retrieve environment
variable values.
User-defined Aggregates
Question: Can you think of another common mathematical aggregate that would be useful
in SQL Server?
• In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click
SQL Server Management Studio. In the Connect to Server window, type Proseware in the
Server name text box and click Connect. From the File menu, click Open, click
Project/Solution, navigate to D:\10776A_Labs\10776A_16_PRJ\10776A_16_PRJ.ssmssln and
click Open.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
• In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click
SQL Server Management Studio. In the Connect to Server window, type Proseware in the
Server name text box and click Connect. From the File menu, click Open, click
Project/Solution, navigate to D:\10776A_Labs\10776A_16_PRJ\10776A_16_PRJ.ssmssln and
click Open.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
3. Follow the instructions contained within the comments of the script file.
• In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click
SQL Server Management Studio. In the Connect to Server window, type Proseware in the
Server name text box and click Connect. From the File menu, click Open, click
Developing Microsoft® SQL Server® 2012 Databases 199
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
3. Follow the instructions contained within the comments of the script file.
200 Developing Microsoft® SQL Server® 2012 Databases
Answer: User-defined functions (scalar and table-valued), stored procedures, triggers (DML and DDL),
user-defined aggregates, user-defined data types.
Best Practices
1. The biggest mistake made when deciding between T-SQL and Managed Code is to assume that either
one is the correct answer for every situation. Each has benefits and limitations and should be used for
the appropriate tasks.
2. Developers should avoid implementing using SQL CLR to implement code that would be better
placed on another application tier (such as on a client system).
3. DBAs should avoid refusing to allow SQL CLR code without consideration. As you have seen in this
module, there is code that should be implemented in Managed Code rather than in T-SQL.
Answer: Answers will vary but interesting options would be jpeg data type, chemical data
types, audio data types, etc.
202 Developing Microsoft® SQL Server® 2012 Databases
Module 17
Storing XML Data in SQL Server® 2012
Contents:
Lesson 1: Introduction to XML and XML Schemas 203
Lesson 1
Introduction to XML and XML Schemas
Contents:
Question and Answers 204
Answer: Explain that a key distinction of XML is that it is self-describing. Note that you can
infer most of what the document is about directly from the document itself.
Question: Do you use XML for exchanging data between your organization and another
organization?
Answer: Answers will vary but a good example would be if the organization interchanges
data using BizTalk Server.
XML Namespaces
Question: Why do you imagine that aliases are typically used with namespaces?
Answer: To avoid having to repeat the details of the entire namespace in each element.
Answer: If you were trying to decide what the schema of the document was, you might not
realize that the element even exists, depending upon which rows of data you happen to have
included.
Developing Microsoft® SQL Server® 2012 Databases 205
2. In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click SQL
Server Management Studio. In the Connect to Server window, type Proseware in the Server
name text box and click Connect. From the File menu, click Open, click Project/Solution, navigate
to D:\10776A_Labs\10776A_17_PRJ\10776A_17_PRJ.ssmssln and click Open.
3. From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file from
within Solution Explorer.
5. Follow the instructions contained within the comments of the script file.
206 Developing Microsoft® SQL Server® 2012 Databases
Lesson 2
Storing XML Data and Schemas in SQL Server
Contents:
Question and Answers 207
Answer: A variety of errors can occur but an example would be that elements that you were
expecting to be present might not be present.
Answer: An XML SCHEMA COLLECTION is a set of XML schemas. XML data that is validated
by the XML SCHEMA COLLECTION must meet the requirements of at least one of the XML
schemas contained in the XML SCHEMA COLLECTION.
208 Developing Microsoft® SQL Server® 2012 Databases
• In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click
SQL Server Management Studio. In the Connect to Server window, type Proseware in the
Server name text box and click Connect. From the File menu, click Open, click
Project/Solution, navigate to D:\10776A_Labs\10776A_17_PRJ\10776A_17_PRJ.ssmssln and
click Open.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
3. Follow the instructions contained within the comments of the script file.
Developing Microsoft® SQL Server® 2012 Databases 209
Lesson 3
Implementing XML Indexes
Contents:
Question and Answers 210
Answer: The name of the primary XML index needs to be specified when creating a
secondary XML index.
Developing Microsoft® SQL Server® 2012 Databases 211
• In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click
SQL Server Management Studio. In the Connect to Server window, type Proseware in the
Server name text box and click Connect. From the File menu, click Open, click
Project/Solution, navigate to D:\10776A_Labs\10776A_17_PRJ\10776A_17_PRJ.ssmssln and
click Open.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
3. Follow the instructions contained within the comments of the script file.
212 Developing Microsoft® SQL Server® 2012 Databases
Best Practices
1. Use appropriate data types for your database columns. Do not store all your data in XML columns.
2. Use XML schemas only when required. Validating data against schemas incurs substantial processing
overhead.
3. Ensure you have at least basic XML proficiency when working with SQL Server, even if you will be
working primarily in database administration.
4. Index XML data stored in database columns. Use the appropriate type of index for the types of
queries expected.
Developing Microsoft® SQL Server® 2012 Databases 213
Answer: The purpose of an XML schema is to defined the allowed structure of an XML
document.
Answer: Use untyped XML data type when you do not have a schema for your XML data or
you do not wish the server to validate the data against the schema.
Question: When would you use typed XML?
Answer: Use typed XML data type when you have schemas for your data and you want the
server to validate the data against the schema.
214 Developing Microsoft® SQL Server® 2012 Databases
Module 18
Querying XML Data in SQL Server® 2012
Contents:
Lesson 1: Using the T-SQL FOR XML Statement 215
Lesson 1
Using the T-SQL FOR XML Statement
Contents:
Question and Answers 216
Answer: The XML data is self-describing – you often would not need to also send
documentation or additional files that would be required with text files. Also, if you add
additional elements into the XML at a later time, existing systems that work with the previous
format might not need to be altered.
Answer: An attribute.
Answer: Rarely and only when using PATH mode is not flexible enough.
Developing Microsoft® SQL Server® 2012 Databases 217
2. In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click SQL
Server Management Studio. In the Connect to Server window, type Proseware in the Server
name text box and click Connect. From the File menu, click Open, click Project/Solution, navigate
to D:\10776A_Labs\10776A_18_PRJ\10776A_18_PRJ.ssmssln and click Open.
3. From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file from
within Solution Explorer.
5. Follow the instructions contained within the comments of the script file.
218 Developing Microsoft® SQL Server® 2012 Databases
Lesson 2
Getting Started with XQuery
Contents:
Question and Answers 219
Answer: XPath is a language for managing XML documents. It provides the ability to
navigate XML documents, and manage the XML nodes using a variety of criteria. Learning
this language is important for administrators to help them developing comprehensive
queries of XML document.
exist() Method
Question: Why would the exist() method outperform the value() method?
Answer: It can exit and return a value as soon as an element or attribute is found. No data
conversions are necessary.
Answer: To avoid the execution of undesirable DDL statements. For example, to prevent
unintentional changes to the master database.
220 Developing Microsoft® SQL Server® 2012 Databases
• In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click
SQL Server Management Studio. In the Connect to Server window, type Proseware in the
Server name text box and click Connect. From the File menu, click Open, click
Project/Solution, navigate to D:\10776A_Labs\10776A_18_PRJ\10776A_18_PRJ.ssmssln and
click Open.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
3. Follow the instructions contained within the comments of the script file.
Developing Microsoft® SQL Server® 2012 Databases 221
Lesson 3
Shredding XML
Contents:
Question and Answers 222
Answer: When the XML document needs to be processed many times within a batch.
Developing Microsoft® SQL Server® 2012 Databases 223
• In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click
SQL Server Management Studio. In the Connect to Server window, type Proseware in the
Server name text box and click Connect. From the File menu, click Open, click
Project/Solution, navigate to D:\10776A_Labs\10776A_18_PRJ\10776A_18_PRJ.ssmssln and
click Open.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
3. Follow the instructions contained within the comments of the script file.
224 Developing Microsoft® SQL Server® 2012 Databases
Answer: AUTO mode gives you more control over the returned XML than RAW mode. It generates
nesting in the resulting XML where necessary, based on the SELECT statement supplied.
Answer: PATH mode is a simpler way to introduce additional nesting for representing complex
properties.
Answer: The nodes() method shreds XML data into relational data.
Answer: The RAW mode generates a single <row> element per row in the rowset that is returned by
a SELECT statement.
Best Practices
1. Convert existing code that uses the nvarchar data type for XML parameters to use the XML data type.
2. Provide meaningful row names when using RAW mode by using the optional name parameter to the
RAW clause.
3. Check the query plans for queries using the nodes() method to ensure that the lack of cardinality
estimates is not producing a poor execution plan.
Developing Microsoft® SQL Server® 2012 Databases 225
Answer: You already know that the data is well-formed XML. This simplifies the level of
error-checking that you would otherwise need to perform.
Question: Which XML query mode did you use for implementing the
WebStock.GetAvailableModelsAsXML stored procedure?
Module 19
Working with SQL Server® 2012 Spatial Data
Contents:
Lesson 1: Introduction to Spatial Data 227
Lesson 1
Introduction to Spatial Data
Contents:
Question and Answers 228
Answer: varbinary(max)
Answer: A sphere is one type of ellipsoid. Other ellipsoids are more like squashed spheres.
Developing Microsoft® SQL Server® 2012 Databases 229
2. In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click SQL
Server Management Studio. In the Connect to Server window, type Proseware in the Server
name text box and click Connect. From the File menu, click Open, click Project/Solution, navigate
to D:\10776A_Labs\10776A_19_PRJ\10776A_19_PRJ.ssmssln and click Open.
3. From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file from
within Solution Explorer.
5. Follow the instructions contained within the comments of the script file.
230 Developing Microsoft® SQL Server® 2012 Databases
Lesson 2
Working with SQL Server Spatial Data Types
Contents:
Question and Answers 231
• In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click
SQL Server Management Studio. In the Connect to Server window, type Proseware in the
Server name text box and click Connect. From the File menu, click Open, click
Project/Solution, navigate to D:\10776A_Labs\10776A_19_PRJ\10776A_19_PRJ.ssmssln and
click Open.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
3. Follow the instructions contained within the comments of the script file.
Developing Microsoft® SQL Server® 2012 Databases 233
Lesson 3
Using Spatial Data in Applications
Contents:
Question and Answers 234
Answer: By eliminating any street that does not come near the target area, then only
checking those that are in the vicinity.
Developing Microsoft® SQL Server® 2012 Databases 235
• In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click
SQL Server Management Studio. In the Connect to Server window, type Proseware in the
Server name text box and click Connect. From the File menu, click Open, click
Project/Solution, navigate to D:\10776A_Labs\10776A_19_PRJ\10776A_19_PRJ.ssmssln and
click Open.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
3. Follow the instructions contained within the comments of the script file.
236 Developing Microsoft® SQL Server® 2012 Databases
Question: Why does the order of points matter when defining a polygon?
Answer: Because anti-clockwise returns the inner area, clockwise returns the outside area.
Best Practices
1. Set the SRID for geometry objects to 0 to ensure that operations on multiple geometry objects can
always be performed.
2. Use a CHECK CONSTRAINT to ensure that the SRID values for a column are consistent across all rows.
3. Before creating spatial indexes, make sure that the queries that need to be executed against the data
use predicate forms that are supported by the types of index you are creating.
Developing Microsoft® SQL Server® 2012 Databases 237
Answer: Spatial data will be a completely new concept for many students. Answers will vary
depending upon their backgrounds and experience levels.
238 Developing Microsoft® SQL Server® 2012 Databases
Module 20
Working with Full-Text Indexes and Queries
Contents:
Lesson 1: Introduction to Full-Text Indexing 239
Lesson 1
Introduction to Full-Text Indexing
Contents:
Question and Answers 240
Answer: Mostly because our searching tools haven't been capable of providing appropriate
answers.
Question: What would you need to know to be able to find words rather than substrings?
Answer: You would at least need to have an understanding of the language and its
punctuation.
2. In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click SQL
Server Management Studio. In the Connect to Server window, type Proseware in the Server
name text box and click Connect. From the File menu, click Open, click Project/Solution, navigate
to D:\10776A_Labs\10776A_20_PRJ\10776A_20_PRJ.ssmssln and click Open.
3. From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file from
within Solution Explorer.
5. Follow the instructions contained within the comments of the script file.
242 Developing Microsoft® SQL Server® 2012 Databases
Lesson 2
Implementing Full-Text Indexes in SQL Server
Contents:
Question and Answers 243
• In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click
SQL Server Management Studio. In the Connect to Server window, type Proseware in the
Server name text box and click Connect. From the File menu, click Open, click
Project/Solution, navigate to D:\10776A_Labs\10776A_20_PRJ\10776A_20_PRJ.ssmssln and
click Open.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
3. Follow the instructions contained within the comments of the script file.
Developing Microsoft® SQL Server® 2012 Databases 245
Lesson 3
Working with Full-Text Queries
Contents:
Question and Answers 246
• In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2012, click
SQL Server Management Studio. In the Connect to Server window, type Proseware in the
Server name text box and click Connect. From the File menu, click Open, click
Project/Solution, navigate to D:\10776A_Labs\10776A_20_PRJ\10776A_20_PRJ.ssmssln and
click Open.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql script file
from within Solution Explorer.
3. Follow the instructions contained within the comments of the script file.
248 Developing Microsoft® SQL Server® 2012 Databases
Answer: They avoid indexing commonly used words that do not add value to the index.
Answer: The first is a predicate used in a WHERE clause. The second returns a table of results and can
include ranking of the results.
Question: How do you configure a thesaurus for use with full-text indexing?
Best Practices
1. Create a stoplist for your company. Add to the stoplist, any words that are used in almost all your
company documents.
2. Use auto-population of indexes except in rare cases with specific issues. (These situations would
typically involve data that is updated at a high rate and where the index does not need to be kept
completely up to date).
3. Try to encourage developers in your organization to offer much more flexible user interfaces to your
end users, based on full-text indexes in SQL Server.
Developing Microsoft® SQL Server® 2012 Databases 249
Answer: Answers will vary but it should be values that offer no usefulness in the index, often
as they are repeated in most rows.
Answer: Terms that are commonly used interchangeably within the organization.
250 Developing Microsoft® SQL Server® 2012 Databases
Note Not all training products will have a Knowledge Base article – if that is the case,
please ask your instructor whether or not there are existing error log entries.
Courseware Feedback
Send all courseware feedback to support@mscourseware.com. We truly appreciate your time and effort.
We review every e-mail received and forward the information on to the appropriate team. Unfortunately,
because of volume, we are unable to provide a response but we may use your feedback to improve your
future experience with Microsoft Learning products.
Reporting Errors
When providing feedback, include the training product name and number in the subject line of your e-
mail. When you provide comments or report bugs, please include the following:
Please provide any details that are necessary to help us verify the issue.
Important All errors and suggestions are evaluated, but only those that are validated are
added to the product Knowledge Base article.