Contents

About the Authors

About the Technical Reviewers

Acknowledgments

Introduction

images Chapter 1: Getting Started with SELECT

1-1. Connecting to a Database

Solution

How It Works

1-2. Retrieving Specific Columns

Solution

How It Works

1-3. Retrieving All Columns

Solution

How It Works

1-4. Specifying the Rows to Be Returned

Solution

How It Works

1-5. Renaming the Output Columns

Solution

How It Works

1-6. Building a Column from an Expression

Solution

How It Works

1-7. Providing Shorthand Names for Tables

Solution

How It Works

1-8. Negating a Search Condition

Solution

How It Works

1-9. Specifying A Range of Values

Solution

How It Works

1-10. Checking for NULL Values

Solution

How It Works

1-11. Providing a List of Values

Solution

How It Works

1-12. Performing Wildcard Searches

Solution

How It Works

1-13. Sorting Your Results

Solution

How It Works

1-14. Specifying Sort Order

Solution

How It Works

1-15. Sorting by Columns Not Selected

Solution

How It Works

1-16. Forcing Unusual Sort Orders

Solution

How It Works

1-17. Paging Through A Result Set

Solution

How It Works

images Chapter 2: Elementary Programming

2-1. Declaring Variables

Solution

How It Works

2-2. Retrieving a Value into a Variable

Solution

How It Works

2-3. Writing an IF…THEN…ELSE Statement

Solution

How It Works

2-4. Writing a Simple CASE Expression

Solution

How It Works

2-5. Writing a Searched CASE Expression

Solution

How It Works

2-6. Writing a WHILE Statement

Solution

How It Works

2-7. Returning from the Current Execution Scope

Solution #1: Exit with No Return Value

Solution #2: Exit and Provide a Value

How It Works

2-8. Going to a Label in a Transact-SQL Batch

Solution

How It Works

2-9. Pausing Execution for a Period of Time

Solution

How It Works

2-10. Creating and Using Cursors

Solution

How It Works

images Chapter 3: NULLs and Other Pitfalls

3-1. Replacing NULL with an Alternate Value

Solution

How It Works

3-2. Returning the First Non-NULL Value from a List

Solution

How It Works

3-3. Choosing Between ISNULL and COALESCE in a SELECT Statement

Solution

How It Works

3-4. Looking for NULLs in a Table

Solution

How It Works

3-5. Removing Values from an Aggregate

Solution

How It Works

3-6. Enforcing Uniqueness with NULL Values

Solution

How It Works

3-7. Enforcing Referential Integrity on Nullable Columns

Solution

How It Works

3-8. Joining Tables on Nullable Columns

Solution

How It Works

images Chapter4: Querying from Multiple Tables

4-1. Correlating Parent and Child Rows

Solution

How It Works

4-2. Querying Many-to-Many Relationships

Solution

How It Works

4-3. Making One Side of a Join Optional

Solution

How It Works

4-4. Making Both Sides of a Join Optional

Solution

How It Works

4-5. Generating All Possible Row Combinations

Solution

How It Works

4-6. Selecting from a Result Set

Solution

How It Works

4-7. Testing for the Existence of a Row

Solution

How It Works

4-8. Testing Against the Result from a Query

Solution

How It Works

4-9. Comparing Subsets of a Table

Solution

How It Works

4-10. Stacking Two Row Sets Vertically

Solution

How It Works

4-11. Eliminating Duplicate Values from a Union

Solution

How It Works

4-12. Subtracting One Row Set from Another

Solution

How It Works

4-13. Finding Rows in Common Between Two Row Sets

Solution

How It Works

4-14. Finding Rows That Are Missing

Solution

How It Works

4-15. Comparing Two Tables

Solution

How It Works

images Chapter 5: Grouping and Summarizing

5-1. Summarizing a Result Set

Solution

How It Works

5-2. Creating Summary Groups

Solution

How It Works

5-3. Restricting a Result Set to Groups of Interest

Solution

How It Works

5-4. Removing Duplicates from the Detailed Results

Solution

How It Works

5-5. Creating Summary Cubes

Solution

How It Works

5-6. Creating Hierarchical Summaries

Solution

How It Works

5-7. Creating Custom Summaries

Solution

How It Works

5-8. Identifying Rows Generated by the GROUP BY Arguments

Solution

How It Works

5-9. Identifying Summary Levels

Solution

