Tải bản đầy đủ (.pdf) (107 trang)

Microsoft Press Configuring sql server 2005 môn 70 - 431 phần 10 ppt

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (3.51 MB, 107 trang )

846 Chapter 2: Lesson Review Answers
Lesson 3
1. Correct Answer: A
A. Correct: When a database is in the Simple recovery model, the database
engine minimally logs most operations.
B. Incorrect: In a Full recovery model, all transactions are logged.
C. Incorrect: In a Bulk-Logged recovery model, only bulk operations are min-
imally logged.
D. Incorrect: The Simple recovery model logs transactions only minimally.
2. Correct Answers: B and C
A. Incorrect: The recovery model is a database-level configuration, so you
cannot change the recovery model by using sp_configure.
B. Correct: You can change the database recovery model graphically in SSMS.
C. Correct: ALTER DATABASE is the Transact-SQL statement that lets you
change the recovery model.
D. Incorrect: You cannot specify the recovery model in the CREATE DATA-
BASE statement. When you create a database with the CREATE DATABASE
statement, SQL Server creates it with the recovery model from the model
database.
3. Correct Answers: A and D
A. Correct: Because the transaction log is truncated in the Simple recovery
model, you cannot restore the database to a given point in time.
B. Incorrect: You can restore differential backups because they are database
backups and you do not need transaction log information.
C. Incorrect: You can restore full backups because you do not need transac-
tion log information to perform that action.
D. Correct: You cannot restore a data page in the Simple recovery model. A
page restore requires an unbroken chain of log backups up to the current
log file.
Lesson 4
1. Correct Answers: B, C, and D


A. Incorrect: Database users are database-level objects, not server-level prin-
cipals.
Z01A62271X.fm Page 846 Friday, April 29, 2005 8:08 PM
Chapter 2: Lesson Review Answers 847
B. Correct: Fixed server roles are server principals that let you assign admin-
istrative rights to logins.
C. Correct: Windows logins are server principals that let you give access to
Windows users and groups.
D. Correct: SQL Server logins are server principals created, stored, and man-
aged in SQL Server.
2. Correct Answers: A and C
A. Correct: By using Windows authentication, SQL Server relies on operating
system authentication. You can gain access to all the operating system secu-
rity features and can implement enterprise-wide policies.
B. Incorrect: SQL Server 2005 lets you apply the local Windows Password
Policy to SQL Server logins.
C. Correct: Windows authentication is the default authentication mode.
D. Incorrect: The default authentication mode is Windows authentication.
3. Correct Answers: B and C
A. Incorrect: The FROM clause is for Windows logins only.
B. Correct: CREATE LOGIN is the recommended syntax for creating SQL
Server logins in SQL Server 2005.
C. Correct: Although you can create SQL Server logins by using the
sp_addlogin stored procedure, this procedure is only for backward compat-
ibility. You should use the CREATE LOGIN syntax.
D. Incorrect: The sp_grantlogin stored procedure grants access to an operating
system user.
Lesson 5
1. Correct Answer: B
A. Incorrect: The database catalog is defined in the database system tables.

B. Correct: Schemas group database objects and let you perform some
administrative tasks, such as grant permissions, together.
C. Incorrect: Schemas do not group databases.
D. Incorrect: Schemas do not define the table catalog.
Z01A62271X.fm Page 847 Friday, April 29, 2005 8:08 PM
848 Chapter 2: Lesson Review Answers
2. Correct Answers: B and D
A. Incorrect: Although you can use the FROM clause to create database user
Peter mapped to login Peter, you must specify the LOGIN clause as well.
B. Correct: You can use FOR LOGIN or FROM to specify the mapped login.
C. Incorrect: This capability does not exist in the SQL_LOGIN clause.
D. Correct: You can create the database user without specifying the login
name; the database engine will look for a login with the same name as the
database user.
3. Correct Answers: A and C
A. Correct. You can nest database roles inside other database roles.
B. Incorrect: You can add user-defined database roles and grant permissions
to them.
C. Correct: All SQL Server databases have predefined database roles, but you
can add new database roles to group users and grant permissions.
D. Incorrect: The map between logins and users is a one-to-one relationship.
You cannot map fixed server roles to database roles.
Lesson 6
1. Correct Answer: C
A. Incorrect: The database engine automatically creates the service master key.
B. Incorrect: The service master key can be opened by the service user
account.
C. Correct: The service master key is generated automatically for each instal-
lation and can be opened only by the SQL Server service account.
D. Incorrect: The service master key is generated automatically.

