1. Trang chủ
  2. » Công Nghệ Thông Tin

professional microsoft sql server 2012 administration

931 368 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Professional Microsoft SQL Server 2012 Administration
Tác giả John Wiley & Sons, Inc.
Trường học Not specified
Chuyên ngành Computer Science
Thể loại Textbook
Năm xuất bản 2012
Thành phố Indianapolis
Định dạng
Số trang 931
Dung lượng 6,65 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Licensing 18Summary 20 CHAPTER 2: INSTALLING SQL SERVER 2012 BEST PRACTICES 21 Installing Analysis Services 40 Installing PowerPivot for SharePoint 43... 53 Independent Software Vendors

Trang 2

Indianapolis, IN 46256

www.wiley.com

Copyright © 2012 by John Wiley & Sons, Inc., Indianapolis, Indiana

Published simultaneously in Canada

No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means,

electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108

of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization

through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers,

MA 01923, (978) 750-8400, fax (978) 646-8600 Requests to the Publisher for permission should be addressed to the

Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011,

fax (201) 748-6008, or online at http://www.wiley.com/go/permissions.

Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with

respect to the accuracy or completeness of the contents of this work and specifi cally disclaim all warranties, including

without limitation warranties of fi tness for a particular purpose No warranty may be created or extended by sales or

promotional materials The advice and strategies contained herein may not be suitable for every situation This work

is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional

services If professional assistance is required, the services of a competent professional person should be sought Neither

the publisher nor the author shall be liable for damages arising herefrom The fact that an organization or Web site is

referred to in this work as a citation and/or a potential source of further information does not mean that the author or the

publisher endorses the information the organization or Web site may provide or recommendations it may make Further,

readers should be aware that Internet Web sites listed in this work may have changed or disappeared between when this

work was written and when it is read.

For general information on our other products and services please contact our Customer Care Department within the

United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.

Wiley publishes in a variety of print and electronic formats and by print-on-demand Some material included with

standard print versions of this book may not be included in e-books or in print-on-demand If this book refers to media

such as a CD or DVD that is not included in the version you purchased, you may download this material at

http://booksupport.wiley.com For more information about Wiley products, visit www.wiley.com.

Library of Congress Control Number: 2012933629

Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Wrox Programmer to Programmer, and related trade dress

are trademarks or registered trademarks of John Wiley & Sons, Inc and/or its affi liates, in the United States and other

countries, and may not be used without written permission Microsoft and SQL Server are registered trademarks of

Microsoft Corporation All other trademarks are the property of their respective owners John Wiley & Sons, Inc., is not

associated with any product or vendor mentioned in this book.

Trang 3

Licensing 18

Summary 20

CHAPTER 2: INSTALLING SQL SERVER 2012 BEST PRACTICES 21

Installing Analysis Services 40

Installing PowerPivot for SharePoint 43

Trang 4

Post-Install Confi guration 45

tempdb 47

Troubleshooting a Failed Install 52 Summary 52

Why Upgrade to SQL Server 2012? 53

Independent Software Vendors and SQL Community Contributions 54

Upgrading to SQL Server 2012 55

In-Place Upgrade versus Side-By-Side Upgrade Considerations 58

Unsupported and Discontinued Features in SQL Server 2012 67

SQL Server Component Considerations 68

Summary 70

CHAPTER 4: MANAGING AND TROUBLESHOOTING

Confi guration and Administration Tools 71

Trang 5

CONTENTS

Automating SQL Server with SQL Server Agent 111

Confi guring SQL Server Agent 130

Trang 6

Connection Properties 134

Architecture 135Security 135

SQL Server Service Broker Versus Other Message Queues 148

Confi guring SQL Server Service Broker 149

Contracts 151Queues 152Services 153Routes 154Priorities 156

Using SQL Server Service Broker 157

Trang 7

Summary 194

Creating Solutions and Projects 198

Trang 8

CHAPTER 10: CONFIGURING THE SERVER FOR OPTIMAL

PERFORMANCE 233

What Every DBA Needs to Know About Performance 234

What the Developer DBA Needs to Know About Performance 237

Users 237

What the Production DBA Needs to Know About Performance 238

CPU 241

x64 242Cache 242Hyper-threading 243Multicore 244

Memory 248

I/O 251

Network 252Disks 252

Fragmentation 269

Summary 271

