Microsoft TechNet Academy UPDATING YOUR SQL SERVER 2005 SKILLS TO SQL SERVER 2008
SQL Server 2008 Security Enhancements Encrypting Databases SQL Server Audit
Encrypting Databases Secure Data Scenarios Encryption in Previous Releases What Is Transparent Data Encryption? How to Encrypt a Database What Is Extensible Key Management?
Secure Data Scenarios Defense in depth Even if attackers get through your firewall, they should have to get through line after line of defence Remote backup storage To ensure adequate disaster recovery, backups are often stored offsite. Sensitive data that is stored offsite must be protected Transparent data encryption Encrypt data transparently so that applications can work with encrypted data without modification
Encryption in Previous Releases In SQL Server 2000 and earlier: No encryption is provided Encryption must be entirely provided d by applications In SQL Server 2005: Encryption is included Encryption and decryption must be performed by Transact-SQL statements There is increased application complexity over unencrypted data
What Is Transparent Data Encryption? Database-level encryption Encryption and decryption performed automatically by SQL Server Transparent to users and applications Requires no additional code or functionality for an application to use encrypted data: The process of accessing encrypted data is identical to the process of accessing unencrypted data
How to Encrypt a Database 1. Create a master key CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'Pa$$w0rd' 2. Create a server-level certificate CREATE CERTIFICATE ServerCertificate WITH SUBJECT = 'Server level certificate' 3. Create a database encryption key by using the server certificate USE AdventureWorks GO CREATE DATABASE ENCRYPTION KEY WITH ALGORITHM = AES_128 ENCRYPTION BY SERVER CERTIFICATE ServerCertificate 4. Alter the database and set the Encryption option to On ALTER DATABASE Ad t W k ALTER DATABASE AdventureWorks SET ENCRYPTION ON
What Is Extensible Key Management? External key management by third-party vendors Typically enterprise-wide Supports HSMs Hardware-based key management Physical separation of keys and data
SQL Server Audit What Is SQL Server Audit? Scenarios for SQL Server Audit How to Create an Audit How to Create an Audit Specification
What Is SQL Server Audit? SQL Server Audit captures activity in the database server and stores it in a log Audit information can be stored in the following destinations: File Windows Application log Windows Security log SQL Server Audit consists of an Audit object and an audit SQL Server Audit consists of an Audit object and an audit specification
Scenarios for SQL Server Audit Increased security: Monitor failed logon attempts Monitor successful logon attempts t to check for activity it at unusual times of the day Regulatory compliance: Log data changes and maintain a version history of data Regulations may require you to keep all versions of a record
How to Create an Audit Use the CREATE SERVER AUDIT statement: Specify the destination CREATE SERVER AUDIT HIPAA_File_Audit TO FILE ( FILEPATH= \\SQLPROD_1\Audit\ ) CREATE SERVER AUDIT HIPAA AppLog Audit CREATE SERVER AUDIT HIPAA_AppLog_Audit TO APPLICATION_LOG WITH ( QUEUE_DELAY = 500, ON_FAILURE = SHUTDOWN)
How to Create an Audit Specification Server audit specification CREATE SERVER AUDIT SPECIFICATION Failed_Login_Spec FOR SERVER AUDIT HIPAA_File_Audit ADD (FAILED_LOGIN_GROUP) Database audit specification CREATE DATABASE AUDIT SPECIFICATION Sales_Audit_Spec Spec FOR SERVER AUDIT HIPAA_AppLog_Audit ADD (DATABASE_OBJECT_CHANGE_GROUP), ADD (INSERT, UPDATE, DELETE ON Schema::Sales BY SalesUser, SalesAdmin)
SQL Server 2008 Database Development Enhancements Developer Tool Enhancements Data Type Enhancements Working with Spatial Data
Developer Tool Enhancements IntelliSense in SQL Server Management Studio The Error List in SQL Server Management Studio Object Explorer Enhancements
IntelliSense in SQL Server Management Studio Similar to Microsoft Visual Studio IntelliSense functionality Complete Word feature Auto List feature Unavailable when: There are code errors above Inside comments Inside string literals The feature is switched off
The Error List in SQL Server Management Studio Similar to the Visual Studio Error List Displays errors and warnings during script editing Double-click an error to locate it in the script
Object Explorer Enhancements New configurable options on the shortcut menu: Select Top x Rows Edit Top y Rows Configuration options
Data Type Enhancements Date and Time Data Types The User-Defined Table Data Type The Hierarchyid Data Type FILESTREAM Data
Date and Time Data Types datetime2 Larger range and more accurate than datetime date Date portion of datetime2 time Time portion of datetime2 datetimeoffset datetime2 plus support for time-zone offset DECLARE @newdatetime @newtime time(3) datedatetimeoffset datetime2 SET @newdatetime @newtime D t = SYSDATETIME() = SYSDATETIMEOFFSET() PRINT @newdatetime @newtime -- OUTPUT -- 2008-01-24 20:50:46.789 2008-02-24 01 02 24 20:50:46.7892464-08:00
The User-Defined Table Data Type A user-defined type that represents a table Use as parameters for stored procedures and functions and in place of table variables Restrictions CREATE include: TYPE ProductionHistory AS TABLE (TransactionID int, You cannot -- use Remaining the user-defined column table definitions type as a here column or a field in a ) structured user-defined type You cannot use the [NOT FOR REPLICATION] option in the definition CREATE PROCEDURE usp_archivehistory @PH ProductionHistory You cannot specify AS - a Remaining DEFAULT value SP definition the definition here You cannot DECLARE modify @PH the AS table ProductionHistory type definition after creation INSERT INTO @PH - Populate table here EXEC usp_archivehistory @PH; GO
The Hierarchyid Data Type Use to represent the position of an item in a hierarchy Members: GetRoot returns the root of the hierarchy Get Level returns an integer that represents the depth of the node GetAncestor returns the hierarchyid of the specified ancestor GetDescendant returns a child node of the specified node Read returns the binary representation of a node Parse converts the string representation of a hierarchyid to a hierarchyid value Write writes a binary representation of a node GetReparentedValue moves a node of a hierarchy to a new location in the hierarchy INSERT DECLARE CREATE INTO TABLE @NodeLevel OrgTable hierarchyid SELECT ( VALUES ((@NodeLevel.GetDescendant(@Manager, = OrgNode FROM OrgTable WHERE null), EmpName 1, = Darren hierarchyid::getroot(), OrgNode Dominic ) hierarchyid, EmpID 0, Darren int, EmpName varchar(50) SELECT ) DECLARE OrgNode.ToString(), @Manager hierarchyid g(), OrgNode, EmpID, EmpName SELECT FROM OrgTable @Manager = max(orgnode) FROM OrgTable WHERE OrgNode.GetAncestor(1) = @NodeLevel
FILESTREAM Data Use to store unstructured data on the NTFS file system, but manage it by using SQL Server Data stored as BLOBs on the file system To store FILESTREAM data: Enable the FILESTREAM Create a FILESTREAM filegroup Create a column of type varbinary(max) FILESTREAM Use a unique identifier for the table Use Transact-SQL or Win32 APIs to access FILESTREAM data INSERT CREATE EXEC sp_configure INTO TABLE DATABASE ResumeData Applicants filestream_access_level, ON PRIMARY 2 RECONFIGURE VALUES (...), FILEGROUP ( ApplicantID FSGroup1 int, CONTAINS FILESTREAM Resume (NAME=ApplicantsBLOBData, 1, CAST( Resume varbinary(max) Text ) FILESTREAM, AS varbinary(max)), FILENAME=N C:\SQLData ), newid() LOG ) ResumeID.. ON. UNIQUEIDENTIFIER ROWGUIDCOL NOT NULL UNIQUE )(...)
Working with Spatial Data What Is Spatial Data? The Geometry and Geography Data Types How to Create Spatial Data Instances How to Perform Spatial Queries and Operations What Are Spatial Indexes? How to Create Spatial Indexes
What Is Spatial Data? Information about the location and shape of a geometric object: Store locations Sales regions Customer sites Area within a specific distance of a location Two types: Planar (or Euclidean) data for coordinate points on a flat, bounded surface. Distances are measured directly between points Geodetic (or ellipsoidal) data for latitude and longitude points on the surface of the Earth. Distances are measured taking into account the curvature of the ellipsoidal surface
The Geometry and Geography Data Types SQL Server supports two spatial data types: geometry for planar spatial data geography for ellipsoidal spatial data Both data types: Are implemented as.net Framework common language runtime types Can store points, lines, and areas Provide members to perform spatial operations Common uses: geometry localized geospatial data such as street maps geography locations on the Earth s surface and integration with geospatial systems
How to Create Spatial Data Instances To create a column to store spatial data: Declare the column as either the geometry or geography type To insert data into a geometry column: Use geometry methods to convert a text string, a WKB description, or GML to a point, line, or polygon To insert data into a geography column: Use geography methods to convert latitude and longitude coordinates or a WKB description to a point, line, or polygon INSERT CREATE INTO TABLE Store (StoreID VALUES (. int.., IDENTITY geometry::stpointfromtext geography::stgeomfromtext PRIMARY KEY,. ('POINT(100 ('POINT(37.603926.. 100)', -122.084552)', 0) 4326)) StoreLocation geography) INSERT INTO Store CREATE VALUES TABLE (.. Store., geometry::stpolyfromtext geography::stgeomfromwkb (StoreID ('POLYGON((5 (0x0101000000EF535568206E4640DC4603780B5557C0, int IDENTITY 5, 5, PRIMARY 10, KEY, 5 5))', 0) 4326))... StoreLocation geometry)
How to Perform Spatial Queries and Operations STIntersection creates a new instance from the intersection of two existing instances STIntersects determines whether two instances intersect STDistance determines the shortest distance between two points STNumPoints determines the number of points that constitute an instance STLength determines the length of a line STSrid sets or returns the SRID of the instance DECLARE @NWRegion geometry SET @NWRegion = SELECT geo FROM Regions WHERE RegionID = 1 SELECT @NWRegion.STArea()
What Are Spatial Indexes? Querying spatial data can take time and processing power Spatial indexes can help to improve performance A spatial index is defined by dividing an area into up to four grids and then indexing the cells in each grid that a spatial value touches For geography data, the spatial index maps the area onto a two-dimensional plane before the indexing process begins Spatial indexes require a primary key
How to Create Spatial Indexes Use the CREATE SPATIAL INDEX statement For geometry data, use the BOUNDING_BOX parameter For both spatial data types: GRIDS specifies the density of each grid, with LOW being 4*4, MEDIUM being 8*8, and HIGH being 16*16 CELLS_PER_OBJECT specifies the maximum number of cells that can be used for a single object in the index Other standard index options are available, including PAD_INDEX and FILLFACTOR -- Create a spatial index on a geography geometry column CREATE SPATIAL INDEX SIndx_Store_StoreLocation ON Stored(StoreLocation) WITH (GRIDS (BOUNDING_BOX = (LEVEL_2 = (0, = HIGH, 0, 200, LEVEL_1 500), = MEDIUM), CELLS_PER_OBJECT GRIDS = (LEVEL_2 _ = 8192) HIGH, LEVEL_1 = MEDIUM), CELLS_PER_OBJECT = 8192)
SQL Server 2008 Availability Enhancements Always-on Technologies Transactional Peer-to-Peer Replication
Always-on Technologies What Is Hot Add CPU? Database Mirroring Performance Enhancements Automatic Page Recovery from Mirror Servers Clustering Enhancements
What Is Hot Add CPU? Add CPUs to supported systems while system is running: No downtime Increased availability Requires Windows Server 2008 Extends the hot add memory capabilities of SQL Server 2005
Database Mirroring Performance Enhancements Page-level mirroring: If a page on the principal or mirror server is corrupt, it is automatically replaced with the corresponding copy on its partner Compressed data flow: Data flow between the principal i and mirror server is now compressed to improve performance Manual failover: Manual failovers no longer require a database restart Log performance: Write-ahead on the incoming log stream on the mirror server Improved use of log send buffers Page read-ahead during the undo phase after a failover
Automatic Page Recovery from Mirror Servers If th i i l i i t it i If a page on the principal or mirror server is corrupt, it is automatically replaced with the corresponding copy on its partner
Clustering Enhancements SQL Server 2008 removes the requirement to have one drive letter for each SQL Server instance Windows Server 2008 provides enhanced clustering: Supports up to 16 nodes in a cluster Supports clustering over multiple subnets Supports OR dependencies: For example, by ensuring that the network name resource is available if either of two IP address resources is available Is easier to set up and manage Contains a cluster validation tool: Ensures hardware, software, and network compatibility
Transactional Peer-to-Peer Replication Configure Peer-to-Peer Topology Wizard Adding New Replication Nodes Automatic Conflict Detection
Configure Peer-to-Peer Topology Wizard Simplifies the configuration of peer-to-peer replication
Adding New Replication Nodes Add nodes with the Configure Peer-To-Peer Topology Wizard Add nodes while keeping the replication process online: Improves availability
Automatic Conflict Detection Detects accidental conflicts when multiple replication nodes update the same row Prevents inconsistent data across nodes Treats a conflicting change as a critical error that causes the failure of the Distribution Agent Keeps the topology in an inconsistent state until the conflict is resolved
QUESTIONS?