Download presentation
Presentation is loading. Please wait.
Published bySilas Barrie Fleming Modified over 9 years ago
1
WHAT’S NEW IN SQL SERVER 2008: T-SQL Martin Bell SQL Server MVP
2
Features we will look at: Date and Time Functionality Dependency Reporting Filestream Storage Merge Statement Row Constructors Sparse Columns and Column Sets Hierarchy ID Data Type User Defined Table Type Table Values Parameters
3
Date and Time Functionality Date Supports Years 0 – 9999 i.e. 01-01-0001 to 31-12-9999 (Gregorian Calendar) Native Datatype (not CLR) Size - 3 bytes
4
Date and Time Functionality Time Variable Precision - 0 to 7 decimal places for seconds Precise to 100 nanoseconds Separate Date and Time saves space Ansi compatible Size - 3 bytes for precisions <= 2; 4 bytes for precisions of 3 and 4 5 bytes for precisions > 4
5
Date and Time Functionality DateTimeOffset Supports Years 0 – 9999 i.e. 01-01-0001 to 31-12-9999 (Gregorian Calendar) Precise to 100 nanoseconds Time Zone Offset (From UTCTime) Preserved Not Time Zone Aware - No Daylight Saving Time Support Size - 8 bytes for precisions <= 2; 9 bytes for precisions of 3 and 4 10 bytes for precisions > 4
6
Date and Time Functionality DateTime2 Supports Years 0 – 9999 i.e. 01-01-0001 to 31-12-9999 (Gregorian Calendar) Precise to 100 nanoseconds Size - 6 bytes for precisions <= 3; 7 bytes for precisions of 4 and 5 7 bytes for precisions > 5
7
Date and Time Functionality Can still use existing date/time functions DATENAME (datepart, date) DATEPART (datepart,date) DATEDIFF (datepart, startdate, enddate) DATEADD (datepart, number, date) Datepart can also be microsecond, nanosecond, TZoffset or ISO_WEEK MONTH DAY YEAR CONVERT extensions
8
Dependency Reporting New dependency views replace sp_depends Kept in sync as changes occur sys.dm_sql_referenced_entities Lists all named entities that an object references sys.dm_sql_referencing_entities Lists all named entities that use an object Can see references at OBJECT, DATABASE DDL TRIGGER, SERVER DDL TRIGGER level
9
Filestream Storage Currently limited to 2GB with varchar(max) Poor streaming performance High cost of data Filestream: Size limited by NTFS volume Kept transactionally consistent Can be stored on compressed volumes
10
Filestream Storage Check out Paul Randal’s Blog for the performance graphs Filestream reads better than varbinary Filestream inserts perform better for files over ≈2MB for Win32 Varbinary inserts perform than T-SQL Filestream Filestream updates perform better for files over ≈1MB for Win32 Filestream updates perform better than varbinary for T-SQL
11
Filestream Storage SqlFileStream Managed API in VS 2008 SP1
12
Merge Statement Lets you INSERT, UPDATE, AND DELETE in a single operation (i.e. single pass of the data) Specify commands for each case (Insert, Update or Delete) Cannot be remote table of distributed partitioned view NOLOCK, READUNCOMMITED disallowed (to maintain index integrity) Special $ACTION column allows you to record whether MERGE did an INSERT, UPDATE, DELETE
13
Merge Statement [ WITH [,...n] ] MERGE [ TOP ( expression ) [ PERCENT ] ] [ INTO ] target_table [ [ AS ] table_alias ] [ WITH ( ) ] USING ON [ WHEN MATCHED [ AND ] THEN ] [ WHEN [TARGET] NOT MATCHED [ AND ] THEN ] [ WHEN SOURCE NOT MATCHED [ AND ] THEN ] [ OPTION ( [,...n ] ) ] ;
14
Row Constructors (Values Clause) Before SQL 2008: DECLARE @t TABLE (id int, name varchar(20)); INSERT INTO @t VALUES SELECT 1, 'Fred‘ UNION ALL SELECT 2, 'Jim‘ UNION ALL SELECT 3, 'Sue' SQL 2008: DECLARE @t TABLE (id int, name varchar(20)); INSERT INTO @t (id, name) VALUES (1, 'Fred'), (2, 'Jim'), (3, 'Sue');
15
Row Constructors (Values Clause) SQL 2008: DECLARE @t TABLE (id int, name varchar(20)); INSERT INTO @t (id, name ) SELECT num, fore FROM ( VALUES (1, 'Fred'), (2, 'Jim'), (3, 'Sue') ) d (num, fore);
16
Sparse Column and Column Sets Ways of modeling sparse data: One row per attribute: 256 table limit in SQL Server JOIN Multiple nullable columns one per attribute: 1024 column limit in SQL Server tables Modeled as XML: Common properties are elements, sparse are attributes
17
Hierarchy Id Data Type Compact way to store hierarchies with SELECT query support Can allow some hierarchy queries without having to resort to recursive queries Slower on re-parenting operations (not just moving pointers!) See BOL for discussions of the various trade- offs vs. XML and parent/child tables
18
Hierarchy Id Data Type CLRUDT implementation Uses ORDPATH representation (materialized path) "Level" property - allows breadth-first indexing
19
Hierarchy Id Data Type Depth First indexing Breadth First indexing
20
Hierarchy Id Data Type Methods for common hierarchical operations GetRoot GetLevel IsDescendant GetDescendant, GetAncestor Reparent
21
User Defined Table Type CREATE TYPE mytab AS TABLE (id int); DECLARE @t mytab;
22
Table Valued Parameters How do I pass a table to a T-SQL stored procedure? How do I efficiently pass multiple values from a database client? Erland Sommarskog’s Web Site http://www.sommarskog.se/arrays-in-sql.html
23
Table Valued Parameters Parameters must use strongly typed table variables Tables are passed by reference No Statistics support exposed on these, so be careful in large query plans
24
Grouping Sets ANSI SQL Extension of CUBE, Rollup Lets you specify specific sets of Rollups without having to generate complete CUBEs Can be more efficient than generating a CUBE and filtering down to the set of rows you need. Equivalent: GROUP BY CUBE (C1, C2, C3) GROUP BY GROUPING SETS ( (C1, C2, C3), (C1, C2), (C1, C3),(C2, C3), (C1), (C2), (C3), () )
25
References (SQL 2008) What’s New http://www.microsoft.com/sqlserver/2008/en/us/overview. aspx Learning Resources http://www.microsoft.com/sqlserver/2008/en/us/learning.a spx Technet Insiders Blog http://blogs.technet.com/industry_insiders/ Technet http://technet.microsoft.com/en-us/library/cc721270.aspx
26
References (Filestream) Should I store my images in the database (SQL 2000) http://databases.aspfaq.com/database/should-i-store- images-in-the-database-or-the-filesystem.html To BLOB or not to BLOB http://research.microsoft.com/research/pubs/view.aspx?m sr_tr_id=MSR-TR-2006-45
27
References (Filestream) Paul Randal’s Blog http://www.sqlskills.com/blogs/paul/2008/03/09/SQLServe r2008FILESTREAMPerformance.aspx Guy Burstein's Blog http://blogs.microsoft.co.il/blogs/bursteg/archive/2008/05/ 12/sqlfilestream-managed-api-for-sql-server-2008- filestream.aspx
28
References (HierarchyId) Simon Sabin’s Blog http://sqlblogcasts.com/blogs/simons/ SQL Server Magazine http://www.sqlmag.com/articles/index.cfm?articleid=99369
29
References (Merge) Connor Cunningham’s Blog http://blogs.msdn.com/conor_cunningham_msft/archive/20 09/02/04/conor-vs-merge-and-primary-key-collisions.aspx
30
Erland Sommarskog’s Articles http://www.sommarskog.se/arrays-in-sql.html http://www.sommarskog.se/arrays-in-sql-perftest.html http://www.sommarskog.se/arrays-in-sql-perftest.html Guy Burstein’s blog http://blogs.microsoft.co.il/blogs/bursteg/archive/2007/12/02/sql-server-2008-table-valued- parameters.aspx Mike Taulty’s blog http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2007/12/03/9991.aspx References (TVPs)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.