2. Correct Answer: A
A. Correct: This is the correct syntax to create a certificate secured with the
database master key.
B. Incorrect: Although the statement is the correct one, the syntax is not valid.
C. Incorrect: The correct statement to use is CREATE CERTIFICATE, not
CREATE CERT.
D. Incorrect: The correct statement to use is CREATE CERTIFICATE, not
CREATE CERT.
Z01A62271X.fm Page 848 Friday, April 29, 2005 8:08 PM
Chapter 2: Lesson Review Answers 849
3. Correct Answers: A and D
A. Correct: The database master key is optional. You can create it if you want
to use it to protect certificates and keys.
B. Incorrect: The database master key is not mandatory.
C. Incorrect: The database master key is created manually.
D. Correct: You should create the database master key manually by using the
CREATE MASTER KEY statement.
Lesson 7
1. Correct Answer: B
A. Incorrect: You can access objects of other databases in the same instance
without creating an external data source.
B. Correct: You need to create an external data source when you need to
access a different instance.
C. Incorrect: You can access objects of different schemas without creating an
external data source.
D. Incorrect: You can access objects of other owners without creating an
external data source.
2. Correct Answers: A and D
A. Correct: You need to define the OLE DB data source to connect to.
B. Incorrect: You need an OLE DB data source so that you can configure a

linked server to an external data source.
C. Incorrect: You need an OLE DB Provider to configure a linked server to an
external data source.
D. Correct: You need an OLE DB provider that lets you connect to the exter-
nal data source.
3. Correct Answers: B and D
A. Incorrect: You can define the security mode for each linked server.
B. Correct: The database engine creates a self-mapping security context when
you create a linked server. You can change this behavior by configuring a
security mapping.
C. Incorrect: The default configuration is self-mapping.
D. Correct: You can choose a different security mode for each linked server.
Z01A62271X.fm Page 849 Friday, April 29, 2005 8:08 PM
850 Chapter 2: Case Scenario Answers
Chapter 2: Case Scenario Answers
Case Scenario 1: Configuring Security
1. Because you need to provide access to Macintosh clients, you need to configure
Mixed Mode authentication. You can use Windows logins for the Windows XP
users.
2. You should create two database roles: one for Sales users and another one for
Marketing users. With this configuration, you need to manage permissions for
only these two roles.
3. To configure the encryption architecture, you need to do the following:
A. Create a database master key for the CRM database.
B. Create a certificate in the CRM database and protect the certificate with the
database master key.
C. Create a symmetric key that is protected with the certificate, and use the
key to encrypt the data.
Case Scenario 2: Configuring a Heterogeneous Environment
1. You need to create a linked server to provide access from the SQL Server data-

base to the Oracle server. You can then execute distributed queries on the Oracle
server and return results to SQL Server data consumers.
2. Because the external data source is a non-SQL Server and does not support Win-
dows authentication, the most secure solution for your connection is to map
SQL Server logins to remote Oracle users.
3. To send e-mail to branch offices from your SQL Server application, you need to
configure SQL Server Database Mail. Because Database Mail is a standard SMTP
client, you do not need to change your infrastructure. You need only a valid
SMTP account on the UNIX mail server to create a profile in Database Mail that
lets you send e-mail using that SMTP account.
Z01A62271X.fm Page 850 Friday, April 29, 2005 8:08 PM
Chapter 3: Lesson Review Answers 851
Chapter 3: Lesson Review Answers
Lesson 1
1. Correct Answer: C
A. Incorrect: A text data type can store up to 2 GB of data but does not allow
direct comparison of columns.
B. Incorrect: A varbinary data type stores binary data.
C. Correct: A varchar(max) column can store up to 2 GB of data while still
enabling you to use all functions and comparison operators.
D. Incorrect: A regular varchar column cannot store 2 GB of data.
Lesson 2
1. Correct Answers: A and C
A. Correct: You can use system functions that return a scalar value in a check
constraint.
B. Incorrect: Stored procedures cannot be called within a check constraint.
C. Correct: UDFs that return a scalar value can be referenced in a check con-
straint.
D. Incorrect: Views cannot be referenced in check constraints.
Lesson 3

1. Correct Answers: B and D
A. Incorrect: You cannot enable the CLR on a database-by-database basis.
B. Correct: You must enable the CLR by using the Surface Area Configuration
utility.
C. Incorrect: You must compile and load into SQL Server a class that con-
forms to the UDT specification. However, class creation is not limited
exclusively to .NET languages.
D. Correct: You can use any CLR-compatible language, including C#, Visual
Basic, and Cobol.NET to create a class for a CLR user-defined type.
Z01A62271X.fm Page 851 Friday, April 29, 2005 8:08 PM
852 Chapter 3: Case Scenario Answers
Chapter 3: Case Scenario Answers
Case Scenario: Designing a Database
1. There are some core tables that are necessary for this database: Customer, Cus-
tomerAddress, CustomerContact, Patient, PatientAddress, Doctor, DoctorAd-
dress, and Claims.
2. You need to create each of these core tables with primary keys to ensure that
each row can be uniquely identified.
3. You need to link each table together by using appropriate foreign key constraints
to enforce rules such as the following: a claim cannot be entered that is not asso-
ciated with a company, and a patient’s address cannot be created without having
the patient in the database first.
4. You should implement additional supporting tables to enforce such things as
valid lists of states.
5. You need to define check constraints to enforce specific formatting for data such
as Social Security numbers, phone numbers, and e-mail addresses.
6. You need to carefully analyze the claims table to determine whether to store doc-
uments in native format such as Word or PDF, or to transform them into a stan-
dard exchange format and store them in a schema-enforced XML column.
7. All these choices require you to spend time defining all pieces of data that need