How It Works

images Chapter 6: Advanced Select Techniques

6-1. Avoiding Duplicate Results

Solution #1

Solution #2

How It Works

6-2. Returning the Top N Rows

Solution

How It Works

6-3. Renaming a Column in the Output

Solution

How It Works

6-4. Retrieving Data Directly into Variables

Solution

How It Works

6-5. Creating a New Table with the Results from a Query

Solution

How It Works

6-6. Filtering on the Results from a Subquery

Solution

How It Works

6-7. Selecting from the Results of Another Query

Solution

How It Works

6-8. Passing Rows Through a Function

Solution

How It Works

6-9. Returning Random Rows from a Table

Solution

How It Works

6-10. Converting Rows into Columns

Solution

How It Works

6-11. Converting Columns into Rows

Solution

How It Works

6-12. Reusing Common Subqueries in a Query

Solution

How It Works

6-13. Querying Recursive Tables

Solution

How It Works

6-14. Hard-Coding the Results from a Query

Solution

How It Works

images Chapter 7: Aggregations and Windowing

7-1. Computing an Average

Solution

How It Works

7-2. Counting the Rows in a Group

Solution

How It Works

7-3. Summing the Values in a Group

Summary

How It Works

7-4. Finding the High and Low Values in a Group

Solution

How It Works

7-5. Detecting Changes in a Table

Solution

How It Works

7-6. Finding the Statistical Variance in the Values of a Column

Solution

How It Works

7-7. Finding the Standard Deviation in the Values of a Column

Solution

How It Works

7-8. Calculating Totals Based Upon the Prior Row

Solution

How It Works

7-9. Calculating Totals Based Upon a Subset of Rows

Solution

How It Works

7-10. Using a Logical Window

Solution

How It Works

7-11. Generating an Incrementing Row Number

Solution

How It Works

7-12. Returning Rows by Rank

Solution

How It Works

7-13. Returning Rows by Rank Without Gaps

Solution

How It Works

7-14. Sorting Rows into Buckets

Solution

How It Works

7-15. Grouping Logically Consec44utive Rows Together

Solution

How It Works

7-16. Accessing Values from Other Rows

Solution

How It Works

7-17. Accessing the First or Last Value from a Partition

Solution

How It Works

7-18. Calculating the Relative Position or Rank of a Value in a Set of Values

Solution

How It Works

7-19. Calculating Continuous or Discrete Percentiles

Solution

How It Works

7-20. Assigning Sequences in a Specified Order

Solution

How It Works

images Chapter 8: Inserting, Updating, Deleting

8-1. Inserting a New Row

Solution

How It Works

8-2. Specifying Default Values

Solution

How It Works

8-3. Overriding an IDENTITY Column

Solution

How It Works

8-4. Generating a Globally Unique Identifier (GUID)

Solution

How It Works

8-5. Inserting Results from a Query

Solution

How It Works

8-6. Inserting Results from a Stored Procedure

Solution

How It Works

8-7. Inserting Multiple Rows at Once

Solution

How It Works

8-8. Inserting Rows and Returning the Inserted Rows

Solution

How It Works

8-9. Updating a Single Row or Set of Rows

Solution

How It Works

8-10. Updating with a Sec29ond Table as the Data Source

Solution

How It Works

8-11. Updating Data and Returning the Affected Rows

Solution

How It Works

8-12. Updating Large-Value Columns

Solution

How It Works

8-13. Deleting Rows

Solution

How It Works

8-14. Deleting Rows and Returning the Deleted Rows

Solution

How It Works

8-15. Deleting All Rows Quickly (Truncating)

Solution

How It Works

8-16. Merging Data (Inserting, Updating, or Deleting Values)

Solution

How It Works

images Chapter 9: Working with Strings

9-1. Concatenating Multiple Strings

Solution

How It Works

9-2. Finding a Character’s ASCII Value

Solution

How It Works

9-3. Returning Integer and Character Unicode Values

Solution

How It Works

9-4. Locating a Substring

Solution

How It Works

9-5. Determining the Similarity of Strings

Solution

How It Works

9-6. Returning the Left-Most Portion of a String

Solution

How It Works

9-7. Returning Part of a String

Solution

How It Works

9-8. Counting Characters or Bytes in a String

Solution

How It Works

9-9. Replacing Part of a String

Solution

How It Works

9-10. Stuffing a String into a String

