Download presentation
Presentation is loading. Please wait.
1
Best People. Best Technology. SQL Server 2008 What’s New for Developers June 15 1 Speaker: Aviel Iluz | Database Consultant Contact: avieli@srl.co.il, 052-3134185avieli@srl.co.il SRL DBA Team Blog: http://blogs.microsoft.co.il/blogs/srldba/ http://blogs.microsoft.co.il/blogs/srldba/
2
Best People. Best Technology. Agenda About SQL Server 2008 Enhancements in SSMS and T-SQL Syntax T-SQL improvements and data types Tracking Changing Data Partitioning Enhancements 2
3
Best People. Best Technology. Agenda About SQL Server 2008 Enhancements in SSMS and T-SQL Syntax T-SQL improvements and data types Tracking Changing Data Partitioning Enhancements 3
4
Best People. Best Technology. SQL Server 2008 Vision 4 Enterprise Data Platform Secure, trusted platform for your dataSecure, trusted platform for your data Optimized and predictable system performanceOptimized and predictable system performance Productive policy-based management of your infrastructureProductive policy-based management of your infrastructure Beyond Relational Store and consume any type of dataStore and consume any type of data Deliver Location Intelligence within your applicationsDeliver Location Intelligence within your applications Dynamic Development Accelerate your development with entitiesAccelerate your development with entities Synchronize your data from anywhereSynchronize your data from anywhere Pervasive Insight Integrate all your data in the Enterprise Data WarehouseIntegrate all your data in the Enterprise Data Warehouse Reach all your users with scalable BI platformReach all your users with scalable BI platform Empower every user with actionable insightsEmpower every user with actionable insights
5
Best People. Best Technology. Editor enhancements (indentation, collapsing) T-SQL IntelliSense T-SQL Debugger Code abbreviations Enhancements in SSMS and T-SQL Syntax 5
6
Best People. Best Technology. Demo Enhancements in SSMS and T-SQL Syntax 6
7
Best People. Best Technology. Agenda About SQL Server 2008 Enhancements in SSMS and T-SQL Syntax T-SQL improvements and data types Tracking Changing Data Partitioning Enhancements 7
8
Best People. Best Technology. T-SQL improvements and data types MERGE statement Table-Valued Parameters Grouping Sets New Date and Time Data Types 8
9
Best People. Best Technology. Merged Data MERGE Statement: Merging Data What is to merge data? 9 SourceTarget Update Insert Delete New Updated Deleted
10
Best People. Best Technology. MERGE Statement SQL Server 2005: Multiple DML Statements: 10 SQL Server 2008: A Single DML Statement BEGIN TRAN COMMIT UPDATE t INNER JOIN s INSERT t LEFT OUTER JOIN DELETE t RIGHT JOIN s MERGE t USING s ON t.ID = s.ID WHEN MATCHED THEN UPDATE WHEN NOT MATCHED THEN INSERT WHEN NOT MATCHED BY SOURCE THEN DELETE;
11
Best People. Best Technology. Demo MERGE statement MERGE vs. “UPSERT” 11
12
Best People. Best Technology. Table-Valued Parameters Common challenge: Passing list of values to SP/FN Problem: No ARRAY data type 12 SQL Server 2005 @p = '1,2,3,4,5,…' Parsing string of delimited valuesShredding XML SQL Server 2008 temp table outside the SP Table Value Parameter
13
Best People. Best Technology. Using Table Value Parameters Create strongly typed table variable (new!) Use as a parameter (must be READONLY) Declare and initialize TABLE variable 13 CREATE TYPE mytab AS TABLE (id int); DECLARE @t mytab; CREATE TYPE mytab AS TABLE (id int); DECLARE @t mytab; INSERT @t VALUES (1), (2), (3); EXEC dbo.usp_usetable @list = @t DECLARE @t mytab; INSERT @t VALUES (1), (2), (3); EXEC dbo.usp_usetable @list = @t CREATE PROC dbo.usp_usetable (@list AS mytab READONLY)
14
Best People. Best Technology. Demo Table-Valued Parameters vs. old alternatives 14
15
Best People. Best Technology. TVP Implementation and Performance Table Variables materialized in TEMPDB Faster than parameter arrays, BCP APIs still fastest 15
16
Best People. Best Technology. TVP in.NET TVP Passed From the APP 16 // Create a data table, and provide its structure DataTable customerTable = new DataTable(); customerTable.Columns.Add("Name", typeof(string)); customerTable.Columns.Add("City", typeof(string)); customerTable.Columns.Add("Phone", typeof(string)); // Fill with rows using (SqlConnection conn = new SqlConnection("...")) { SqlCommand cmd = conn.CreateCommand(); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandText = "dbo.CustomersInsertMany"; SqlParameter param = cmd.Parameters.AddWithValue("@CustomersTable", customerTable); conn.Open(); cmd.ExecuteNonQuery(); } // Create a data table, and provide its structure DataTable customerTable = new DataTable(); customerTable.Columns.Add("Name", typeof(string)); customerTable.Columns.Add("City", typeof(string)); customerTable.Columns.Add("Phone", typeof(string)); // Fill with rows using (SqlConnection conn = new SqlConnection("...")) { SqlCommand cmd = conn.CreateCommand(); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandText = "dbo.CustomersInsertMany"; SqlParameter param = cmd.Parameters.AddWithValue("@CustomersTable", customerTable); conn.Open(); cmd.ExecuteNonQuery(); }
17
Best People. Best Technology. Grouping Sets 17 SQL Server 2005SQL Server 2008 Common challenge: Many grouping sub-totals required from the same table SELECT a, sum(q) FROM T GROUP BY a UNION ALL SELECT a, b, sum(q) FROM T GROUP BY a, b UNION ALL SELECT a, b, c, sum(q) FROM T GROUP BY a, b, c SELECT a, sum(q) FROM T GROUP BY a UNION ALL SELECT a, b, sum(q) FROM T GROUP BY a, b UNION ALL SELECT a, b, c, sum(q) FROM T GROUP BY a, b, c SELECT a, b, c, sum(q) FROM T GROUP BY GROUPING SETS ( (a), (b), (a, b, c) ) SELECT a, b, c, sum(q) FROM T GROUP BY GROUPING SETS ( (a), (b), (a, b, c) )
18
Best People. Best Technology. More on Grouping Sets Single read pass for performance GROUPING_ID() and GROUPING() new function Distinguish between different subtotals 18
19
Best People. Best Technology. Demo GROUPING SETS GROUPING and GROUPING_ID Functions 19
20
Best People. Best Technology. New Date and Time Data Types 20 SQL Server 2008: DATE TIME Prev. SQL Server: DATETIME
21
Best People. Best Technology. DATE and TIME 21 DATE Data Type o Date Only o Large range: 01-01-0001 to 31-12-9999 TIME Data Type o Time Only o Variable Accuracy: up yo 100
22
Best People. Best Technology. 2005 TIME/DATE alternatives 22 SQL Server 2005 Alternatives to TIME/DATE o User Defined Data Types + Rules o Creating Computed Columns o Extracting time/date component form DATETIME 22
23
Best People. Best Technology. DATETIME2 and DATETIMEOFFSET 23 DATETIME2 Data Type o Large range (like DATE) o High precision (like TIME) DATETIMEOFFSET o Like DATETIME2 o + Time Zone Offset YYYY-MM-DD hh:mm:ss[.nnnnnnn] [+|-]hh:mm
24
Best People. Best Technology. New Date and Time Data Types – Summary Table 24 Time zone offset User- defined fractional second precision Size (bytes) AccuracyRangeFormatData type NoYes3 to 5100 ns00:00:00.0000000 through 23:59:59.9999999 hh:mm:ss[.nnnnnnn]time No 31 day0001-01-01 through 9999-12-31 YYYY-MM-DDdate NoYes6 to 8100 ns0001-01-01 00:00:00.0000000 through 9999-12-31 23:59:59.9999999 YYYY-MM-DD hh:mm:ss[.nnnnnnn] datetime2 Yes 8 to 10100 ns0001-01-01 00:00:00.0000000 through 9999-12-31 23:59:59.9999999 (in UTC, No day light saving) YYYY-MM-DD hh:mm:ss[.nnnnnnn] [+|-]hh:mm datetimeoffset
25
Best People. Best Technology. Date Time Library Extensions 25 Higher precision current date/time uses SYSDATETIME SYSUTCDATETIME SYSDATETIMEOFFSET Special functions for DATETIMEOFFSET o SWITCHOFFSET (datetimeoffset, timezone) o TODATETIMEOFFSET (any date/time, timezone )
26
Best People. Best Technology. Demo New date and time data types New data and time functions 26
27
Best People. Best Technology. Agenda 27 About SQL Server 2008 Enhancements in SSMS and T-SQL Syntax T-SQL improvements and data types Tracking Changing Data Partitioning Enhancements
28
Best People. Best Technology. Tracking Changing Data 28 Common challenge: Track data changes for data storage synchronisation SQL Server 2005 Timestamp column Triggers and schema changes SQL Server 2008 Change Tracking (synchronous) Change Data Capture (asynchronous)
29
Best People. Best Technology. Change Data Capture SQL Agent jobs periodically (asynchronously) scan the transaction log for change data Change data is placed in change relational tables Changes are requested using TVFs 29
30
Best People. Best Technology. CDC vs. Change Tracking (1) 30 CDCCT
31
Best People. Best Technology. CDC vs. Change Tracking (2) Change Data CaptureChange Tracking Asynchronous Process Changes From T-Log Synchronous Part of the DML Tran not suited for two-way synchSuitable for two-way synch Conflicts can be reliably detected Scenarios When all / specified time intervals intermediate changes values are Required Only net changes are required. E.g only Row’s PK last value (no history) captures all changes for a row.low storage and performance overhead 31
32
Best People. Best Technology. Demo Change Tracking Change Data Capture 32
33
Best People. Best Technology. Agenda 33 About SQL Server 2008 Enhancements in SSMS and T-SQL Syntax T-SQL improvements and data types Tracking Changing Data Partitioning Enhancements
34
Best People. Best Technology. Partitioning Enhancements Partition-Aligned Indexed Views Date-Only Data type Partitioned Table Parallelism Partition-Level Lock Escalation 34
35
Best People. Best Technology. Lock Escalation: The Problem Lock escalation on partitioned tables locks ALL partitions Only way to solve this currently is to disable escalation 35 IXX FG1 FG2 ` FG3 Partitioned Table Partition 1 Partition 2 Partition 3 Query 1 ESCALATE Query 2 update
36
Best People. Best Technology. Lock Escalation: The Solution SQL Server 2008 allows lock escalation to the partition level Escalation to partition level does not block queries on other partitions 36 IX X FG1 FG2 FG3 Partitioned Table Partition 1 Partition 2 Partition 3 Query 1 ESCALATE Query 2 update
37
Best People. Best Technology. Demo Partitioning Enhancements: o Partition-Level Lock Escalation 37
38
Best People. Best Technology. Learn More Itzik Ben-Gan, Introduction to New T-SQL Programmability Features in SQL Server 2008 http://msdn.microsoft.com/en-gb/library/cc721270(SQL.100).aspx MSDN Webcast: New T-SQL Programmability Features in SQL Server 2008 http://msevents.microsoft.com/CUI/WebCastEventDetails.aspx?cul ture=en-US&EventID=1032357754&CountryCode=US
39
Best People. Best Technology. Contact Us: Tel: +972 3 766 2020 Fax: +972 3 648 2197 www.srl.co.il Thank You! June 15 39 Aviel Iluz | Database Consultant Email: avieli@srl.co.il
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.