to be stored and any business rules that need to be enforced.
Chapter 4: Lesson Review Answers
Lesson 1
1. Correct Answers: B and C
A. Incorrect: An index has a single page at the root level that is called the root
page.
B. Correct: An intermediate level can contain zero or more pages, and an
index can have multiple intermediate levels.
C. Correct: The leaf level can contain one or more pages; there is only a single
leaf level, which is at the bottom of the index.
D. Incorrect: B-tree is the name for the structure of the index, not a level in the
structure.
Z01A62271X.fm Page 852 Friday, April 29, 2005 8:08 PM
Chapter 4: Lesson Review Answers 853
Lesson 2
1. Correct Answer: B
A. Incorrect: A unique index requires that the data value in each row for the
index is not duplicated, but it does not affect the physical ordering of the
table.
B. Correct: A clustered index causes the rows in the table to be physically
ordered based on the index definition.
C. Incorrect: A nonclustered index does not enforce a physical structure.
D. Incorrect: A foreign key enforces referential integrity between two tables.
2. Correct Answer: B
A. Incorrect: PAD_INDEX leaves empty space on intermediate-level pages in
the index.
B. Correct: FILLFACTOR leaves empty space on the leaf level of an index.
C. Incorrect: MAXDOP specifies the maximum degree of parallelism used
during index creation.
D. Incorrect: IGNORE_DUP_KEY causes duplicates to be ignored for unique

indexes.
Lesson 3
1. Correct Answer: A
A. Correct: PAD_INDEX leaves empty space on intermediate-level pages in
the index.
B. Incorrect: FILLFACTOR leaves empty space on the leaf level of an index.
C. Incorrect: MAXDOP specifies the maximum degree of parallelism used
during index creation.
D. Incorrect: IGNORE_DUP_KEY causes duplicates to be ignored for unique
indexes.
Z01A62271X.fm Page 853 Friday, April 29, 2005 8:08 PM
854 Chapter 4: Case Scenario Answers
Chapter 4: Case Scenario Answers
Case Scenario: Indexing a Database
1. The first step is to verify that each table in the database has a primary key to
ensure that rows can be uniquely identified. You implement the primary keys as
indexes, and they should be sufficient to satisfy the requirements of data entry.
2. After verifying that primary keys exist on all the tables, you ensure that each
table has a clustered index. To simplify things at this point, until you have much
more knowledge about the data-access patterns and the volume and pattern of
changes, you decide to alter all the primary keys so that they are clustered
indexes as well.
3. You then create additional nonclustered indexes that SQL Server can use to
quickly satisfy the search criteria that employees are using to locate claims data.
The initial stage of this process is to simply get nonclustered indexes in place for
use with the most common queries.
4. In a secondary indexing round, you will take a closer look at the nonclustered
indexes to determine whether columns can be included to make the indexes
covering indexes for the most common queries.
Chapter 5: Lesson Review Answers

Lesson 1
1. Correct Answers: A, C, and D
A. Correct: A full outer join returns nonmatching data from both the left and
right tables.
B. Incorrect: An inner join returns only matching data.
C. Correct: A right outer join returns nonmatching data from the right table.
D. Correct: A left outer join returns nonmatching data from the left table.
2. Correct Answer: D
A. Incorrect: AVG returns the average value of the rows.
B. Incorrect: COUNT_BIG returns the count of rows as a big integer.
C. Incorrect: STDEV returns the standard deviation of the rows.
D. Correct: COUNT returns the count of rows as an integer.
Z01A62271X.fm Page 854 Friday, April 29, 2005 8:08 PM
Chapter 5: Lesson Review Answers 855
3. Correct Answer: D
A. Incorrect: This syntax would return only matches for “Book”.
B. Incorrect: This syntax would return matches for “Book*” (exact string).
C. Incorrect: This syntax would return only matches for “Book”.
D. Correct: This syntax would return all words starting with “Book”.
Lesson 2
1. Correct Answers: A, C, and D
A. Correct: STR converts numbers into strings.
B. Incorrect: STUFF inserts strings inside other strings.
C. Correct: CAST converts between data types.
D. Correct: CONVERT converts between data types.
2. Correct Answer: C
A. Incorrect: This method does not exist by default.
B. Incorrect: This method does not exist by default.
C. Correct: ToString returns the string representation of the UDT.
D. Incorrect: This method does not exist by default.