Solution

How It Works

9-11. Changing Between Lower- and Uppercase

Solution

How It Works

9-12. Removing Leading and Trailing Blanks

Solution

How It Works

9-13. Repeating an Expression N Times

Solution

How It Works

9-14. Repeating a Blank Space N Times

Solution

How It Works

9-15. Reversing the order of Characters in a String

Solution

How It Works

images Chapter 10: Working with Dates and Times

10-1. Returning the Current Date and Time

Solution

How It Works

10-2. Converting Between Time Zones

Solution

How It Works

10-3. Converting a Date/Time Value to a Datetimeoffset Value

Solution

How It Works

10-4. Incrementing or Decrementing a Date’s Value

Solution

How It Works

10-5. Finding the Difference Between Two Dates

Solution

How It Works

10-6. Finding the Elapsed Time Between Two Dates

Solution

How It Works

10-7. Displaying the String Value for Part of a Date

Solution

How It Works

10-8. Displaying the Integer Representations for Parts of a Date

Solution

How It Works

10-9. Determining Whether a String Is a Valid Date

Solution

How It Works

10-10. Determining the Last Day of the Month

Solution

How It Works

10-11. Creating a Date from Numbers

Solution

How It Works

10-12. Finding the Beginning Date of a Datepart

Solution #1

Solution #2

Solution #3

How It Works #1

How It Works #2

How It Works #3

10-13. Include Missing Dates

Solution

How It Works

10-14. Finding Arbitrary Dates

Solution

How It Works

10-15. Querying for Intervals

Solution

How It Works

10-16. Working with Dates and Times Across National Boundaries

Solution

How It Works

images Chapter 11: Working with Numbers

11-1. Representing Integers

Solution

How It Works

11-2. Representing Decimal Amounts

Solution

How It Works

11-3. Representing Monetary Amounts

Solution #1

Solution #2

How It Works

11-4. Representing Floating-Point Values

Solution

How It Works

11-5. Writing Mathematical Expressions

Solution

How It Works

11-6. Guarding Against Errors in Expressions with Mixed Data Types

Solution

How It Works

11-7. Rounding

Solution

How It Works

11-8. Rounding Always Up or Down

Solution

How It Works

11-9. Discarding Decimal Places

Solution

How It Works

11-10. Testing Equality of Binary Floating-Point Values

Solution

How It Works

11-11. Treating Nulls as Zeros

Solution

How It Works

11-12. Generating a Row Set of Sequential Numbers

Solution

How It Works

11-13. Generating Random Integers in a Row Set

Solution

How It Works

11-14. Reducing Space Used by Decimal Storage

Solution

How It Works

images Chapter 12: Transactions, Locking, Blocking, and Deadlocking

Transaction Control

12-1. Using Explicit Transactions

Solution

How It Works

12-2. Displaying the Oldest Active Transaction

Solution

How It Works

12-3. Querying Transaction Information by Session

Solution

How It Works

Locking

12-4. Viewing Lock Activity

Solution

How It Works

12-5. Controlling a Table’s Lock Escalation Behavior

Solution

How It Works

Transaction, Locking, and Concurrency

12-6. Configuring a Session’s Transaction Locking Behavior

Solution

How It Works

Blocking

12-7. Identifying and Resolving Blocking Issues

Solution

How It Works

12-8. Configuring How Long a Statement Will Wait for a Lock to Be Released

Solution

How It Works

Deadlocking

12-9. Identifying Deadlocks with a Trace Flag

Solution

How It Works

12-10. Setting Deadlock Priority

Solution

How It Works

images Chapter 13: Managing Tables

13-1. Creating a Table

Solution

How It Works

13-2. Adding a Column

Solution

How It Works

13-3. Adding a Column That Requires Data

Solution

How It Works

13-4. Changing a Column

Solution

How It Works

13-5. Creating a Computed Column

Solution

How It Works

13-6. Removing a Column

Solution

How It Works

13-7. Removing a Table

Solution

How It Works

13-8. Reporting on a Table’s Definition

Solution

How It Works

13-9. Reducing Storage Used by NULL Columns

Solution

How It Works

13-10. Adding a Constraint to a Table

Solution

How It Works

13-11. Creating a Recursive Foreign Key

Solution

How It Works

13-12. Allowing Data Modifications to Foreign Keys Columns in the Referenced Table to Be Reflected in the Referencing Table