The Silent Killer: I/O Problems 274

Trang 9

CONTENTS

Table and Index Partitioning 279

Memory Considerations and Enhancements 302

Using Resource Governor from SQL Server 2012

Summary 315

Choosing the Appropriate Monitoring Tools 319

Trang 10

Monitoring with Dynamic Management Views and Functions 376

Query Plan and Query Text for Currently Running Queries 385

Viewing Data Collected by the System Data Collection Sets 388

SQL Server Standard Reports 393 System Center Management Pack 395 SQL Server Best Practice Analyzer 396

Summary 397

Physical Query Processing Part One: Compilation

Compilation 400Recompilation 401

Trang 11

CONTENTS

Optimization 412

Physical Query Processing Part Two: Execution 417

Fragmentation 438

Statistics 439

Query Processing Enhancements on Partitioned Tables and Indexes 444

Gathering Query Plans for Analysis with SQL Trace 446

Summary 447

Noteworthy Index-Related Features in SQL Server 449

Index Features from SQL Server 2008R2, SQL Server 2008,

Partitioned Tables and Indexes 455

Improving Query Performance with Indexes 464

Trang 12

Multiple Publishers, Single Subscriber 480

Clustering and Your Organization 510

Choosing SQL Server 2012 Clustering for the Right Reasons 512

Clustering: The Big Picture 514

Upgrading SQL Server Clustering 520

Getting Prepared for Clustering 523

Clustering Windows Server 2008 527

Installing Windows Server 2008 Failover Clustering 528

Trang 13

CONTENTS

Clustering Microsoft Distributed Transaction Coordinator 532

Installing the Service Pack and Cumulative Updates 540

Managing and Monitoring the Cluster 542

Troubleshooting Cluster Problems 543

How to Approach Windows Failover Clustering

Overview of Backup and Restore 559

Trang 14

Maintenance Time Window 583

Developing and Executing a Backup Plan 585

Log Shipping Deployment Scenarios 608

Monitoring and Troubleshooting 624

Trang 15

CONTENTS

Switching Roles from the Primary to Secondary Servers 630

Redirecting Clients to Connect to the Secondary Server 632

Integrating Log Shipping with Other High-Availability Solutions 634

Upgrading to SQL Server 2012 Log Shipping 638

Summary 639

Overview of Database Mirroring 641 Operating Modes of Database Mirroring 643 Database Mirroring In Action 645

Initial Synchronization Between Principal and Mirror 653

High-Safety Operating Mode Without Automatic Failover 655High-Safety Operating Mode with Automatic Failover 655

Database Mirroring and SQL Server 2012 Editions 658 Database Mirroring Catalog Views 658

sys.database_mirroring 658sys.database_mirroring_witnesses 660sys.database_mirroring_endpoints 660

Database Mirroring Role Change 661

Trang 16

Mirror Is Lost 668

Monitoring Database Mirroring 670

Setting Thresholds on Counters and Sending Alerts 676

Troubleshooting Database Mirroring 678

Preparing the Mirror Server for Failover 681

Mirroring Multiple Databases 685 Database Mirroring and Other High-Availability Solutions 686

Database Mirroring versus Transactional Replication 687

Mirroring Event Listener Setup 688

Summary 693

CHAPTER 20: INTEGRATION SERVICES ADMINISTRATION

A Tour of Integration Services 696

Administration of the Integration Services Service 699

Administration of Integration Services Packages in

Deployment 709

Trang 17

CONTENTS

Administration of Integration Services Packages

in Project Deployment Model 712

Running Packages with the SQL Server Import