3. Correct Answer: B
A. Incorrect: STR is a system function.
B. Correct: The AS keyword is used to create a column alias.
C. Incorrect: The FROM keyword is used to query a table.
D. Incorrect: The COLUMN keyword is used when defining a table.
Lesson 3
1. Correct Answers: A, C, and D
A. Correct: Static cursors do not detect any changes to underlying data.
B. Incorrect: A so-called firehose cursor is a name for a type of forward-only
cursor supported by some clients; it is not a SQL Server feature.
C. Correct: Dynamic cursors detect all changes to the underlying data.
D. Correct: Keyset cursors detect some changes to the underlying data.
Z01A62271X.fm Page 855 Friday, April 29, 2005 8:08 PM
856 Chapter 5: Lesson Review Answers
2. Correct Answer: B
A. Incorrect: Prefixing the table name with # creates a local temporary table.
B. Correct: Prefixing the table name with ## creates a global temporary table.
C. Incorrect: Declaring a table using DECLARE and prefixing with @ creates
a local table variable.
D. Incorrect: Using SELECT INTO and specifying a table name prefixed with
# creates a local temporary table.
3. Correct Answers: A, B, and D
A. Correct: SELECT INTO can be used to create local temporary tables.
B. Correct: SELECT INTO can be used to create permanent tables.
C. Incorrect: SELECT INTO cannot be used to insert data into an existing
table.
D. Correct: SELECT INTO can be used to create global temporary tables.
Lesson 4
1. Correct Answer: B
A. Incorrect: DELETE FROM TRANSACTION deletes all rows from a table

called TRANSACTION.
B. Correct: COMMIT TRANSACTION is used to save the data from a transac-
tion.
C. Incorrect: UPDATE TRANSACTION returns an error because it is updating
no columns in a table called TRANSACTION.
D. Incorrect: SELECT TRANSACTION returns a single row with an unnamed
column with the value “TRANSACTION”.
2. Correct Answer: D
A. Incorrect: The ERROR_STATE function returns the state of the error.
B. Incorrect: The ERROR_MESSAGE function returns the message associated
with the error.
C. Incorrect: The ERROR_SEVERITY function returns the severity of the error.
D. Correct: The ERROR_NUMBER function returns the number for the error
that occurred.
Z01A62271X.fm Page 856 Friday, April 29, 2005 8:08 PM
Chapter 5: Case Scenario Answers 857
Chapter 5: Case Scenario Answers
Case Scenario 1: Database-Backed Authoring Application
1. Because the data-validation stored procedures throw exceptions if there are
errors in the data, this is a natural case for the TRY/CATCH error handling syn-
tax. Proseware developers should start a transaction, perform all data modifica-
tions in a TRY block, and then execute the data-validation procedures. If there
are any errors, they will be caught in the CATCH block, and the data modifica-
tion can be rolled back.
2. Proseware developers can use the COUNT aggregate function to determine how
many submissions each author had. The query can select from the Submission
table, using the author ID column as the nonaggregated grouping column.
3. The report should use the PIVOT operator to generate a weekly summary. First,
developers need to create a derived table that includes the author ID and the
week of submission date. They can then pivot this derived table, using the

COUNT aggregate function, for each week of submission that exists in the quar-
ter.
Case Scenario 2: Banking Corporation
1. Northwind Partners should make sure that all funds-transfer logic participates
in transactions. Starting a transaction will ensure that if an error occurs after
money is withdrawn from one account, but before it is deposited into another
account, the withdrawal can be rolled back, thereby restoring the data to its orig-
inal state.
2. All data-modification code should be put in TRY blocks. Logging code can be
placed into the associated CATCH blocks.
3. The search should use the FREETEXT predicate, which will match a search term
even if it’s not typed exactly as it appears in the data.
Z01A62271X.fm Page 857 Friday, April 29, 2005 8:08 PM
858 Chapter 6: Lesson Review Answers
Chapter 6: Lesson Review Answers
Lesson 1
1. Correct Answer: A
A. Correct: A partition function defines the boundary points used to partition
a table, index, or indexed view.
B. Incorrect: A partition scheme defines the physical storage that partitions
will be stored on.
C. Incorrect: There isn’t a function that returns the values in a partition. To
return values in a partition, you would use a SELECT statement in combi-
nation with the $PARTITION function.
D. Incorrect: The function that returns the number of the partition contain-
ing a specified value is $PARTITION.
Lesson 2
1. Correct Answer: B
A. Incorrect: A partition function defines the boundary points used to parti-
tion a table, index, or indexed view.

