0% found this document useful (0 votes)
40 views

SQL Server 2012: Common Tasks and Solutions For Non-SQL Administrators

Uploaded by

Ovidiu Manolescu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

SQL Server 2012: Common Tasks and Solutions For Non-SQL Administrators

Uploaded by

Ovidiu Manolescu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 60

SQL Server 2012: Common Tasks

and Solutions for Non-SQL


Administrators
Conditions and Terms of Use
Microsoft Confidential
This training package is proprietary and confidential, and is intended only for uses described in the training materials. Content and software is provided to you under a Non-
Disclosure Agreement and cannot be distributed. Copying or disclosing all or any portion of the content and/or software included in such packages is strictly prohibited.
The contents of this package are for informational and training purposes only and are provided "as is" without warranty of any kind, whether express or implied, including
but not limited to the implied warranties of merchantability, fitness for a particular purpose, and non-infringement.
Training package content, including URLs and other Internet website references, is subject to change without notice. Because Microsoft must respond to changing market
conditions, the content should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information presented
after the date of publication. Unless otherwise noted, the 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.

Copyright and Trademarks


© 2013 Microsoft Corporation. All rights reserved.
Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering subject matter in this document. Except as expressly
provided in 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.
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.
For more information, see Use of Microsoft Copyrighted Content at
http://www.microsoft.com/about/legal/permissions/
Microsoft®, Internet Explorer®, Outlook®, SkyDrive®, Windows Vista®, Zune®, Xbox 360®, DirectX®, Windows Server® and Windows® are either registered
trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. Other Microsoft products mentioned herein may be 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.
How to View This Presentation
Switch to Notes Page view:
Click View on the ribbon and select Notes Page
Use page up or page down to navigate
Zoom in or out as needed

In the Notes Page view you can:


Read any supporting text, now or after the delivery
Add your own notes

Take the presentation files home with you

Microsoft Confidential 3
Module 5: Managing SQL
Server Databases

Module Overview

Microsoft Confidential 4
Module 5: Managing SQL
Server Databases

Section 1: System and User Lesson 1: Understanding System


Databases and User Databases

Microsoft Confidential 5
What is a Database?

• A collection of objects.

Server 1
INST1 Master INST2

AdventureWorks2012
Model
Stored
Tables Views
Procedures
MSDB
Functions

TempDB

Microsoft Confidential 6
System Databases

MSDB ––Used
Model
Resource
TempDB
Master by information.
Template.
–System SQL
– Temporary
Hidden Server
database. Agent.
user objects.

Master
INST1

Model
Server 1 Resource
MSDB

TempDB

Microsoft Confidential 7
Is it supported to directly update system objects?

Microsoft Confidential 8
Demonstration: Viewing
System Databases
User Databases

• A maximum of 32,767 databases.

INST1

AdventureWorks2012

Person.Address
Server 1

Microsoft Confidential 10
Demonstration : Create a
User Database
Lab: Create a User Database
Lesson Knowledge Check

How many system database does a SQL Server instance have?

What is the master database used for?

How many user databases can a SQL Server instance have?

Microsoft Confidential
Module 5: Managing SQL
Server Databases

Section 1: System and User Lesson 2: Understanding Files


Databases and Filegroups

Microsoft Confidential 15
Database Files Logical_file_name – mydb.
OS_file_name
-E:\MSSQL11….\DATA
\MyDB.mdf
Stores the data.
Asynchronous,
Random, Database Files
Read, Write Stores changes to
the data.
Synchronous,
Sequential, Write.
Stores data and info Data Log Extention- .ldf
about other files.
Extention - .mdf

Stores data.
Primary Secondary Extention - .ndf

Microsoft Confidential 16
Database Filegroups

Data Log

Primary Secondary2 Secondary Secondary3

Primary Filegroup User-defined Filegroup User-defined


Filegroup2

Microsoft Confidential 17
Demonstration: Add a file
and a filegroup to a database
Lab: Add files and filegroup
Lesson Knowledge Check

What are the two types of filegroup?

Which filegroup is the transaction log file a part of?

Can you create more than one transaction log file for a database?

Microsoft Confidential
Module 5: Managing SQL
Server Databases

Section 2: Database Lesson 1: How to configure


Configuration automatic options for databases?

Microsoft Confidential 22
Auto Growth
•Controls how the file grows
Manage
Proactively

AutoGrowth
Exponential Constant
growth.
File Growth growth.
Not recommended. Recommended!

Percent Megabytes

Microsoft Confidential
Auto Shrink
• Automatically reduces the size and compacts the data and log files.

AutoShrink

Data File Log File

Shrinks when Shrinks when a


records are part of the log file
deleted or purged is marked as
inactive.

Microsoft Confidential
What are the performance implications of auto growth
and auto shrink options?

Microsoft Confidential
Best Practices for auto growth and auto shrink

• Use auto-growth as contingency for unexpected growth

Proactively monitor available space

Expand them manually when necessary

• Configure auto-growth with a fixed size growth increment of less than 1 GB

Exact value depends on your environment

Test it

• Leave Auto Shrink option to the default value (False)

Microsoft Confidential
Auto Close

• Shuts down the database after the last user exits.

• OFF by default.

• Best Practice – Leave this option to the default value (False).

Microsoft Confidential
Auto Create Statistics

• Automatically creates statistics for columns in a predicate.

• ON by default.

• Best Practice – Leave this option to the default value (True).

Microsoft Confidential
Auto Update Statistics

• Automatically updates the statistics

• ON by default.

• Best Practice – Leave this option to the default value (True).

Microsoft Confidential
Auto Update Statistics Asynchronously