Solution

How It Works

13-13. Specifying Default Values for a Column

Solution

How It Works

13-14. Validating Data as It Is Entered into a Column

Solution

How It Works

13-15. Temporarily Turning Off a Constraint

Solution

How It Works

13-16. Removing a Constraint

Solution

How It Works

13-17. Creating Auto-incrementing Columns

Solution

How It Works

13-18. Obtaining the Identity Value Used

Solution

How It Works

13-19. Viewing or Changing the Seed Settings on an Identity Column

Solution

How It Works

13-20. Inserting Values into an Identity Column

Solution

How It Works

13-21. Automatically Inserting Unique Values

Solution

How It Works

13-22. Using Unique Identifiers Across Multiple Tables

Solution

How It Works

13-23. Using Temporary Storage

Solution #1

Solution #2

How It Works

images Chapter 14: Managing Views

Regular Views

14-1. Creating a View

Solution

How It Works

14-2. Querying a View’s Definition

Solution

How It Works

14-3. Obtaining a List of All Views in a Database

Solution

How It Works

14-4. Obtaining a List of All Columns in a View

Solution

How It Works

14-5. Refreshing the Definition of a View

Solution

How It Works

14-6. Modifying a View

Solution

How It Works

14-7. Modifying Data Through a View

Solution

How It Works

14-8. Encrypting a View

Solution

How It Works

14-9. Indexing a View

Solution

How It Works

14-10. Creating a Partitioned View

Solution

How It Works

14-11. Creating a Distributed Partitioned View

Solution

How It Works

images Chapter 15: Managing Large Tables and Databases

15-1. Partitioning a Table

Solution

How It Works

15-2. Locating Data in a Partition

Solution

How It Works

15-3. Adding a Partition

Solution

How It Works

15-4. Removing a Partition

Solution

How It Works

15-5. Determining Whether a Table Is Partitioned

Solution

How It Works

15-6. Determining the Boundary Values for a Partitioned Table

Solution

How It Works

15-7. Determining the Partitioning Column for a Partitioned Table

Solution

How It Works

15-8. Moving a Partition to a Different Partitioned Table

Solution

How It Works

15-9. Moving Data from a Nonpartitioned Table to a Partition in a Partitioned Table

Solution

How It Works

15-10. Moving a Partition from a Partitioned Table to a Nonpartitioned Table

Solution

How It Works

15-11. Reducing Table Locks on Partitioned Tables

Solution

How It Works

15-12. Removing Partition Functions and Schemes

Solution

How It Works

15-13. Easing VLDB Manageability (with Filegroups)

Solution

How It Works

15-14. Compressing Table Data

Solution

How It Works

15-15. Rebuilding a Heap

Solution

How It Works

images Chapter 16: Managing Indexes

Index Overview

16-1. Creating a Table Index

Solution

How It Works

16-2. Enforcing Uniqueness on Non-key Columns

Solution

How It Works

16-3. Creating an Index on Multiple Columns

Solution

How It Works

16-4. Defining Index Column Sort Direction

Solution

How It Works

16-5. Viewing Index Metadata

Solution

How It Works

16-6. Disabling an Index

Solution

How It Works

16-7. Dropping Indexes

Solution

How It Works

16-8. Changing an Existing Index

Solution

How It Works

Controlling Index Build Performance and Concurrency

16-9. Sorting in Tempdb

Solution

How It Works

16-10. Controlling Index Creation Parallelism

Solution

How It Works

16-11. User Table Access During Index Creation

Solution

How It Works

Index Options

16-12. Using an Index INCLUDE

Solution

How It Works

16-13. Using PADINDEX and FILLFACTOR

Solution

How It Works

16-14. Disabling Page and/or Row Index Locking

Solution

How It Works

Managing Very Large Indexes

16-15. Creating an Index on a Filegroup

Solution

How It Works

16-16. Implementing Index Partitioning

Solution

How It Works

16-17. Indexing a Subset of Rows

Solution

How It Works

16-18. Reducing Index Size

Solution

How It Works

images Chapter 17: Stored Procedures

17-1. Selling the Benefits

Solution

How It Works

17-2. Creating a Stored Procedure

Solution

How It Works

17-3. Generalizing a Stored Procedure

Solution

How It Works

17-4. Making Parameters Optional

Solution

How It Works

17-5. Making Early Parameters Optional

Solution