Running Packages with DTExecUI (Package

Running Packages with the Execute Package Tool

Applying Security to Integration Services 725

Summary 728

CHAPTER 21: ANALYSIS SERVICES ADMINISTRATION

Administering Analysis Services Server 733

Administering Analysis Services Databases 737

Backing Up and Restoring Analysis Services Databases 745

Analysis Services Performance Monitoring and Tuning 749

Using Flight Recorder for After-the-Fact Analysis 751

Management of Analysis Services MOLAP Model Storage 752

Trang 18

Partition Confi guration 753

Applying Security to Analysis Services in the MOLAP Model 758

Applying Security to Analysis Services in the Tabular Model 762

Summary 763

CHAPTER 22: SQL SERVER REPORTING SERVICES

SQL Server Reporting Services Confi guration Manager 765

Trang 19

CONTENTS

What’s Missing in SQL Azure 854

Trang 20

Active Secondary for Secondary Read-Only 875

Performance 878

Backup on the Secondary Replica 879

Monitoring and Troubleshooting 883 Summary 884

INDEX 885

Trang 21

SQL SERVER 2012 REPRESENTS A SIZABLE jump forward in scalability, performance, and usability for the DBA, developer, and business intelligence (BI) developer It is no longer unheard of to have 40-terabyte databases running on a SQL Server SQL Server administration used to just be the job

of a database administrator (DBA), but as SQL Server proliferates throughout smaller companies, many developers have begun to act as administrators and BI developers as well In addition, some of the new features in SQL Server are more developer-centric, and poor confi guration of these features can result in poor performance SQL Server now enables all roles through signifi cantly improved data tools experiences, better security integration, and drastic improvements in data integration,

administration, availability, and usability Professional Microsoft SQL Server2012 Administration

is a comprehensive, tutorial-based book to get you over the learning curve of how to confi gure and administer SQL Server 2012

WHO THIS BOOK IS FOR

Whether you’re an administrator or developer using SQL Server, you can’t avoid wearing a DBA hat at some point Developers often have SQL Server on their own workstations and must provide guidance to the administrator about how they’d like the production confi gured Oftentimes, they’re responsible for creating the database tables and indexes Administrators or DBAs support the

production servers and often inherit the database from the developer

This book is intended for developers, DBAs, and casual users who hope to administer or may

already be administering a SQL Server 2012 system and its business intelligence features, such as

Integration Services This book is a professional book, meaning the authors assume that you know

the basics about how to query a SQL Server and have some rudimentary concepts of SQL Server For example, this book does not show you how to create a database or walk you through the

installation of SQL Server using the wizard Instead, the author of the installation chapter provides insight into how to use some of the more advanced concepts of the installation Although this book does not cover how to query a SQL Server database, it does cover how to tune the queries you’ve already written

HOW THIS BOOK IS STRUCTURED

This book follows the same basic path of previous editions, with one major change The author team has been selected specifi cally to focus on their areas of expertise The authors are the same people seen at major conferences and delivering top-tier services for topics such as performance tuning,

business intelligence, database design, high availability, PowerShell, and even SQL Azure! This

approach has led to unprecedented focus on quality and content with even better access to folks at Microsoft to drive the content in this new release of SQL Server Hundreds of Connect items were

Trang 22

fi led and resolved as a direct result of the work of this author team pushing for higher quality for

you Connect is the primary method for industry professionals and SQL Server MVPs to provide bug

reports and vote on feature requests from Microsoft It’s a great outlet for improving the product

This edition of the book covers all the same great information covered in the previous edition, but

with loads of new content added for SQL Server 2012, which includes numerous new features to

improve the DBA’s life In short, the new version of SQL Server focuses on improving your effi ciency,

the scale of your server, and the performance of your environment, so you can do more in much less

time, and with fewer resources and people The following is a brief description of each chapter

Chapter 1: SQL Server 2012 Architecture — The book starts off with a review of the new

architecture changes and focuses on the overall components that make up SQL Server 2012

Chapter 2: Installing SQL Server 2012 Best Practices — This chapter reviews the different

ways to install SQL Server 2012 and covers best practices for the process

Chapter 3: Upgrading SQL Server 2012 Best Practices — This chapter covers upgrading to

SQL Server 2012 and best practices to keep in mind while upgrading Choosing the best

upgrade method, requirements, and benefi ts of upgrading are also covered

Chapter 4: Managing and Troubleshooting the Database Engine — This chapter focuses

on the database engine and working through challenges as they arise It also covers

management and tools appropriate for the task

Chapter 5: Automating SQL Server — This chapter focuses on automation throughout the

SQL Server 2012 world including jobs, PowerShell, and other ways to automate

Chapter 6: Service Broker in SQL Server 2012 — Service Broker is a great tool to handle

messaging inside the database This chapter covers setup, operations, and management of

Service Broker

Chapter 7: SQL Server CLR Integration — SQL Server and NET work together inside the

Common Language Runtime This chapter focuses on integrating NET and the CLR with

SQL Server, including assemblies and other options

Chapter 8: Securing the Database Instance — Security is critical in the database engine

This chapter helps you outline and implement your security plan

Chapter 9: Change Management — Managing change is paramount to operational stability

This chapter focuses on features in SQL Server that support change management

Chapter 10: Confi guring the Server for Optimal Performance — Confi guring and setting

up your server properly is important for maximizing application and database performance

This chapter discusses storage, server options, and other settings critical to system

performance

Chapter 11: Optimizing SQL Server 2012 — This chapter covers topics that help the reader

review and analyze performance It also focuses on settings and confi guration items that

improve SQL Server performance

Chapter 12: Monitoring Your SQL Server — SQL Server is critically important to make

sure you keep performance where it needs to be This chapter covers the important aspects

and tools used to monitor SQL Server 2012

Trang 23

xxxix

Chapter 13: Performance Tuning T-SQL — Writing effi cient and effective T-SQL is

important to have good application performance and scalability This chapter explains how

to optimize your T-SQL to make it more effi cient It focuses on how SQL Server’s engine and internals read and execute your queries You then learn how to take advantage of areas where this process can be tweaked and best practices can be leveraged

Chapter 14: Indexing Your Database — Indexing is critical to successful database

performance This chapter discusses considerations and strategies for effective indexing for your database

Chapter 15: Replication — Replication is a key feature in SQL Server for keeping tables

and databases in sync and supporting applications This chapter will cover the types of replication, how to set them up, and the pros and cons of each

Chapter 16: Clustering SQL Server 2012 — Clustering has been improved again in SQL

2012 and this chapter takes the reader through the setup, confi guration, and testing of your clustered confi guration

Chapter 17: Backup and Recovery — Backup and recovery is critical to the success of a

continuity plan and operational achievement This chapter outlines the options in SQL Server for backups and recoveries, and provides recommendations to make the most of these features

Chapter 18: SQL Server 2012 Log Shipping — This chapter goes through setup,

confi guration, and administration of log shipping

Chapter 19: Database Mirroring — There is more functionality in this release for

availability than ever before This chapter covers new and existing features to help you keep your systems online for your organization

Chapter 20: Integration Services Administration and Performance Tuning — Integration

is the key to making sure systems stay in sync This chapter focuses on administering and tuning this great feature in SQL Server

Chapter 21: Analysis Services Administration and Performance Tuning — Analysis Services

is the Online Analytical Processing (OLAP) product of choice and cannot be ignored by data administrators This chapter helps you get prepared

Chapter 22: SQL Server Reporting Services Administration — Reporting Services is often

administered by the DBA and this book prepares you no matter what your role to handle those Reporting Services challenges

Chapter 23: SQL Server 2012 SharePoint 2010 Integration — SharePoint is a bigger part of

SQL Server than ever This chapter covers what you need to know about how SharePoint

2010 integrates with SQL Server so you can be prepared to interact with that team or take

on some SharePoint database administration responsibilities yourself

Chapter 24: SQL Azure Administration and Confi guration — This chapter introduces the

reader to SQL Server Azure and gets you up and running on this exciting new cloud platform

Chapter 25: AlwaysOn Availability Groups — This chapter focuses on the availability

group feature in Always On These groups allow you to control instances and servers

as groups and assign prioritization and additional fl exibility to how failover and high availability are handled in your environment

Trang 28

PowerPivot for SharePoint enable users to be closer to the data at all times and to seek and

deliver intelligence more rapidly than ever

Integration and collaboration: New integrations for reporting services, PowerPivot, and

claims authentication in SharePoint 2010 provide a strong foundation for the signifi cant focus

on self-service in this release The new BI semantic model approach extends into the cloud as

well with reporting services now in SQL Azure and more features promised to come

NEW IMPORTANT FEATURES IN 2012

There are a number of new things that you will be excited about, depending on your role and

how you use SQL Server This section touches on the features you should be checking out and

getting your hands on Many of these features are quick to get up and running, which is exciting

for those readers who want to begin delivering impact right away

Production DBA

Production DBAs are a company’s insurance policy that the production database won’t go down

If the database does go down, the company cashes in its insurance policy in exchange for a

recovered database The Production DBA also ensures that the server performs optimally and

promotes database changes from development to quality assurance (QA) to production New

features include the following:

AlwaysOn: Availability functionality including availability groups and the ability to fi le

over databases in groups that mimic applications This includes new readable secondary

servers, a big enhancement

FileTable: Additional fi le-based data storage

Extended Events: A new functionality built into SQL Server 2012 that provides lightweight

and extensive tracing capability

Improved functionality and stability in SQL Server Management Studio (now in Visual

Studio 2010 shell)

Distributed replay capabilities

Improved debugging functionality including expression support and breakpoint validation

Columnstore indexes for optimizing large data volumes

Improved statistics algorithm for very large databases

Improved compression and partitioning capabilities

Development DBA

Since the release of SQL Server 2000, there has been a trend away from full-time Production DBAs,

and the role has merged with that of the Development DBA The trend may have slowed, though, with

laws such as Sarbanes-Oxley, which require a separation of power between the person developing

Trang 29

the change and the person implementing the change In a large organization, a Production DBA may fall into the operations department, which consists of the network of administrators and Windows-

support administrators In other instances, a Production DBA may be placed in a development group This removes the separation of power that is sometimes needed for regulatory reasons

Development DBAs play a traditional role in an organization They wear more of a developer’s hat

and are the development staff’s database experts and representatives This administrator ensures

that all stored procedures are optimally written and that the database is modeled correctly, both

physically and logically The development DBA also may be the person who writes the migration

processes to upgrade the database from one release to the next The Development DBA typically does not receive calls at 2:00 A.M like the Production DBA might for failed backups or similar problems Things development DBAs should be excited about in this new release include the following:

New TSQL and spatial functionalitySQL Server data tools: A new TSQL development environment integrated with Visual Studio

New DAX expression language that provides Excel-like usability with the power of multidimensional capabilities

New tabular model for Analysis Services: Provides in-memory OLAP capabilities in a quick time to value format

The Development DBA typically reports to the development group and receives requests from a

business analyst or another developer In a traditional sense, Development DBAs should never have modifi cation access to a production database They should, however, have read-only access to the production database to debug in a time of escalation

Business Intelligence DBA and Developer

The Business Intelligence (BI) DBA is a new role that has evolved due to the increased capabilities

of SQL Server In SQL Server 2012, BI grew to be an incredibly important feature set that many

businesses could not live without The BI DBA or developer is an expert at these features This release is

a treasure trove of new BI functionality including new enhancements to Reporting Services Integration, data exploration tools such as Power View, and a dramatic set of enhancements that make PowerPivot easier and more accessible than ever Additionally, the new Tabular model in SSAS delivers the ability to create new PowerPivot-like “in memory” BI projects to SharePoint for mass user consumption

Development BI DBAs specialize in the best practices, optimization, and use of the BI toolset In

a small organization, a Development BI DBA may create your SSIS packages to perform Extract

Transform and Load (ETL) processes or reports for users In a large organization, developers create the SSIS packages and SSRS reports The Development BI DBA is consulted regarding the physical implementation of the SSIS packages and Analysis Services (SSAS) cubes Development BI DBAs

may be responsible for the following types of functions:

Model\consult regarding Analysis Services cubes and solutionsCreate reports using Reporting Services

Create\consult around ETL using Integration ServicesDevelop deployment packages to be sent to the Production DBA

Trang 30

These responsibilities, coupled with these following new features make for an exciting time for the

BI-oriented folks:

Rapid data discovery with Power View and PowerPivot

Managed Self-Service BI with SharePoint and BI Semantic Model

Credible, consistent data with Data Quality Services and Master Data Management

capabilities

Robust DW solutions with Parallel Data Warehouse and Reference Architectures

SQL SERVER ARCHITECTURE

Many people just use SQL Server for its classic use: to store data This release of SQL Server focuses

on expanding the capabilities that were introduced in SQL Server 2008 R2, which was largely a

self-service business intelligence and SharePoint feature release The additional functionality in

SQL Server 2012 not only enables but encourages users to go beyond simply storing data in SQL

Server; this release can now be the center of an entire data strategy New tools such as Power View

and PowerPivot quickly integrate on top of SQL Server and can provide an easy user interface (UI)

for SQL Server and other systems’ data This section covers the primary fi le types in SQL Server

2012, fi le management, SQL Client, and system databases It also covers an overview of schemas,

synonyms, and Dynamic Management Objects Finally, it also goes into the new SQL Server 2012

data types

Database Files and Transaction Log

The architecture of database and transaction log fi les remains relatively unchanged from prior

releases Database fi les serve two primary purposes depending on their type Data fi les hold the

data, indexes, and other data support structure within the database Log fi les hold the data from

committed transactions to ensure consistency in the database

Database Files

A database may consist of multiple fi legroups Each fi legroup must contain one or more physical data

fi les Filegroups ease administrative tasks for a collection of fi les Data fi les are divided into 8KB

data pages, which are part of 64KB extents You can specify how full each data page should be with

the fi ll factor option of the create/alter index T-SQL command In SQL Server 2012 Enterprise

Edition, you continue to have the capability to bring your database partially online if a single fi le is

corrupt In this instance, the DBA can bring the remaining fi les online for reading and writing, and

users receive an error if they try to access the other parts of the database that are offl ine

In SQL 2000 and before, the largest row you could write was 8060 bytes The exceptions to this limit

are text, ntext, image, varchar(max), varbinary(max), and nvarchar(max) columns, which

may each be up to 2 gigabytes and are managed separately Beginning with SQL 2005, the 8KB limit

applies only to those columns of fi xed length The sum of fi xed-length columns and pointers for other

column types must still be less than 8060 bytes per row However, each variable-length column may

be up to 8KB in size allowing for a total row size of well over 8060 bytes If your actual row size

Trang 31

exceeds 8060 bytes, you may experience some performance degradation because the logical row must now be split across multiple physical 8060-byte rows.

Transaction Log

The purpose of the transaction log is to ensure that all committed transactions are persisted in the database and can be recovered, either through rollback or point in time recovery The transaction

log is a write-ahead log As you make changes to a database in SQL Server, the data is written to

the log, and then the pages that need to be changed are loaded into memory (specifi cally into the

write buffer portion of the buffer pool) The pages are then dirtied by having the changes written

to them Upon checkpoint, the dirty pages are written to disk, making then now clean pages which

no longer need to be part of the write buffer This is why you may see your transaction log grow

signifi cantly in the middle of a long-running transaction even if your recovery model is set to simple (Chapter 17, “Backup and Recovery” covers this in much more detail.)

SQL Native Client

The SQL Native Client is a data-access method that shipped with SQL Server 2005 and was

enhanced in 2012 and is used by both OLE DB and ODBC for accessing SQL Server The SQL

Native Client simplifi es access to SQL Server by combining the OLE DB and ODBC libraries into a single access method The access type exposes these features in SQL Server:

Database mirroringAlways On readable secondary routingMultiple Active Result Sets (MARS)Snapshot isolation

Query notifi cationXML data type supportUser-defi ned data types (UDTs)Encryption

Performing asynchronous operationsUsing large value types

Performing bulk copy operationsTable-value parameters

Large CLR user-defi ned typesPassword expiration

In these features, you can use the feature in other data layers such as Microsoft Data Access

Components (MDAC), but it takes more work MDAC still exists, and you can use it if you don’t

need some of the new functionality of SQL Server 2008\2012 If you develop a COM-based

application, you should use SQL Native Client; and if you develop a managed code application

Trang 34

model Database

model is a system database that serves as a template when SQL Server creates a new database As

each database is created, SQL Server copies the model database as the new database The only time

this does not apply is when you restore or attach a database from a different server

If a table, stored procedure, or database option should be included in each new database that you

create on a server, you may simplify the process by creating the object in model When the new

database is created, model is copied as the new database, including the special objects or database

settings you have added to the model database If you add your own objects to model, it should be

included in your backups, or you should maintain a script that includes the changes

msdb Database

msdb is a system database that contains information used by SQL Server agent, log shipping, SSIS,

and the backup and restore system for the relational database engine The database stores all the

information about jobs, operators, alerts, and job history Because it contains this important

system-level data, you should back up this database regularly

Schemas

Schemas enable you to group database objects together You may want to do this for ease of

administration because you can apply security to all objects within a schema Another reason to

use schemas is to organize objects so that the consumers may fi nd the objects they need easily For

example, you may create a schema called HumanResource and place all your employee tables and

stored procedures into it You could then apply security policies on the schema to allow appropriate

access to the objects contained within it

When you refer to an object, you should always use the two-part name The dbo schema is the default

schema for a database An Employee table in the dbo schema is referred to as dbo.Employee Table names

must be unique within a schema You could create another table called Employee in the HumanResources

schema It would be referred to as HumanResources.Employee This table actually exists in the

AdventureWorks sample database for SQL Server 2012 (All SQL Server 2012 samples must be

downloaded and installed separately from wrox.com.) A sample query using the two-part name follows:

SELECT BusinessEntityID, JobTitle

FROM HumanResources.Employee

Prior to SQL 2005, the fi rst part of the two-part name was the user name of the object owner The

problem with that implementation was related to maintenance If a user who owned objects were

to leave the company, you could not remove that user login from SQL Server until you ensured that

all the objects owned by the user were changed to a different owner All the code that referred to

the objects had to be changed to refer to the new owner By separating ownership from the schema

name, SQL 2005 through 2012 removes this maintenance problem

Synonyms

A synonym is an alias, or alternative name, for an object This creates an abstraction layer between

the database object and the consumer This abstraction layer enables you to change some of the

physical implementation and isolate those changes from the consumer The following example is

Trang 36

sys.dm_io_virtual_file_stats(DB_ID(‘AdventureWorks’),

FILE_ID(‘AdventureWorks_Data’))

Many new DMV’s and DMF’s exist in SQL Server 2012 These views focus on improved insight

into new and existing areas of functionality and include the following:

AlwaysOn Availability Groups Dynamic Management Views and Functions

Change Data Capture Related Dynamic Management Views

Change Tracking Related Dynamic Management Views

Common Language Runtime Related Dynamic Management Views

Database Mirroring Related Dynamic Management Views

Database-Related Dynamic Management Views

Execution-Related Dynamic Management Views and Functions

SQL Server Extended Events Dynamic Management Views

FileStream and FileTable Dynamic Management Views

Full-Text Search and Semantic Search Dynamic Management Views and Functions

Index-Related Dynamic Management Views and Functions

I/O-Related Dynamic Management Views and Functions

Object-Related Dynamic Management Views and Functions

Query Notifi cations Related Dynamic Management Views

Replication-Related Dynamic Management Views

Resource Governor Related Dynamic Management Views

Security-Related Dynamic Management Views and Functions

Server-Related Dynamic Management Views and Functions

Service Broker Related Dynamic Management Views

Spatial Data Related Dynamic Management Views and Functions

SQL Server Operating System Related Dynamic Management Views

Transaction-Related Dynamic Management Views and Functions

SQL Server 2012 Data Types

Data types are the foundation of table creation in SQL Server As you create a table, you must assign

a data type for each column This section covers some of the more commonly used data types in

SQL Server Even if you create a custom data type, it must be based on a standard SQL Server data

type For example, you may create a custom data type (Address) by using the following syntax, but

notice that it based on the SQL Server standard varchar data type:

CREATE TYPE Address

FROM varchar(35) NOT NULL

Trang 39

SQL Server Architecture ❘ 13

Exact Numeric Data Types

Numeric data types consist of bit, tinyint, smallint, int, bigint, numeric, decimal, money,

float, and real Each of these data types stores different types of numeric values The fi rst data

type, bit, stores only a null, 0 or a 1, which in most applications translates into true or false Using the bit data type is perfect for on and off fl ags, and it occupies only a single byte of space Table 1-2 shows other common numeric data types

TABLE 1.2: Exact Numeric Data Types

of this data type

smallint Whole numbers from −32,768 to 32,767 2 bytes

int Whole numbers from −2,147,483,648 to

Numeric data types, such as decimal and numeric can store a variable number of digits to the

right and left of the decimal place Scale refers to the number of digits to the right of the decimal

Precision defi nes the total number of digits, including the digits to the right of the decimal place

For example, 14.88531 would be a numeric(7,5) or decimal(7,5) If you were to insert 14.25

into a numeric(5,1) column, it would be rounded to 14.3

Approximate Numeric Data Types

The data types float and real are included in this group They should be used when fl oating-point data must be represented However, because they are approximate, not all values can be represented exactly

The n in the float(n) is the number of bits used to store the mantissa of the number SQL Server uses only two values for this fi eld If you specify between 1 and 24, SQL uses 24 If you specify

between 25 and 53, SQL uses 53 The default is 53 when you specify float(), with nothing in

parenthesis

Ngày đăng: 01/08/2014, 16:32

TỪ KHÓA LIÊN QUAN

w