B. Correct: A partition scheme defines the physical storage on which the par-
titions are stored.
C. Incorrect: There isn’t a function that returns the values in a partition. To
return the values in a partition, you would use a SELECT statement in com-
bination with the $PARTITION function.
D. Incorrect: The function that returns the number of the partition contain-
ing a specified value is $PARTITION.
Lesson 3
1. Correct Answers: A and B
A. Correct: You can partition tables, indexes, and indexed views.
B. Correct: You can partition tables, indexes, and indexed views.
C. Incorrect: Regular views do not contain any data, so they cannot be
partitioned.
D. Incorrect: Partitioning is internal to a database, so you cannot partition an
entire database.
Z01A62271X.fm Page 858 Friday, April 29, 2005 8:08 PM
Chapter 6: Case Scenario Answers 859
Lesson 4
1. Correct Answer: D
A. Incorrect: A partition function defines the boundary points used to parti-
tion a table, index, or indexed view.
B. Incorrect: A partition scheme defines the physical storage that partitions
will be stored on.
C. Incorrect: There isn’t a function that returns the values in a partition. To
retrieve the values in a partition, you use a SELECT statement in combina-
tion with the $PARTITION function.
D. Correct: The function that returns the number of the partition containing
a specified value is $PARTITION.
Lesson 5
1. Correct Answer: A

A. Correct: SWITCH exchanges a full partition and an empty partition
between tables.
B. Incorrect: MERGE removes a boundary point in a partition function.
C. Incorrect: SPLIT introduces a new boundary point into a partition func-
tion.
D. Incorrect: INTERSECT is a new Transact-SQL operator that is not used to
manage partitions.
Chapter 6: Case Scenario Answers
Case Scenario: Archiving Data
1. You first partition the Claims table by using a datetime column that divides the
data based on month.
2. At the beginning of each month, you create a new table that exactly matches the
structure of the Claims table. Create the new table by using the same partition
function and partition scheme as the Claims table.
3. Use the SWITCH operator to move the oldest partition from the Claims table to
the newly created, empty table.
Z01A62271X.fm Page 859 Friday, April 29, 2005 8:08 PM
860 Chapter 7: Lesson Review Answers
4. Execute a MERGE operation to remove the boundary point for the month that
was just removed.
5. Alter the partition scheme to set the NEXT USED filegroup to the one that held
the data just removed from the table.
6. Execute a SPLIT operation to introduce a new boundary point for the new
month.
7. Use SQL Server Integration Services (SSIS) to load the data into a staging table
in the Research database. The staging table has the same structure as the Claims
table within this database and uses the same partition function and partition
scheme, but the staging table does not have any additional indexes created yet.
8. After you load the data into the staging table, you create the rest of the indexes
so that the staging table matches the structure of the Claims table. You then trun-

cate the table in the claims database.
9. Execute a SPLIT operation against the Claims table to create a new empty parti-
tion that corresponds to the data in the staging table.
10. Execute a SWITCH operation to add the data from the staging table into the
Claims table.
11. Finally, truncate the staging table.
Chapter 7: Lesson Review Answers
Lesson 1
1. Correct Answer: B
A. Incorrect: The CHECK OPTION parameter forces queries that modify data
using the view to conform to any filter criteria specified in the view defini-
tion.
B. Correct: SCHEMABINDING prevents a table from being dropped without
first dropping views that depend on the table.
C. Incorrect: UNION is an operator that can be used in a query.
D. Incorrect: QUOTED_IDENTIFIER is a setting that must be set to ON to cre-
ate an indexed view.
Z01A62271X.fm Page 860 Friday, April 29, 2005 8:08 PM
Chapter 7: Case Scenario Answers 861
Lesson 2
1. Correct Answer: B
A. Incorrect: SCHEMABINDING prevents a base table from being dropped if
a view is created over it.
B. Correct: CHECK OPTION ensures that changes made through the view
conform to the selection criteria of the view.
C. Incorrect: The ANSI_NULLS setting does not limit the modifications that
can be performed through a view.
D. Incorrect: The QUOTED_IDENTIFIER setting does not limit the modifica-
tions that can be performed through a view.
Lesson 3

1. Correct Answers: A and C
A. Correct: QUOTED_IDENTIFIER has to be set to ON when the view and any
base tables referenced in the view are created.
B. Incorrect: Two-part names are required for all tables referenced in the view.
C. Correct: The view must have been created with SCHEMABINDING.
D. Incorrect: ANSI_NULLS has to be turned ON when the view and base
tables referenced in the view are created.
Chapter 7: Case Scenario Answers
Case Scenario: Creating Views
1. The development group should implement views that return data based on var-
ious functions that the applications require. The developers can then replace the
application code that currently executes the queries with the new views, ensur-
ing that all applications are using the same query.
2. As long as all the requirements are met, the developers could turn the poorly
performing queries into views and then add a clustered index to each view to
make it an indexed view. Using indexed views would incur a slight overhead
when data is written but could improve performance on read operations.
Z01A62271X.fm Page 861 Friday, April 29, 2005 8:08 PM
862 Chapter 8: Lesson Review Answers
Chapter 8: Lesson Review Answers
Lesson 1
1. Correct Answers: A and C
A. Correct: Document order and structure are preserved because the XML
data is stored as text. SQL Server does not modify its contents.
B. Incorrect: When storing XML data in a text column, SQL Server does not
allow mixing the XML data with relational data as a result of a query. The
only way to do this is to extract the XML data from the text column and
assign it to a variable of type XML.
C. Correct: This is the most efficient scenario. In cases in which the XML data
will not be filtered or modified at the node level, storing it as a text column