How It Works

17-6. Returning Output

Solution

How It Works

17-7. Modifying a Stored Procedure

Solution

How It Works

17-8. Removing a Stored Procedure

Solution

How It Works

17-9. Automatically Run a Stored Procedure at Start-Up

Solution

How It Works

17-10. Viewing a Stored Procedure’s Definition

Solution

How It Works

17-11. Documenting Stored Procedures

Solution

How It Works

17-12. Determining the Current Nesting Level

Solution

How It Works

17-13. Encrypting a Stored Procedure

Solution

How It Works

17-14. Specifying a Security Context

Solution

How It Works

17-15. Avoiding Cached Query Plans

Solution

How It Works

17-16. Flushing the Procedure Cache

Solution

How It Works

images Chapter 18: User-Defined Functions and Types

UDF Basics

18-1. Creating Scalar Functions

Solution

How It Works

18-2. Creating Inline Functions

Solution

How It Works

18-3. Creating Multi-Statement User-Defined Functions

Solution

How It Works

18-4. Modifying User-Defined Functions

Solution

How It Works

18-5. Viewing UDF Metadata

Solution

How It Works

Benefitting from UDFs

18-6. Maintaining Reusable Code

Solution

How It Works

18-7. Cross-Referencing Natural Key Values

Problem

Solution

How It Works

18-8. Replacing a View with a Function

Solution

How It Works

18-9. Dropping a Function

Solution

How It Works

UDT Basics

18-10. Creating and Using User-Defined Types

Solution

How It Works

18-11. Identifying Dependencies on User-Defined Types

Solution

How It Works

18-12. Passing Table-Valued Parameters

Solution

How It Works

18-13. Dropping User-Defined Types

Solution

How It Works

images Chapter 19: Triggers

19-1. Creating an AFTER DML Trigger

Solution

How It Works

19-2. Creating an INSTEAD OF DML Trigger

Solution

How It Works

19-3. Handling Transactions in Triggers

Solution

How It Works

19-4. Linking Trigger Execution to Modified Columns

Solution

How It Works

19-5. Viewing DML Trigger Metadata

Solution

How It Works

19-6. Creating a DDL Trigger

Solution

How It Works

19-7. Creating a Logon Trigger

Solution

How It Works

19-8. Viewing DDL Trigger Metadata

Solution

How It Works

19-9. Modifying a Trigger

Solution

How It Works

19-10. Enabling and Disabling a Trigger

Solution

How It Works

19-11. Nesting Triggers

Solution

How It Works

19-12. Controlling Recursion

Solution

How It Works

19-13. Specifying the Firing Order

Solution

How It Works

19-14. Dropping a Trigger

Solution

How It Works

images Chapter 20: Error Handling

20-1. Handling batch errors

Solution

How It Works

20-2. What are the error numbers and messages within SQL?

Solution

How It Works

20-3. How can I implement structured error handling in my queries?

Solution

How It Works

20-4. How can I use structured error handling, but still return an error?

Solution

How It Works

20-5. Nested error handling

Solution

How It Works

20-6. Throwing an error

Solution #1: Use RAISERROR to throw an error

How It Works

Solution #2: Use THROW to throw an error

How It Works

20-7. Creating a user defined error

Solution: Use sp_addmessage to create user defined error message

How It Works

20-7. Removing a user defined error

Solution: Use sp_dropmessage to remove the user defined error message

How It Works

images Chapter 21: Query Performance Tuning

Query Performance Tips

Capturing and Evaluating Query Performance

21-1. Capturing Executing Queries

Solution

How It Works

21-2. Viewing Estimated Query Execution Plans

Solution

How It Works

21-3. Viewing Execution Runtime Information

Solution

How It Works

21-4. Viewing Statistics for Cached Plans

Solution

How It Works

21-5. Viewing Record Counts for Cached Plans

Solution

How It Works

21-6. Viewing Aggregated Performance Statistics Based on Query or Plan Patterns

Solution

How It Works

21-7. Identifying the Top Bottleneck

Solution

How It Works

21-8. Identifying I/O Contention by Database and File

Solution

How It Works

Miscellaneous Techniques

21-9. Parameterizing Ad Hoc Queries

Solution

How It Works

21-10. Forcing Use of a Query Plan

Solution

How It Works

21-11. Applying Hints Without Modifying a SQL Statement

Solution

How It Works

