twitter: @johnsterrett blog: ://filtered indexes demo…. • sql server 2008 extends date/time...
TRANSCRIPT
twitter: @JohnSterrett
blog: http://johnsterrett.com
Presented By: John Sterrett
I am not an expert but I stayed at a HolidayInn Express….
I reside in Wheeling, WV (Pittsburgh, PA)◦ Recently started Wheeling SQL Server UG
◦ Co-Host SQL Saturday #36 in Wheeling, WV
Work for Orrick Herrington & Sutcliffe LLP◦ Responsible 100+ Instances of SQL Server
◦ Responsible for PeopleSoft
Give an introduction to new features.
Give real-world cases for using new features.
This is an introduction, NOT a deep dive.
◦ Management Studio (SSMS) Enhancements
◦ T-SQL Delighters
◦ Filtered Indexes
◦ New Date and Time Data Types
◦ Table-Valued Parameters
◦ MERGE statement
◦ Policy Based Management and Central ManagementServer
◦ Change Data Capture
• IntelliSense
• Debugging
• Error List
• Object Explorer Details Viewer
• Template Explorer (SQL 2005)
• Activity Monitor
• Declare and Initialize Variables
• Compound assignment Operators
• Table Value Constructor Support through theVALUES Clause
Demo covering The following topics
• IntelliSense
• Debugging
• Error Lists
• Object Explorer Details
• Template Explorer
• Activity Monitor
Have you ever wanted to create an index thatfilters between a static search criteria?
CREATE INDEX idxName ON Schema.Table(Column) WHERE ……
• Improved query performance and planquality if used correctly!
• Reduced index maintenance costs
• Reduced index storage costs
Filtered Indexes Demo….
• SQL Server 2008 extends date/time support
• Larger Value Space– Current DATETIME - 1753-9999 Years
– Current DATETIME - 0.00333 Second Accuracy
– New Date Types - 0001-9999 Years
– New Date/Time Types - Precisions to 100nanoseconds
• Variable Precision Saves Space
• Separate Date and Time Saves Space
• ANSI Compatible
DATE Data Type◦ Date Only◦ 01-01-0001 to 31-12-9999 Gregorian Calendar
TIME Data Type◦ Time Only◦ Variable Precision - 0 to 7 decimal places for
seconds◦ To 100 nanoseconds
DATETIME2 Data Type◦ 01-01-0001 to 31-12-9999 Gregorian Calendar
◦ Variable Precision - to 100 nanoseconds
DATETIMEOFFSET◦ 01-01-0001 to 31-12-9999 Gregorian Calendar
◦ Variable Precision - to 100 nanoseconds
◦ Time Zone Offset (From UTCTime) Preserved
◦ Not Time Zone Aware - No Daylight Saving TimeSupport
• SWITCHOFFSET (DATETIMEOFFSET,time_zone)
• Allows you to change time zones (+14 to -14)
• Uses Gregorian Calendar
• SqlDbType.DateTimeOffset
T-SQL Date and Time
DATETIMEOFFSET with .NET
Have you wished that you could send a tableinto a stored procedure?
Do you wish you could send all parent-childrelationship data in one round-trip?
SQL Server has table variables◦ DECLARE @t TABLE (id int);
SQL Server 2008 adds strongly typed tablevariables◦ CREATE TYPE mytab AS TABLE (id int);
DECLARE @t mytab;
Table-Value Parameters must use stronglytyped table variables
ADO.NET 3.5 Supports Table ValueParameters
You can populate TVP from the following.NET objects◦ DataTable
◦ DbDataReader
◦ System.Collections.Generic.IList <SQLDataRecord>
Recommended for 1000 or less records
SqlParameter tvpParam = new SqlParameter();
tvpParam.ParameterName = "@TVP";
tvpParam.Value = dtList; //DataTable in this example
tvpParam.SqlDbType = SqlDbType.Structured; // This data type allowsus to pass a table into DB Objects
tvpParam.TypeName = "TVPComponentType"; // Name of strongtyped (table type)
Table-Value Parameters with T-SQL
Table-Value Parameters with ASP.NET (C#)
Once upon a time I use to build scripts likethe following:
TRUNCATE TABLE db1.dbo.fool
INSERT INTO db1.dbo.foolSELECT * FROM db2.dbo.fool
Multiple set operations in a single SQLstatement
Uses multiple sets as input◦ MERGE target USING source ON ...
Operations can be INSERT, UPDATE, DELETE Operations based on◦ WHEN MATCHED◦ WHEN [TARGET] NOT MATCHED◦ WHEN SOURCE NOT MATCHED
ANSI SQL 2006 compliant - with extensions
Multiple WHEN clauses possible◦ For MATCHED and SOURCE NOT MATCHED
◦ Only one WHEN clause for TARGET NOT MATCHED
MERGE can be used with any table source
A MERGE statement causes triggers to befired once
Rows affected includes total rows affected byall clauses
MERGE statement is transactional◦ No explicit transaction required
One Pass Through Tables◦ At most a full outer join◦ Matching rows = when matched◦ Left-outer join rows = when target not matched◦ Right-outer join rows = when source not matched
Demo Merge with T-SQL!
Have you ever wanted to run a script againstall production databases?
Have you ever wanted to enforce namingconventions in SQL Programming?
• Central Management System• Needs only 1 instance of SQL 2008
• Reactive not proactive
• great tool for running a script against multipleservers
• Policy Based Management• proactive tool prevents stuff from happening
• great tool to enforce compliance on SQL 2008+servers
• Facets
• Conditions
• Policies
Demo monitoring and enforcing namingstandards with Policy Based Management
Have you ever wanted to get row deltas on atable without using replication or triggers onthe source table?
• Must have Enterprise Edition
• Uses transaction log to pull deltas
• Enable on database (req sysadmin)• sys.sp_cdc_enable_db_change_data_capture
• creates cdc schema
• creates cdc user
• creates system tables with cdc schema
• Enable on table(s) (req db_owner)• sys.sp_cdc_enable_table
• creates sql agent jobs
• creates table cdc.schema_tablename_CT
• Changes stored incdc.schema_tablename_CT
• _$operation column specifies change type• 1 = DELETE
• 2 = INSERT
• 3 = BEFORE UPDATE
• 4 = AFTER UPDATE
• cdc.fn_cdc_get_all_changes<capture_instance>
• gets all changes during specific range
• cdc.fn_cdc_get_net_changes<capture_instance>
• returns final (net change) for each row in thespecific range
Enable and use Change Data Capture
Using the Transact-SQL Debugger
SQL 2008 JumpStart
MSDN – SQL 2008 Virtual Labs
Developer Fundamentals Part 1: UncoveringT-SQL on SQL Server 2008
Presented By: John Sterrett
◦ Twitter: @JohnSterrett
◦ Blog: http://johnsterrett.com
◦ LinkedIn: http://linkedin.com/johnsterrett