allows for fast retrieval of the complete XML document.
D. Incorrect: SQL Server 2005 does not offer any indexing for text columns.
2. Correct Answers: B and C
A. Incorrect: You can create indexes on XML data type columns, but this is
not a function of an XML schema.
B. Correct: An XML schema validates an XML instance whenever a typed
XML instance is assigned to or modified.
C. Correct: An XML schema provides information about the types of
attributes and elements in the XML data type instance. For example, deci-
mal arithmetic operations can be performed on a decimal value but not on
a string value.
D. Incorrect: The XML data type includes methods for manipulating XML
data and structure; this is not a function of an XML schema.
Z01A62271X.fm Page 862 Friday, April 29, 2005 8:08 PM
Chapter 8: Lesson Review Answers 863
Lesson 2
1. Correct Answer: C
A. Incorrect: The requested XML structure is made of two levels, so a nested
query is required. The formatting indications to create elements and
attributes do not match the requested structure.
B. Incorrect: Even though a nested query is used, the inner FOR XML query
does not use the TYPE instruction to indicate that the result of the inner
query should be of the XML data type, so it will be interpreted as text. The
formatting indications to create elements and attributes do not match the
requested structure.
C. Correct: A nested query is used to generate a two-level XML structure. The
outer query uses an aggregate function to calculate the total number of con-
tacts stored for each company. The inner query retrieves each of the con-
tacts for that company. The inner query composes the columns into
attribute-centric XML nested under a <Contacts> element. The outer query

composes the columns into element-centric XML nested under a <Con-
tactList> element.
D. Incorrect: The inner query composes the columns into element-centric
XML nested under a <Contacts> element. The outer query composes the
columns into attribute-centric XML nested under a <ContactList> element.
The formatting indications to create elements and attributes do not match
the requested structure.
2. Correct Answers: A and D
A. Correct: The exist() method can execute the XQUERY expression. It will
return 1 if there are any nodes returned from the expression or 0 if there is
nothing returned from the expression.
B. Incorrect: The modify() method accepts a different type of expression that
includes specific commands for XML data manipulation.
C. Incorrect: The value() method accepts XQUERY expressions, but it must
validate that the expression returns a single scalar value. This is not the
case in this example, so the expression would generate a compilation error.
D. Correct: The query() method would execute the XQUERY expression and
return an XML fragment as output.
Z01A62271X.fm Page 863 Friday, April 29, 2005 8:08 PM
864 Chapter 8: Lesson Review Answers
Lesson 3
1. Correct Answer: C
A. Incorrect: The exist() method of the XML data type provides the ability to
execute an XPATH or XQUERY expression to check for the existence of
nodes.
B. Incorrect: An XML schema collection is used to type the parameters, vari-
ables, and columns of the XML data type.
C. Correct: An annotated XML schema uses special annotation keywords to
map an XML schema to a relational schema.
D. Incorrect: A relational schema is the term for data in a relational-tabular

format; this schema does not map an XML schema to the database schema.
2. Correct Answers: B and C
A. Incorrect: An XML schema validates your XML document: if an XML doc-
ument conforms to what is declared inside an XML schema, the XML doc-
ument is said to be valid. An invalid XML document does not conform to
what is declared inside an XML schema.
B. Correct: XML views and annotation XML schemas are easy to maintain
because they are stored as files on the file system; any changes you make to
them do not require recompiling the application.
C. Correct: You can offload the XML rendering from your database system by
deploying the XML views and annotated XML schemas on a different
machine than the database server.
D. Incorrect: An updategram is the mechanism that compares the original
and current views of the XML data to create the Transact-SQL commands
that synchronize the changes from the XML data into relational data.
Z01A62271X.fm Page 864 Friday, April 29, 2005 8:08 PM
Chapter 8: Lesson Review Answers 865
Lesson 4
1. Correct Answer: C
A. Incorrect: SQLXML-annotated XSD schemas just declare a mapping
between an XML schema and a relational schemSQLXML-annotated XSD
schemas by themselves do not support updating the XML data; they must
be used in conjunction with SQLXML updategrams.
B. Incorrect: SQLXML updategrams allow modification of XML values but
do not support modifying the XML structure. SQLXML updategrams take
the XML structure as declared on an annotated XSD schema.
C. Correct: XML DML enables you to modify XML values as well as the XML
structure. By using XQUERY constructor functions such as attribute and
element, XML DML supports adding a new dynamic structure to the XML
document.