21-12. Creating Plan Guides from Cache

Solution

How It Works

21-13. Checking the Validity of a Plan Guide

Solution

How It Works

21-14. Parameterizing a Nonparameterized Query Using Plan Guides

Solution

How It Works

21-15. Limiting Competing Query Resource Consumption

Solution

How It Works

images Chapter 22: Hints

22-1. Forcing a Join’s Execution Approach

Solution

How It Works

22-2. Forcing a Statement Recompile

Solution

How It Works

22-3. Executing a Query Without Locking

Solution #1: The NOLOCK Hint

Solution #2: The Isolation Level

How It Works

22-4. Forcing an Index Seek

Solution

How It Works

22-5. Forcing an Index Scan

Solution

How It Works

22-6. Optimizing for First Rows

Solution

How It Works

22-7. Specifying Join Order

Solution

How It Works

22-8. Forcing Use of a Specific Index

Solution

How It Works

22-9. Optimizing for Specific Parameter Values

Solution

How It Works

images Chapter 23: Index Tuning and Statistics

Index Tuning

Index Maintenance

23-1. Displaying Index Fragmentation

Solution

How It Works

23-2. Rebuilding Indexes

Solution

How It Works

23-3. Defragmenting Indexes

Solution

How It Works

23-4. Rebuilding a Heap

Solution

How It Works

23-5. Displaying Index Usage

Solution

How It Works

Statistics

23-6. Manually Creating Statistics

Solution

How It Works

23-7. Creating Statistics on a Subset of Rows

Solution

How It Works

23-8. Updating Statistics

Solution

How It Works

23-9. Generating Statistics Across All Tables

Solution

How It Works

23-10. Updating Statistics Across All Tables

Solution

How It Works

23-11. Viewing Statistics Details

Solution

How It Works

23-12. Removing Statistics

Solution

How It Works

images Chapter 24: XML

24-1. Creating an XML Column

Solution

How It Works

24-2. Inserting XML Data

Solution

How It Works

24-3. Validating XML Data

Solution

How It Works

24-4. Verifying the Existence of XML Schema Collections

Solution

How It Works

24-5. Retrieving XML Data

Solution

How It Works

24-6. Modifying XML Data

Solution

How It Works

24-7. Indexing XML Data

Solution

How It Works

24-8. Formatting Relational Data as XML

Solution

How It Works

24-9. Formatting XML Data as Relational

Solution

images Chapter 25: Files, Filegroups, and Integrity

25-1. Adding a Data File or a Log File

Solution

How It Works

25-2. Removing a Data File or a Log File

Solution

How It Works

25-3. Relocating a Data File or a Log File

Solution

How It Works

25-4. Changing a File’s Logical Name

Solution

How It Works

25-5. Increasing the Size of a Database File

Solution

How It Works

25-6. Adding a Filegroup

Solution

How It Works

25-7. Adding a File to a Filegroup

Solution

How It Works

25-8. Setting the Default Filegroup

Solution

How It Works

25-9. Adding Data to a Specific Filegroup

Solution

How It Works

25-10. Moving Data to a Different Filegroup

Solution #1

Solution #2

Solution #3

How It Works

25-11. Removing a Filegroup

Solution

How It Works

25-12. Making a Database or a Filegroup Read-Only

Problem #2

Solution #1

Solution #2

How It Works

25-13. Viewing Database Space Usage

Solution #1

Solution #2

Solution #3

How It Works

25-14. Shrinking the Database or a Database File

Solution #1

Solution #2

How It Works

25.15. Checking Consistency of Allocation Structures

Solution

How It Works

25-16. Checking Allocation and Structural Integrity

Solution

How It Works

25-17. Checking Integrity of Tables in a Filegroup

Solution

How It Works

25-18. Checking Integrity of Specific Tables and Indexed Views

Solution

How It Works

25-19. Checking Constraint Integrity

Solution

How It Works

25-20. Checking System Table Consistency

Solution

How It Works

images Chapter 26: Backup

26-1. Backing Up a Database

Solution

26-2. Compressing a Backup

Solution

How It Works

26-3. Ensuring That a Backup Can Be Restored

Solution

How It Works

26-4. Understanding Why the Transaction Log Continues to Grow

Solution

How It Works

26-5. Performing a Differential Backup

Solution

How It Works

26-6. Backing Up a Single Row or Table

Solution #1: Restore Rows from a Backup