• Updates the statistics asynchronously.

• Current query uses stale statistics.

• OFF by default.

• If AUTO_UPDATE_STATISTICS_ASYNC is to be turned ON then

AUTO_UPDATE_STATISTICS needs to be ON as well.


• Best Practice

Leave this option to the default value (False).

Microsoft Confidential
Demonstration: Configuring
auto options
Lesson Knowledge Check

What is the recommended value for auto shrink and why?


What is the recommended value for auto create statistics and auto update statistics?

Microsoft Confidential
Module 5: Managing SQL
Server Databases

Section 2: Database Lesson 2: How to configure other


Configuration databases options?

Microsoft Confidential 34
Recovery Models

Recovery Model

Simple Bulk Logged Full

Controls the behavior of the Transaction log


• What's written

• How it is backed up and maintained

• How much data is recoverable


Microsoft Confidential
Page Verify
• Discovers damaged database pages.

Page Verify
Deprecated
in SQL 2012 Recommended!

Torn Page
None Checksum
Detection

Microsoft Confidential
Compatibility Level
• Affects database behavior.

Compatibility Level Set to latest


after thorough
testing

SQL 2005 SQL 2008 SQL 2012


(90) (100) (110)

Microsoft Confidential
Is compatibility level 80 (SQL Server 2000) supported in SQL Server 2012?

Microsoft Confidential
Collation
• Sorting rules, case and accent sensitivity
* Latin1_General = ASCII encoding
* CP1 = Code Page 1
* CI = Case Insensitive
* AS = Accent Sensitive

Microsoft Confidential
Demonstration: Configuring
database options
Lab: Configure a user
database as per best practices
Lesson Knowledge Check

When should you use simple recovery model?

Should the compatibility level be changed for a database after an upgrade?

Is it ok to leave the compatibility level to a lower level as a permanent solution?

What is the default page verify value for a database in SQL 2012?

Microsoft Confidential
Module 5: Managing SQL Server
Databases

Section 3: Data Storage Lesson 1: How to store data in


SQL Server?

Microsoft Confidential 45
Storage Best Practices

• Separate physical disks for user data, log and tempDB

• Preferred file allocation unit (FAU) size – 64KB

64KB 64KB 64KB


User Data User Log TempDB
User User Data
Data Log
User Data User Log
TempDB Log
User Data User Log

Microsoft Confidential
Storage Best Practices

• Up-to-date HBA drivers, firmware

• Design for ideal disk latency

Ideal latency <10 ms Ideal Latency < 1 ms

64KB 64KB 64KB


User Data User Log TempDB
User User Data
Data Log
User Data User Log
TempDB Log
User Data User Log

Microsoft Confidential
Tempdb Best Practices

• Create multiple tempdb data files

For <= 8 logical processors, # data files = # logical processors

For > 8 logical processors, start with 8 and increase by 4 if contention continues
• Set the size of tempdb to an appropriate value

• Ensure all tempdb data files are the same size

• Implement trace flags –T1117 and -T1118

Microsoft Confidential
Partition Alignment Best Practices

• Required only on disks formatted before Windows Server 2008.

Default value for Windows Server 2008 and above = 1024KB


• Partitions created on Windows Server 2003 and lower are not aligned by default.

Partition alignment must be explicitly performed.


• Performance gains of up to 30% seen in test environments.

Microsoft Confidential
Instant File Initialization

• Initializes data files instantaneously.

• This allows faster execution of operations.

• Log files are not initialized.

• Requires “Perform Volume Maintenance Tasks” right.

If your SQL Server service is running as a local administrator this permission


already exists.
• Available in all SQL Server editions.

• Not available when Transparent Data Encryption is enabled.


Microsoft Confidential
Are there any security considerations for instant file initialization?

Microsoft Confidential
Lab: Configure tempdb
database
Lesson Knowledge Check

What is the preferred file allocation unit size for SQL Server?

How many tempdb data files should you have?

Is there any down-side in implementing trace flags 1117 and 1118?

Microsoft Confidential
Module 5: Managing SQL Server
Databases

Section 4: SQL Server Security Lesson 1: Authenticating and


authorizing SQL users

Microsoft Confidential 55
Login

• Allows connection to the database engine

• Types:

SQL

Windows

Microsoft Confidential
User

• Access to the database

• Can be mapped to a valid login

• Specific to a single database

Microsoft Confidential
Logins and Users

Network connection request/pre-login handshake


Connect to SQL Server
Login authentication request to SQL Server

Establish login credentials

Switch to a database and authorize access

Establish a database context


Attempt to perform some action

Verify permissions for all actions


against a database

Microsoft Confidential
DBO and Guest User
DBO
• Performs all activities in the database

• Members of sysadmin role, sa login

and database owner are mapped to DBO


• Cannot be deleted

Guest
• Allows logins without user accounts to access database

• Disabled by default in user databases

• Cannot be dropped but you can prevent it from accessing a database

• Must NOT be disabled from master and tempdb

Microsoft Confidential
What is the guest user useful for?

Microsoft Confidential
Demonstration: Managing
guest user access
Roles

Server Roles

• Fixed server roles

• User-defined server roles (new in SQL Server 2012)

Database Roles

• Fixed database roles

• User-defined database roles

Application roles

• Assign rights to applications instead of users

Microsoft Confidential
What is the public server role?

Microsoft Confidential
Demonstration: Create a
user-defined server role
Lesson Knowledge Check

Can you create a user without being mapped to a login?

Can you drop a guest user?

Why must you take care while granting permissions to Public server role?

Microsoft Confidential
67

Microsoft Confidential

You might also like