D. Incorrect: You use OPENXML to transform an XML instance into a tabular
format. It does not support modifying XML data.
2. Correct Answer: B
A. Incorrect: The result of executing the XQUERY expression is a collection
of nodes. XQUERY is supported by the insert XML DML keyword.
B. Correct: The insert instruction is composed of two expressions and one
operator. The first expression, the XQUERY expression, extracts all the
Employee nodes in this location: /Departments/Department[@id=1]/
Employees/Employee. The second expression indicates that the extracted
nodes should be copied into the same location (/Departments/Depart-
ment[@id=1]/Employees/Employee), therefore duplicating the nodes.
C. Incorrect: The [1] axis applies to the entire path because it is scoped with
the parenthesis. The contents of /Departments/Department[@id=1]/
Employees/Employee will be copied into exactly the same location.
D. Incorrect: XML DML is an extension to the XQUERY language, so it sup-
ports the FLWOR expression.
Z01A62271X.fm Page 865 Friday, April 29, 2005 8:08 PM
866 Chapter 8: Lesson Review Answers
Lesson 5
1. Correct Answers: A, B, and C
A. Correct: By processing all documents at once, just a single DOM structure
is created in memory.
B. Correct: This is the most important performance practice when using
OPENXML. The sp_xml_removedocument stored procedure will unload the
XML structure and free memory resources.
C. Correct: Using smaller XML tag names could provide a slight improve-
ment in performance, especially if the XML tag names used are very large.
D. Incorrect: Splitting the XML data into multiple files is usually not a good
idea because you will need to process each of them independently. This
process translates into loading multiple DOM structures in memory

instead of just one.
2. Correct Answers: A, B, and C
A. Correct: When calling the sp_xml_preparedocument stored procedure to
use OPENXML, the procedure accepts the following data types: char, nchar,
varchar, nvarchar, text, ntext, or xml. But if the data is stored already as XML,
using the nodes() method would be easier and provide better performance.
B. Correct: OPENXML enables you to extract XML data out of a single
source—a single XML document loaded into memory. By using the nodes()
method, you can merge multiple XML documents coming from different
sources into a single result set.
C. Correct: The XPATH implementation in OPENXML and in the XML data
type differs slightly, and it is possible that an XPATH function that works in
OPENXML won’t work in the XML data type—or the other way around.
D. Incorrect: The syntax for writing OPENXML has not changed from previ-
ous versions of SQL Server. Therefore, you don’t need to migrate code
involving XML manipulation via OPENXML unless any of the previously
explained reasons apply.
Lesson 6
1. Correct Answer: C
A. Incorrect: A PATH secondary index will not help much in this type of
query because the expression is not searching for a specific path, and the
path is not even fully specified.
Z01A62271X.fm Page 866 Friday, April 29, 2005 8:08 PM
Chapter 8: Case Scenario Answers 867
B. Incorrect: A PROPERTY secondary index will not help much in this type of
query because the expression is not filtering on the table’s primary key and
extracting values by using the value() method.
C. Correct: A VALUE secondary index will improve the query performance
because the query engine will execute a lookup on the secondary index
and serve the query without having to access the XML BLOB.

D. Incorrect: SQL Server 2005 does not support creating a clustered index on
an XML-typed column.
2. Correct Answer: D
A. Incorrect: Creating new indexes will not help because the application is
inserting more information than it is reading.
B. Incorrect: Dropping the secondary indexes would bring a slight improve-
ment in performance, but it is not the best answer.
C. Incorrect: Creating new indexes would not help because the application is
inserting more information than it is reading.
D. Correct: Dropping all the indexes on the XML columns would improve
performance because SQL Server would not have to maintain them. You
could re-create them later, after the heavy insert activity is finished.
Chapter 8: Case Scenario Answers
Case Scenario 1: Troubleshooting XML Performance by Choosing the
Correct Indexing Strategy
1. You should use an XML VALUE index if your queries are value-based, meaning
that you will filter by the contents of the nodes first and maybe not by the struc-
ture of the XML data. Also, you should use an XML VALUE index when the path
is not fully specified or if it includes a wildcard. When such conditions exist, an
XML VALUE index is optimal because the key columns of the VALUE index are
the node value and path of the primary XML index. In our case scenario, even
though we are interested in searching on the values (we must search for feeds
that contain specific keywords) and not in the structure, the XQUERY written in
the fn_FindKeyword function filters first by the node structure and then by the
values. Therefore, the VALUE index doesn’t provide the best performance.
Z01A62271X.fm Page 867 Friday, April 29, 2005 8:08 PM
868 Chapter 9: Lesson Review Answers
2. The for $item in /rss/channel/item, $title in $item/title, $desc in $item/desc decla-
ration in the FLWOR expression will filter first by path to find those nodes that
must be processed. In this case, an XML PATH index would be much more valu-

able because the key columns are the path and then the node value.
3. Another possible alternative in this specific scenario is to use the SQL Server
2005 Full Text Search service to query the text provided inside the XML feeds.
Case Scenario 2: Handling Data as XML or as Relational
Representation
Among the many reasons you could give your manager for your recommended solu-
tion, here are some important benefits your company could gain from using XML
Web services for this application:
■ The type of information you must store requires order preservation. The order in
which questions are formulated depends on previous answers. Preserving order
is an XML strength.
■ The different schemes for answer types would be hard to represent in a relational
structure. XML easily handles semistructured data, in which some structure in
the data is constant, and others might be optional or dependent on other parts
of the structure.
■ Because this questionnaire must be given in more than 150 countries, it likely
will be easier and more scalable and maintainable to distribute the questions as
XML Web services. And if the data will be consumed in XML format, why spend
the time and effort to transform it into a different format just for storage?
■ Management will want to run different types of reports against this data (for
example, which employees are performing above expectations, which are having
morale problems, and so on). And you can use XQUERY to create complex que-
ries that span different answer choices and answer formats.
Chapter 9: Lesson Review Answers
Lesson 1
1. Correct Answers: B and D
A. Incorrect: Modifying data is not allowed within a function.
B. Correct: A function can return the result of a SELECT statement.
C. Incorrect: Stored procedures cannot be executed within a function.
D. Correct: Inserts, updates, and deletes are allowed with local table variables.

Z01A62271X.fm Page 868 Friday, April 29, 2005 8:08 PM
Chapter 9: Case Scenario Answers 869
Lesson 2
1. Correct Answer: B
A. Incorrect: The ENCRYPTION option causes SQL Server to encrypt the con-
tents of the stored procedure before storing it.
B. Correct: The RECOMPILE option causes SQL Server to compile the stored
procedure each time it is executed, generating a new query plan for each
execution.
C. Incorrect: VARYING is a keyword related to the output parameter of the
procedure.
D. Incorrect: The EXECUTE AS clause specifies the security context for the
stored procedure.
Lesson 3
1. Correct Answer: C
A. Incorrect: Indexes cannot be created within a trigger.
B. Incorrect: Backup and restore operations are not allowed within a trigger.
C. Correct: Triggers can be used to insert data into tables.
D. Incorrect: The structure of a database cannot be changed in a trigger.
Chapter 9: Case Scenario Answers
Case Scenario: Creating Triggers, Functions, and Stored Procedures
1. Because all changes need to be audited, Contoso should implement DML trig-
gers behind each table that log all changes in a set of audit tables. The company
should also implement DDL triggers that prevent any changes to objects (CRE-
ATE/ALTER/DROP) within the database so that structural changes can be con-
trolled and audited.
2. Because the patient risk score is a common calculation that should not be left up
to each developer to implement, this calculation should be encapsulated in a
function.
3. The company should implement stored procedures that SELECT, INSERT,

UPDATE, and DELETE data so that users do not need permissions directly to the
base tables within the database.
Z01A62271X.fm Page 869 Friday, April 29, 2005 8:08 PM
870 Chapter 10: Lesson Review Answers
Chapter 10: Lesson Review Answers
Lesson 1
1. Correct Answers: A and C
A. Correct: When the database recovery model is changed from Full to Bulk-
Logged, point-in-time recovery capability is lost and is not reestablished
until the recovery model is set back to Full and a log backup is performed.
B. Incorrect: Minimal logging does NOT require that a table have a clustered
index. In fact, if a table has a clustered index and the table is not empty,
minimal logging cannot occur. Also, the database does not have to be in
single-user mode for clustered indexes to be created.
C. Correct: A table lock can prevent users from accessing the data in the table
during the bulk load.
D. Incorrect: bcp can be run at any time.
Lesson 2
1. Correct Answers: B and D
A. Incorrect: The -T argument specifies that the connection to SQL Server is a
trusted connection. Although you need to establish a connection with the
SQL Server, it does not necessarily have to be a trusted connection.
B. Correct: The -t argument specifies the field terminator or delimiter, and
because the default is a tab, not a comma, you must specify this argument.
C. Incorrect: The -r argument specifies the row delimiter, which defaults to
newline if not specified. Therefore, you do not need to specify this argu-
ment.
D. Correct: The -F argument specifies which row is the first row bcp should
read for import; it defaults to the first row. The data file contains a header
row as its first row, so bcp must start the import at the second row.

Z01A62271X.fm Page 870 Friday, April 29, 2005 8:08 PM

×