How It Works

Solution #2: Restore Rows from a Database Snapshot

How It Works

26-7. Backing Up Data Files or Filegroups

Solution #1: Perform a File Backup

Solution #2: Perform a Filegroup Backup

How It Works

26-8. Mirroring Backup Files

Solution

How It Works

26-9. Backing Up a Database Without Affecting the Normal Sequence of Backups

Solution

How It Works

26-10. Querying Backup Data

Solution

How It Works

images Chapter 27: Recovery

27-1. Restoring a Database from a Full Backup

Solution

How It Works

27-2. Restoring a Database from a Transaction Log Backup

Solution

How It Works

27-3. Restoring a Database from a Differential Backup

Solution

How It Works

27-4. Restoring a File or Filegroup

Solution

How It Works

27-5. Performing a Piecemeal (PARTIAL) Restore

Solution

How It Works

27-6. Restoring a Page

Solution

How It Works

27-7. Identifying Databases with Multiple Recovery Paths

Solution

images Chapter 28: Principals and Users

Windows Principals

28-1. Creating a Windows Login

Solution

28-2. Viewing Windows Logins

Solution

How It Works

28-3. Altering a Windows Login

Solution

How It Works

28-4. Dropping a Windows Login

Solution

How It Works

28-5. Denying SQL Server Access to a Windows User or Group

Solution

How It Works

SQL Server Principals

28-6. Creating a SQL Server Login

Solution

How It Works

28-7. Viewing SQL Server Logins

Solution

How It Works

28-8. Altering a SQL Server Login

Solution

How It Works

28-9. Managing a Login’s Password

Solution

How It Works

28-10. Dropping a SQL Login

Solution

How It Works

28-11. Managing Server Role Members

Solution

How It Works

28-12. Reporting Fixed Server Role Information

Solution

How It Works

Database Principals

28-13. Creating Database Users

Solution

How It Works

28-14. Reporting Database User Information

Solution

How It Works

28-15. Modifying a Database User

Solution

How It Works

28-16. Removing a Database User from the Database

Solution

How It Works

28-17. Fixing Orphaned Database Users

Solution

How It Works

28-18. Reporting Fixed Database Roles Information

Solution

How It Works

28-19. Managing Fixed Database Role Membership

Solution

How It Works

28-20. Managing User-Defined Database Roles

Solution

How It Works

28-21. Managing Application Roles

Solution

How It Works

images Chapter 29: Securables, Permissions, and Auditing

Permissions Overview

29-1. Reporting SQL Server Assignable Permissions

Solution

How It Works

Server-Scoped Securables and Permissions

29-2. Managing Server Permissions

Solution

How It Works

29-3. Querying Server-Level Permissions

Solution

How It Works

Database-Scoped Sec14urables and Permissions

29-4. Managing Database Permissions

Solution

How It Works

29-5. Querying Database Permissions

Solution

How It Works

Schema-Scoped Securables and Permissions

29-6. Managing Schemas

Solution

How It Works

29-7. Managing Schema Permissions

Solution

How It Works

Object Permissions

29-8. Managing Object Permissions

Solution

How It Works

Managing Permissions Across Securable Scopes

29-9. Determining Permissions to a Securable

Solution

How It Works

29-10. Reporting Permissions by Securable Scope

Solution

How It Works

29-11. Changing Securable Ownership

Solution

How It Works

29-12. Allowing Access to Non-SQL Server Resources

Solution

How It Works

Auditing Activity of Principals Against Securables

29-13. Defining Audit Data Sources

Solution

How It Works

29-14. Capturing SQL Instance–Scoped Events

Solution

How It Works

29-15. Capturing Database-Scoped Events

Solution

How It Works

29-16. Querying Captured Audit Data

Solution

How It Works

29-17. Managing, Modifying, and Removing Audit Objects

Solution

How It Works

images Chapter 30: Objects and Dependencies

30-1. Changing the Name of a Database Object

Solution

How It Works

30-2. Changing an Object’s Schema

Solution

How It Works

30-3. Identifying Object Dependencies

Solution

How It Works

30-4. Identifying Referencing and Referenced Entities

Solution

How It Works

30-5. Viewing an Object’s Definition

Solution 1

Solution 2

How It Works

30-6. Returning a Database Object’s Name, Schema Name, and Object ID

Solution 1

Solution 2

How It Works

images Index

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset