SlideShare a Scribd company logo
1 of 98
New Programmability Features
Valinor SQL Server Professional Services Database Projects end-to-end High Availability & Disaster Recovery Upgrades Performance Analysis & Tuning Security Training contact@valinor.co.il
Valinor SQL Server Complementary Tools ,[object Object]
SQLcompliance manager
SQLsafe backup
SQLchange manager
SQLdefrag manager
SQL comparison toolset
SQLadmin toolset,[object Object]
Agenda T-SQL enhancements MERGE Statement Table Valued Parameters Grouping Sets Compound Assignments Table value constructors New data types Filestream HierarchyID Temporal data types Spatial data types SSMS Enhancements Intellisense Multi-instances query Registered Servers properties SSRS Enhancements More new features Data compression Resource Governor
T-SQL Enhancements MERGE Statement Table Valued Parameters Grouping Sets Compound Assignments Table value constructors
MERGE Statement What is it? MERGE allows you to compare two tables and apply changes to one of them according to matching and non-matching rows Allows multiple set operations in a single SQL statement Operations can be INSERT, UPDATE, DELETE ANSI SQL 2006 compliant - with extensions
What can I do with it? ETL processes “Update if exists, insert otherwise” stored procedures Data comparison, verification and modification MERGE Statement
MERGE Syntax MERGE [INTO] target_table AS target USING source_table AS source	(table, view, derived table) 	ON <merge_search_conditions> WHEN MATCHED [AND <other predicates>] 	UPDATE SET target.col2 = source.col2 	 (or delete) WHEN NOT MATCHED [BY TARGET] [AND <other predicates>] 	INSERT [(col_list)] VALUES (col_list) WHEN NOT MATCHED BY SOURCE [AND <other predicates>] 	DELETE						(or update) OUTPUT $action, inserted.col, deleted.col, source.col; 	Get used to semicolons!
MERGE Statement $action function in OUTPUT clause Multiple WHEN clauses possible  For MATCHED and NOT MATCHED BY SOURCE Only one WHEN clause for NOT MATCHED Rows affected includes total rows affected by all clauses
MERGE Performance MERGE statement is transactional No explicit transaction required One pass through tables At most a full outer join Matching rows (inner join) = when matched Left-outer join rows = when not matched Right-outer join rows = when not matched by source When optimizing, optimize joins Index columns used in ON clause (if possible, unique index on source table)
MERGE and Determinism UPDATE using a JOIN is non-deterministic If more than one row in source matches ON clause, either/any row can be used for the UPDATE. MERGE is deterministic If more than one row in source matches ON clause, an exception is thrown.
MERGE & Triggers When there are triggers on the target table Trigger is raised per DML (insert/update/delete) “Inserted” and “deleted” tables are populated In much the same way, MERGE is treated by replication as a series of insert, update and delete commands.
Where is MERGE useful? Replace UPDATE … JOIN and DELETE … JOIN statements ETL Processes Set comparison Update-if-exists, insert-otherwise procedures IF EXISTS (SELECT … FROM tbl) 	UPDATE tbl … ELSE  	INSERT …
MERGE Statement ,[object Object],[object Object]
Table Types SQL Server has table variables 	DECLARE @t TABLE (id int); SQL Server 2008 adds strongly typed table variables CREATE TYPE mytab AS TABLE (id int); DECLARE @t mytab; Parameters must use strongly typed table variables
Table Variables are Input Only Declare and initialize TABLE variable DECLARE @t mytab; INSERT @t VALUES (1), (2), (3); EXEC myproc @t; Parameter must be declared READONLY CREATE PROCEDURE usetable 	( @t mytabREADONLY ...) AS   INSERT INTO lineitems SELECT * FROM @t;   UPDATE @t SET... -- no!
TVP Implementation and Performance Table Variables materialized in TEMPDB Faster than parameter arrays, BCP APIs still fastest Duration (ms) Number of rows passed
Table-Valued Parameters ,[object Object],[object Object]
Grouping Sets GROUP BY Extensions GROUPING SETS Specifies multiple groupings of data in one query CUBE * All permutations in column set ROLLUP* Sub totals, super aggregates and grand total. * don’t confuse with old nonstandard WITH CUBE and WITH ROLLUP options
Grouping_ID() New function that computes the level of grouping Takes a set of columns as parameters and returns the grouping level Helps identify the grouping set that each result row belongs to. GROUPING(col) function returns 1 bit: 1 if the result is grouped by the column, 0 otherwise.
Grouping Sets ,[object Object],[object Object]
Table Value Constructors Use the VALUES clause to construct a set of rows to insert multiple rows or as a derived tables INSERT INTO dbo.Customers(custid, companyname, phone, address)   VALUES   (1, 'cust 1', '(111) 111-1111', 'address 1'),   (2, 'cust 2', '(222) 222-2222', 'address 2'),   (3, 'cust 3', '(333) 333-3333', 'address 3'); SELECT * FROM ( VALUES  	 (CAST('20090730' AS DATE),'TishaB''Av') 	,(CAST('20090918' AS DATE),'Erev Rosh HaShana') 	,(CAST('20090919' AS DATE),'Rosh HaShana') 	) AS holidays (HolidayDate,description)
FILESTREAM Storage To Blob Or Not To Blob? Cons   LOBS take memory buffers   Updating LOBS causes fragmentation   Poor streaming capabalities Pros   Transactional consistency   Point-in-time backup & restore   Single storage and query vehicle ?
Dedicated BLOB Store Store BLOBs in Database Use File Servers Application Application Application BLOBs BLOBs BLOBs DB DB DB ,[object Object]
Integrated management
Data-level consistency
Enterprise-scales only
Scalability & ExpandabilityAdvantages ,[object Object]
Separate data management
Integration with structured data
Poor data streaming support
File size limitations
Affects performance of structured data querying
Complex application development & deployment
Separate data management
Enterprise-scales onlyChallenges ,[object Object]
NetAppNetFiler
EMC Centera
Fujitsu Nearline
SQL Server VARBINARY(MAX)Example  Blob Storage Options
FILESTREAM combines the best of 2 worlds ,[object Object]
Stores BLOB data as filesFILESTREAM Storage Application BLOBs FEATURES: ,[object Object]
 SQL buffer pool is not used and is available to   query processing
Windows file system interface provides streaming access to data
 Compressed volumes are supported
 File access is part of DB transaction.DB
It’s not only about storing but also about working with BLOBS:  ,[object Object]
Voice interpretation
Mixing satellite feeds & Spatial Data type for weather reports
and more…FILESTREAM Storage
FILESTREAM Programming Dual Programming Model TSQL (Same as SQL BLOB) Win32 Streaming File IO APIs Begin a SQL Server Transaction Obtain a symbolic PATH NAME & TRANSACTION CONTEXT Open a handle using sqlncli10.dll - OpenSqlFilestream Use Handle Within System.IO Classes Commit Transaction
// 1. Start up a database transaction –  SqlTransactiontxn = cxn.BeginTransaction(); // 2. Insert a row to create a handle for streaming. newSqlCommand("INSERT <Table> VALUES ( @mediaId, @fileName, @contentType);",cxn, txn); // 3. Get a filestreamPathName & transaction context. newSqlCommand("SELECT PathName(), GET_FILESTREAM_TRANSACTION_CONTEXT() FROM <Table>", cxn, txn); // 4. Get a Win32 file handle using SQL Native Client call. SafeFileHandle handle = SqlNativeClient.OpenSqlFilestream(...); // 5. Open up a new stream to write the file to the blob. FileStreamdestBlob= newFileStream(handle, FileAccess.Write); // 6. Loop through source file and write to FileStream handle while ((bytesRead = sourceFile.Read(buffer, 0, buffer.Length)) > 0)   {destBlob.Write(buffer, 0, bytesRead);} // 7. Commit transaction, cleanup connection. – txn.Commit(); FILESTREAM Programming
FILESTREAM Implementation Server & Instance level Enable filestream (in setup or configuration manager) Make sure port 445 (SMB) is open if remote access is used Exec sp_configure'filestream_access_level', [0/1/2] At Database Level Create a filestreamfilegroup & map to directory At Table Level Define VARBINARY(MAX) FILESTREAM column(s) Must have UNIQUEIDENTIFIER column (and file extension column if FTS is used)
FILESTREAM Implementation Integrated security ACLs (NT permissions) granted only to SQL Server service account. Permissions to access files implied by granting read/write permissions on FILESTREAM column in SQL Server. Naturally, only Windows authentication is supported. Integrated management BACKUP and RESTORE (for both database and log) also backup and restore FILESTREAM data. Note that in the FULL RECOVERY MODEL, “deleted” files are not deleted until log is backed up.
FILESTREAM Limitations Not supported  Remote FILESTREAM storage Database snapshot and Mirroring Supported: Replication (with SQL Server 2008 subscribers) Log shipping (with SQL Server 2008 secondaries) SQL Server Express Edition (4gb size limit does not apply to FILESTREAM data container) Features not integrated SQL Encryption Table Value Parameters
HierarchyID
HierarchyID When should I use it? ,[object Object]
Business organization charts
Product categories
Files/Folders management
Anything hierarchicalFeatures: ,[object Object]
  Available to CLR clients as the Sqlhierarchyid data type,[object Object]
Managable
2005 – CTEs can beused for recursive queriesCons: ,[object Object]
 Bad performance with large trees.2005 Alternatives - Adjacency Model
2005 Alternatives – Path Enumeration Each node holds a path to the root, as a string concatenation Pros: ,[object Object]
 Easy tree traversalCons:  ,[object Object]
 Searches are done with string functions (LIKE, string split),[object Object]
 Easy to indexCons: ,[object Object],(try to add another underboss…) 2005 Alternatives – Nested Sets
HierarchyID  New data type in SQL Server 2008  Uses path enumeration, but in a much more efficient binary representation.  Exposes methods to query the tree and set relations between nodes.  Remember that it’s just data  It’s up to the application to assign correct hierarchyID values to the nodes to represent the relations (using HierarchyID methods)  It’s up to the developer/DBA to create a unique constraint on the hierarchyID column
HierarchyID Nodes are ordered Root:  / First child: /1/ Second Child: /2/ First grandchild: /1/1/ Second: /1/2/ If you want to insert another grandchild between them - /1/1.1/
HierarchyID Methods hierarchyid::GetRoot() – get root of hierarchy tree Hierarchyid::Parse() – same as cast(@str as hierarchyid) node.ToString() - Logical string representation of node’s hID parent.GetDescendant(c1,c2)- returns a child node of parent between c1 and c2 node.GetAncestor(n) - hierarchyid of the nth ancestor of node node.IsDescendantOf(pID) - true if node is a descendant of pID node.GetLevel() – integer representing  depth of node node.GetReparentedValue(oldRoot,newRoot) – get path to newRoot for node who is descendant of oldRoot (use to move subt-trees within tree)
Depth-first Index Breadth-first Index Order by level, then path Useful for querying immediate children Ordered by path Useful for querying sub-trees e.g. all files in a subfolder HierarchyID Indexes
Insert Root Insert 1st Subordinate Insert rest of tree Query Hierarchical Data Demo Structure
HierarchyID ,[object Object]
Trees and Hierarchies,[object Object]
Date/Time Types SQL Server 2008 Save date and time in separate columns. 	Query all logins that occurred 18:00-7:00 during weekdays Higher precision  Scientific data Timezone offset 	Global applications
DATE and TIME DATE Data Type - Date Only 01-01-0001 to 31-12-9999 Gregorian Calendar Takes only 3 bytes TIME Data Type -  Time Only Variable Precision - 0 to 7 decimal places for seconds Up to 100 nanoseconds Takes 3-5 bytes, depending on precision
DATETIME2 and DATETIMEOFFSET DATETIME2 Data Type 01-01-0001 to 31-12-9999 Gregorian Calendar Variable Precision - to 100 nanoseconds Takes 6-8 bytes (same or less than DATETIME!) DATETIMEOFFSET 01-01-0001 to 31-12-9999 Gregorian Calendar Variable Precision - to 100 nanoseconds Time Zone Offset (From UTCTime) Preserved No Daylight Saving Time Support Takes 8-10 bytes
Date/Time Types Compatibility New Data Types Use Same T-SQL Functions DATENAME (datepart, date) DATEPART (datepart,date) DATEDIFF (datepart, startdate, enddate) DATEADD (datepart, number, date) Datepart can also be microsecond, nanosecond, TZoffset MONTH DAY YEAR CONVERT
Date Time Library Extensions Current date/time in higher precision  SYSDATETIME SYSUTCDATETIME SYSDATETIMEOFFSET Original date/time uses GETDATE, GETUTCDATE, CURRENT_TIMESTAMP ISDATE(datetime/smalldatetime) Special functions for DATETIMEOFFSET SWITCHOFFSET(datetimeoffset, timezone) TODATETIMEOFFSET(datetime, timezone)
Temporal Data Types ,[object Object],[object Object]
Spatial Data Type Represent geometric data: Point Lines Polygons Multi-point/line/polygon
Spatial Data Type SQL Server supports two spatial data types GEOMETRY - flat earth model GEOGRAPHY - round earth model Both types support all of the instanciable OGC types InstanceOf method can distinguish between them
Spatial Data Type - Input Spatial data is stored in a proprietary binary format Instance of the type can be NULL Can be input as Well Known binary - ST[Type]FromWKB Well Known text - ST[Type]FromText Geography Markup Language (GML) - GeomFromGml Can also use SQLCLR functions Parse Point - extension function Input from SQLCLR Type - SqlGeometry, SqlGeography
Spatial Data Type - Output Spatial Data Can Be Output As Well Known binary - STAsBinary Well Known text - STAsText GML - AsGml Text with Z and M values - AsTextZM SQLCLR standard method ToString - returns Well Known text As SQLCLR object - SqlGeometry, SqlGeography Other useful formats are GeoRSS, KML Not Directly Supported
Useful Spatial Methods & Properties
Spatial Data Types ,[object Object],[object Object]
Management Studio Enhancements Multi Instance Queries Quickly run SQL statements on multiple instances Downside  if you wish to insert the dataset to a single table, you better find some other tool. Useful for ad-hoc queries,  not more than that… Custom status bar color (per server) Quick trace New Activity Monitor
Reporting Services 2008 Enhancements ,[object Object],Reporting engine no longer requires IIS Better memory management ,[object Object],Better Processing ,[object Object]
Page to page response time is constant,[object Object]
Tablix Control ,[object Object],Best of both table data-region and matrix data-region Allows fixed and dynamic columns and rows Enables Arbitrary nesting on each axis Enables multiple parallel row/column members at each level Introduces optional omission of row/column headers

More Related Content

What's hot

Oracle 12c Multi Tenant
Oracle 12c Multi TenantOracle 12c Multi Tenant
Oracle 12c Multi TenantRed Stack Tech
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...Alex Zaballa
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowAlex Zaballa
 
Oracle Database 12c Release 2 - New Features On Oracle Database Exadata Expre...
Oracle Database 12c Release 2 - New Features On Oracle Database Exadata Expre...Oracle Database 12c Release 2 - New Features On Oracle Database Exadata Expre...
Oracle Database 12c Release 2 - New Features On Oracle Database Exadata Expre...Alex Zaballa
 
Oracle Basics and Architecture
Oracle Basics and ArchitectureOracle Basics and Architecture
Oracle Basics and ArchitectureSidney Chen
 
oracle upgradation
oracle upgradationoracle upgradation
oracle upgradationinfluxbob
 
Dan Hotka's Top 10 Oracle 12c New Features
Dan Hotka's Top 10 Oracle 12c New FeaturesDan Hotka's Top 10 Oracle 12c New Features
Dan Hotka's Top 10 Oracle 12c New FeaturesEmbarcadero Technologies
 
Oracle dba interview questions with answer
Oracle dba interview questions with answerOracle dba interview questions with answer
Oracle dba interview questions with answerupenpriti
 
Less17 flashback tb3
Less17 flashback tb3Less17 flashback tb3
Less17 flashback tb3Imran Ali
 
Less18 moving data
Less18 moving dataLess18 moving data
Less18 moving dataImran Ali
 
Less08 managing data and concurrency
Less08 managing data and concurrencyLess08 managing data and concurrency
Less08 managing data and concurrencyImran Ali
 
Crating a Robust Performance Strategy
Crating a Robust Performance StrategyCrating a Robust Performance Strategy
Crating a Robust Performance StrategyGuatemala User Group
 
Oracle-L11 using Oracle flashback technology-Mazenet solution
Oracle-L11 using  Oracle flashback technology-Mazenet solutionOracle-L11 using  Oracle flashback technology-Mazenet solution
Oracle-L11 using Oracle flashback technology-Mazenet solutionMazenetsolution
 
Major features postgres 11
Major features postgres 11Major features postgres 11
Major features postgres 11EDB
 
Ensuring Data Protection Using Oracle Flashback Features - Presentation
Ensuring Data Protection Using Oracle Flashback Features - PresentationEnsuring Data Protection Using Oracle Flashback Features - Presentation
Ensuring Data Protection Using Oracle Flashback Features - PresentationPini Dibask
 
Dba 3+ exp qus
Dba 3+ exp qusDba 3+ exp qus
Dba 3+ exp quskrreddy21
 
Oracle10g New Features I
Oracle10g New Features IOracle10g New Features I
Oracle10g New Features IDenish Patel
 

What's hot (19)

Oracle 12c Multi Tenant
Oracle 12c Multi TenantOracle 12c Multi Tenant
Oracle 12c Multi Tenant
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
 
Oracle Database 12c Release 2 - New Features On Oracle Database Exadata Expre...
Oracle Database 12c Release 2 - New Features On Oracle Database Exadata Expre...Oracle Database 12c Release 2 - New Features On Oracle Database Exadata Expre...
Oracle Database 12c Release 2 - New Features On Oracle Database Exadata Expre...
 
Oracle Basics and Architecture
Oracle Basics and ArchitectureOracle Basics and Architecture
Oracle Basics and Architecture
 
oracle upgradation
oracle upgradationoracle upgradation
oracle upgradation
 
Dan Hotka's Top 10 Oracle 12c New Features
Dan Hotka's Top 10 Oracle 12c New FeaturesDan Hotka's Top 10 Oracle 12c New Features
Dan Hotka's Top 10 Oracle 12c New Features
 
Oracle dba interview questions with answer
Oracle dba interview questions with answerOracle dba interview questions with answer
Oracle dba interview questions with answer
 
Less17 flashback tb3
Less17 flashback tb3Less17 flashback tb3
Less17 flashback tb3
 
Less18 moving data
Less18 moving dataLess18 moving data
Less18 moving data
 
Less08 managing data and concurrency
Less08 managing data and concurrencyLess08 managing data and concurrency
Less08 managing data and concurrency
 
Oracle 10g Introduction 1
Oracle 10g Introduction 1Oracle 10g Introduction 1
Oracle 10g Introduction 1
 
Crating a Robust Performance Strategy
Crating a Robust Performance StrategyCrating a Robust Performance Strategy
Crating a Robust Performance Strategy
 
Oracle-L11 using Oracle flashback technology-Mazenet solution
Oracle-L11 using  Oracle flashback technology-Mazenet solutionOracle-L11 using  Oracle flashback technology-Mazenet solution
Oracle-L11 using Oracle flashback technology-Mazenet solution
 
Major features postgres 11
Major features postgres 11Major features postgres 11
Major features postgres 11
 
Ensuring Data Protection Using Oracle Flashback Features - Presentation
Ensuring Data Protection Using Oracle Flashback Features - PresentationEnsuring Data Protection Using Oracle Flashback Features - Presentation
Ensuring Data Protection Using Oracle Flashback Features - Presentation
 
Dba 3+ exp qus
Dba 3+ exp qusDba 3+ exp qus
Dba 3+ exp qus
 
Oracle10g New Features I
Oracle10g New Features IOracle10g New Features I
Oracle10g New Features I
 
Oracle SQL Tuning
Oracle SQL TuningOracle SQL Tuning
Oracle SQL Tuning
 

Similar to Sql Server 2008 New Programmability Features

Database development coding standards
Database development coding standardsDatabase development coding standards
Database development coding standardsAlessandro Baratella
 
Mysqlppt
MysqlpptMysqlppt
MysqlpptReka
 
Overview of query evaluation
Overview of query evaluationOverview of query evaluation
Overview of query evaluationavniS
 
MYSQL
MYSQLMYSQL
MYSQLARJUN
 
My sql with querys
My sql with querysMy sql with querys
My sql with querysNIRMAL FELIX
 
Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007paulguerin
 
Azure Data Factory Data Flows Training (Sept 2020 Update)
Azure Data Factory Data Flows Training (Sept 2020 Update)Azure Data Factory Data Flows Training (Sept 2020 Update)
Azure Data Factory Data Flows Training (Sept 2020 Update)Mark Kromer
 
Mapping Data Flows Training April 2021
Mapping Data Flows Training April 2021Mapping Data Flows Training April 2021
Mapping Data Flows Training April 2021Mark Kromer
 
Ms sql server ii
Ms sql server  iiMs sql server  ii
Ms sql server iiIblesoft
 
Database COMPLETE
Database COMPLETEDatabase COMPLETE
Database COMPLETEAbrar ali
 
Introduction to sql new
Introduction to sql newIntroduction to sql new
Introduction to sql newSANTOSH RATH
 
Oracle tips and tricks
Oracle tips and tricksOracle tips and tricks
Oracle tips and tricksYanli Liu
 
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
Tony jambu   (obscure) tools of the trade for tuning oracle sq lsTony jambu   (obscure) tools of the trade for tuning oracle sq ls
Tony jambu (obscure) tools of the trade for tuning oracle sq lsInSync Conference
 
BIS06 Physical Database Models
BIS06 Physical Database ModelsBIS06 Physical Database Models
BIS06 Physical Database ModelsPrithwis Mukerjee
 
BIS06 Physical Database Models
BIS06 Physical Database ModelsBIS06 Physical Database Models
BIS06 Physical Database ModelsPrithwis Mukerjee
 

Similar to Sql Server 2008 New Programmability Features (20)

Database development coding standards
Database development coding standardsDatabase development coding standards
Database development coding standards
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
Overview of query evaluation
Overview of query evaluationOverview of query evaluation
Overview of query evaluation
 
Mysql1
Mysql1Mysql1
Mysql1
 
MYSQL
MYSQLMYSQL
MYSQL
 
My sql with querys
My sql with querysMy sql with querys
My sql with querys
 
Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007
 
Azure Data Factory Data Flows Training (Sept 2020 Update)
Azure Data Factory Data Flows Training (Sept 2020 Update)Azure Data Factory Data Flows Training (Sept 2020 Update)
Azure Data Factory Data Flows Training (Sept 2020 Update)
 
Mapping Data Flows Training April 2021
Mapping Data Flows Training April 2021Mapping Data Flows Training April 2021
Mapping Data Flows Training April 2021
 
Ms sql server ii
Ms sql server  iiMs sql server  ii
Ms sql server ii
 
My sql.ppt
My sql.pptMy sql.ppt
My sql.ppt
 
Database COMPLETE
Database COMPLETEDatabase COMPLETE
Database COMPLETE
 
Introduction to sql new
Introduction to sql newIntroduction to sql new
Introduction to sql new
 
Oracle tips and tricks
Oracle tips and tricksOracle tips and tricks
Oracle tips and tricks
 
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
Tony jambu   (obscure) tools of the trade for tuning oracle sq lsTony jambu   (obscure) tools of the trade for tuning oracle sq ls
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
 
BIS06 Physical Database Models
BIS06 Physical Database ModelsBIS06 Physical Database Models
BIS06 Physical Database Models
 
BIS06 Physical Database Models
BIS06 Physical Database ModelsBIS06 Physical Database Models
BIS06 Physical Database Models
 
Sql
SqlSql
Sql
 

More from sqlserver.co.il

Windows azure sql_database_security_isug012013
Windows azure sql_database_security_isug012013Windows azure sql_database_security_isug012013
Windows azure sql_database_security_isug012013sqlserver.co.il
 
Things you can find in the plan cache
Things you can find in the plan cacheThings you can find in the plan cache
Things you can find in the plan cachesqlserver.co.il
 
Sql server user group news january 2013
Sql server user group news   january 2013Sql server user group news   january 2013
Sql server user group news january 2013sqlserver.co.il
 
Query handlingbytheserver
Query handlingbytheserverQuery handlingbytheserver
Query handlingbytheserversqlserver.co.il
 
Adi Sapir ISUG 123 11/10/2012
Adi Sapir ISUG 123 11/10/2012Adi Sapir ISUG 123 11/10/2012
Adi Sapir ISUG 123 11/10/2012sqlserver.co.il
 
Products.intro.forum version
Products.intro.forum versionProducts.intro.forum version
Products.intro.forum versionsqlserver.co.il
 
SQL Explore 2012: P&T Part 3
SQL Explore 2012: P&T Part 3SQL Explore 2012: P&T Part 3
SQL Explore 2012: P&T Part 3sqlserver.co.il
 
SQL Explore 2012: P&T Part 2
SQL Explore 2012: P&T Part 2SQL Explore 2012: P&T Part 2
SQL Explore 2012: P&T Part 2sqlserver.co.il
 
SQL Explore 2012: P&T Part 1
SQL Explore 2012: P&T Part 1SQL Explore 2012: P&T Part 1
SQL Explore 2012: P&T Part 1sqlserver.co.il
 
SQL Explore 2012 - Tzahi Hakikat and Keren Bartal: Extended Events
SQL Explore 2012 - Tzahi Hakikat and Keren Bartal: Extended EventsSQL Explore 2012 - Tzahi Hakikat and Keren Bartal: Extended Events
SQL Explore 2012 - Tzahi Hakikat and Keren Bartal: Extended Eventssqlserver.co.il
 
SQL Explore 2012 - Michael Zilberstein: ColumnStore
SQL Explore 2012 - Michael Zilberstein: ColumnStoreSQL Explore 2012 - Michael Zilberstein: ColumnStore
SQL Explore 2012 - Michael Zilberstein: ColumnStoresqlserver.co.il
 
SQL Explore 2012 - Meir Dudai: DAC
SQL Explore 2012 - Meir Dudai: DACSQL Explore 2012 - Meir Dudai: DAC
SQL Explore 2012 - Meir Dudai: DACsqlserver.co.il
 
SQL Explore 2012 - Aviad Deri: Spatial
SQL Explore 2012 - Aviad Deri: SpatialSQL Explore 2012 - Aviad Deri: Spatial
SQL Explore 2012 - Aviad Deri: Spatialsqlserver.co.il
 
Bi303 data warehousing with fast track and pdw - Assaf Fraenkel
Bi303 data warehousing with fast track and pdw - Assaf FraenkelBi303 data warehousing with fast track and pdw - Assaf Fraenkel
Bi303 data warehousing with fast track and pdw - Assaf Fraenkelsqlserver.co.il
 

More from sqlserver.co.il (20)

Windows azure sql_database_security_isug012013
Windows azure sql_database_security_isug012013Windows azure sql_database_security_isug012013
Windows azure sql_database_security_isug012013
 
Things you can find in the plan cache
Things you can find in the plan cacheThings you can find in the plan cache
Things you can find in the plan cache
 
Sql server user group news january 2013
Sql server user group news   january 2013Sql server user group news   january 2013
Sql server user group news january 2013
 
DAC 2012
DAC 2012DAC 2012
DAC 2012
 
Query handlingbytheserver
Query handlingbytheserverQuery handlingbytheserver
Query handlingbytheserver
 
Adi Sapir ISUG 123 11/10/2012
Adi Sapir ISUG 123 11/10/2012Adi Sapir ISUG 123 11/10/2012
Adi Sapir ISUG 123 11/10/2012
 
Products.intro.forum version
Products.intro.forum versionProducts.intro.forum version
Products.intro.forum version
 
SQL Explore 2012: P&T Part 3
SQL Explore 2012: P&T Part 3SQL Explore 2012: P&T Part 3
SQL Explore 2012: P&T Part 3
 
SQL Explore 2012: P&T Part 2
SQL Explore 2012: P&T Part 2SQL Explore 2012: P&T Part 2
SQL Explore 2012: P&T Part 2
 
SQL Explore 2012: P&T Part 1
SQL Explore 2012: P&T Part 1SQL Explore 2012: P&T Part 1
SQL Explore 2012: P&T Part 1
 
SQL Explore 2012 - Tzahi Hakikat and Keren Bartal: Extended Events
SQL Explore 2012 - Tzahi Hakikat and Keren Bartal: Extended EventsSQL Explore 2012 - Tzahi Hakikat and Keren Bartal: Extended Events
SQL Explore 2012 - Tzahi Hakikat and Keren Bartal: Extended Events
 
SQL Explore 2012 - Michael Zilberstein: ColumnStore
SQL Explore 2012 - Michael Zilberstein: ColumnStoreSQL Explore 2012 - Michael Zilberstein: ColumnStore
SQL Explore 2012 - Michael Zilberstein: ColumnStore
 
SQL Explore 2012 - Meir Dudai: DAC
SQL Explore 2012 - Meir Dudai: DACSQL Explore 2012 - Meir Dudai: DAC
SQL Explore 2012 - Meir Dudai: DAC
 
SQL Explore 2012 - Aviad Deri: Spatial
SQL Explore 2012 - Aviad Deri: SpatialSQL Explore 2012 - Aviad Deri: Spatial
SQL Explore 2012 - Aviad Deri: Spatial
 
מיכאל
מיכאלמיכאל
מיכאל
 
נועם
נועםנועם
נועם
 
עדי
עדיעדי
עדי
 
מיכאל
מיכאלמיכאל
מיכאל
 
Bi303 data warehousing with fast track and pdw - Assaf Fraenkel
Bi303 data warehousing with fast track and pdw - Assaf FraenkelBi303 data warehousing with fast track and pdw - Assaf Fraenkel
Bi303 data warehousing with fast track and pdw - Assaf Fraenkel
 
DBCC - Dubi Lebel
DBCC - Dubi LebelDBCC - Dubi Lebel
DBCC - Dubi Lebel
 

Recently uploaded

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 

Recently uploaded (20)

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 

Sql Server 2008 New Programmability Features

  • 2. Valinor SQL Server Professional Services Database Projects end-to-end High Availability & Disaster Recovery Upgrades Performance Analysis & Tuning Security Training contact@valinor.co.il
  • 3.
  • 9.
  • 10. Agenda T-SQL enhancements MERGE Statement Table Valued Parameters Grouping Sets Compound Assignments Table value constructors New data types Filestream HierarchyID Temporal data types Spatial data types SSMS Enhancements Intellisense Multi-instances query Registered Servers properties SSRS Enhancements More new features Data compression Resource Governor
  • 11. T-SQL Enhancements MERGE Statement Table Valued Parameters Grouping Sets Compound Assignments Table value constructors
  • 12. MERGE Statement What is it? MERGE allows you to compare two tables and apply changes to one of them according to matching and non-matching rows Allows multiple set operations in a single SQL statement Operations can be INSERT, UPDATE, DELETE ANSI SQL 2006 compliant - with extensions
  • 13. What can I do with it? ETL processes “Update if exists, insert otherwise” stored procedures Data comparison, verification and modification MERGE Statement
  • 14. MERGE Syntax MERGE [INTO] target_table AS target USING source_table AS source (table, view, derived table) ON <merge_search_conditions> WHEN MATCHED [AND <other predicates>] UPDATE SET target.col2 = source.col2 (or delete) WHEN NOT MATCHED [BY TARGET] [AND <other predicates>] INSERT [(col_list)] VALUES (col_list) WHEN NOT MATCHED BY SOURCE [AND <other predicates>] DELETE (or update) OUTPUT $action, inserted.col, deleted.col, source.col; Get used to semicolons!
  • 15. MERGE Statement $action function in OUTPUT clause Multiple WHEN clauses possible For MATCHED and NOT MATCHED BY SOURCE Only one WHEN clause for NOT MATCHED Rows affected includes total rows affected by all clauses
  • 16. MERGE Performance MERGE statement is transactional No explicit transaction required One pass through tables At most a full outer join Matching rows (inner join) = when matched Left-outer join rows = when not matched Right-outer join rows = when not matched by source When optimizing, optimize joins Index columns used in ON clause (if possible, unique index on source table)
  • 17. MERGE and Determinism UPDATE using a JOIN is non-deterministic If more than one row in source matches ON clause, either/any row can be used for the UPDATE. MERGE is deterministic If more than one row in source matches ON clause, an exception is thrown.
  • 18. MERGE & Triggers When there are triggers on the target table Trigger is raised per DML (insert/update/delete) “Inserted” and “deleted” tables are populated In much the same way, MERGE is treated by replication as a series of insert, update and delete commands.
  • 19. Where is MERGE useful? Replace UPDATE … JOIN and DELETE … JOIN statements ETL Processes Set comparison Update-if-exists, insert-otherwise procedures IF EXISTS (SELECT … FROM tbl) UPDATE tbl … ELSE INSERT …
  • 20.
  • 21. Table Types SQL Server has table variables DECLARE @t TABLE (id int); SQL Server 2008 adds strongly typed table variables CREATE TYPE mytab AS TABLE (id int); DECLARE @t mytab; Parameters must use strongly typed table variables
  • 22. Table Variables are Input Only Declare and initialize TABLE variable DECLARE @t mytab; INSERT @t VALUES (1), (2), (3); EXEC myproc @t; Parameter must be declared READONLY CREATE PROCEDURE usetable ( @t mytabREADONLY ...) AS INSERT INTO lineitems SELECT * FROM @t; UPDATE @t SET... -- no!
  • 23. TVP Implementation and Performance Table Variables materialized in TEMPDB Faster than parameter arrays, BCP APIs still fastest Duration (ms) Number of rows passed
  • 24.
  • 25. Grouping Sets GROUP BY Extensions GROUPING SETS Specifies multiple groupings of data in one query CUBE * All permutations in column set ROLLUP* Sub totals, super aggregates and grand total. * don’t confuse with old nonstandard WITH CUBE and WITH ROLLUP options
  • 26. Grouping_ID() New function that computes the level of grouping Takes a set of columns as parameters and returns the grouping level Helps identify the grouping set that each result row belongs to. GROUPING(col) function returns 1 bit: 1 if the result is grouped by the column, 0 otherwise.
  • 27.
  • 28. Table Value Constructors Use the VALUES clause to construct a set of rows to insert multiple rows or as a derived tables INSERT INTO dbo.Customers(custid, companyname, phone, address)   VALUES   (1, 'cust 1', '(111) 111-1111', 'address 1'),   (2, 'cust 2', '(222) 222-2222', 'address 2'),   (3, 'cust 3', '(333) 333-3333', 'address 3'); SELECT * FROM ( VALUES (CAST('20090730' AS DATE),'TishaB''Av') ,(CAST('20090918' AS DATE),'Erev Rosh HaShana') ,(CAST('20090919' AS DATE),'Rosh HaShana') ) AS holidays (HolidayDate,description)
  • 29. FILESTREAM Storage To Blob Or Not To Blob? Cons LOBS take memory buffers Updating LOBS causes fragmentation Poor streaming capabalities Pros Transactional consistency Point-in-time backup & restore Single storage and query vehicle ?
  • 30.
  • 34.
  • 39. Affects performance of structured data querying
  • 42.
  • 46. SQL Server VARBINARY(MAX)Example Blob Storage Options
  • 47.
  • 48.
  • 49. SQL buffer pool is not used and is available to query processing
  • 50. Windows file system interface provides streaming access to data
  • 51. Compressed volumes are supported
  • 52. File access is part of DB transaction.DB
  • 53.
  • 55. Mixing satellite feeds & Spatial Data type for weather reports
  • 57. FILESTREAM Programming Dual Programming Model TSQL (Same as SQL BLOB) Win32 Streaming File IO APIs Begin a SQL Server Transaction Obtain a symbolic PATH NAME & TRANSACTION CONTEXT Open a handle using sqlncli10.dll - OpenSqlFilestream Use Handle Within System.IO Classes Commit Transaction
  • 58. // 1. Start up a database transaction – SqlTransactiontxn = cxn.BeginTransaction(); // 2. Insert a row to create a handle for streaming. newSqlCommand("INSERT <Table> VALUES ( @mediaId, @fileName, @contentType);",cxn, txn); // 3. Get a filestreamPathName & transaction context. newSqlCommand("SELECT PathName(), GET_FILESTREAM_TRANSACTION_CONTEXT() FROM <Table>", cxn, txn); // 4. Get a Win32 file handle using SQL Native Client call. SafeFileHandle handle = SqlNativeClient.OpenSqlFilestream(...); // 5. Open up a new stream to write the file to the blob. FileStreamdestBlob= newFileStream(handle, FileAccess.Write); // 6. Loop through source file and write to FileStream handle while ((bytesRead = sourceFile.Read(buffer, 0, buffer.Length)) > 0) {destBlob.Write(buffer, 0, bytesRead);} // 7. Commit transaction, cleanup connection. – txn.Commit(); FILESTREAM Programming
  • 59. FILESTREAM Implementation Server & Instance level Enable filestream (in setup or configuration manager) Make sure port 445 (SMB) is open if remote access is used Exec sp_configure'filestream_access_level', [0/1/2] At Database Level Create a filestreamfilegroup & map to directory At Table Level Define VARBINARY(MAX) FILESTREAM column(s) Must have UNIQUEIDENTIFIER column (and file extension column if FTS is used)
  • 60. FILESTREAM Implementation Integrated security ACLs (NT permissions) granted only to SQL Server service account. Permissions to access files implied by granting read/write permissions on FILESTREAM column in SQL Server. Naturally, only Windows authentication is supported. Integrated management BACKUP and RESTORE (for both database and log) also backup and restore FILESTREAM data. Note that in the FULL RECOVERY MODEL, “deleted” files are not deleted until log is backed up.
  • 61. FILESTREAM Limitations Not supported Remote FILESTREAM storage Database snapshot and Mirroring Supported: Replication (with SQL Server 2008 subscribers) Log shipping (with SQL Server 2008 secondaries) SQL Server Express Edition (4gb size limit does not apply to FILESTREAM data container) Features not integrated SQL Encryption Table Value Parameters
  • 63.
  • 67.
  • 68.
  • 70.
  • 71. Bad performance with large trees.2005 Alternatives - Adjacency Model
  • 72.
  • 73.
  • 74.
  • 75.
  • 76. HierarchyID New data type in SQL Server 2008 Uses path enumeration, but in a much more efficient binary representation. Exposes methods to query the tree and set relations between nodes. Remember that it’s just data It’s up to the application to assign correct hierarchyID values to the nodes to represent the relations (using HierarchyID methods) It’s up to the developer/DBA to create a unique constraint on the hierarchyID column
  • 77. HierarchyID Nodes are ordered Root: / First child: /1/ Second Child: /2/ First grandchild: /1/1/ Second: /1/2/ If you want to insert another grandchild between them - /1/1.1/
  • 78. HierarchyID Methods hierarchyid::GetRoot() – get root of hierarchy tree Hierarchyid::Parse() – same as cast(@str as hierarchyid) node.ToString() - Logical string representation of node’s hID parent.GetDescendant(c1,c2)- returns a child node of parent between c1 and c2 node.GetAncestor(n) - hierarchyid of the nth ancestor of node node.IsDescendantOf(pID) - true if node is a descendant of pID node.GetLevel() – integer representing depth of node node.GetReparentedValue(oldRoot,newRoot) – get path to newRoot for node who is descendant of oldRoot (use to move subt-trees within tree)
  • 79. Depth-first Index Breadth-first Index Order by level, then path Useful for querying immediate children Ordered by path Useful for querying sub-trees e.g. all files in a subfolder HierarchyID Indexes
  • 80. Insert Root Insert 1st Subordinate Insert rest of tree Query Hierarchical Data Demo Structure
  • 81.
  • 82.
  • 83. Date/Time Types SQL Server 2008 Save date and time in separate columns. Query all logins that occurred 18:00-7:00 during weekdays Higher precision Scientific data Timezone offset Global applications
  • 84. DATE and TIME DATE Data Type - Date Only 01-01-0001 to 31-12-9999 Gregorian Calendar Takes only 3 bytes TIME Data Type - Time Only Variable Precision - 0 to 7 decimal places for seconds Up to 100 nanoseconds Takes 3-5 bytes, depending on precision
  • 85. DATETIME2 and DATETIMEOFFSET DATETIME2 Data Type 01-01-0001 to 31-12-9999 Gregorian Calendar Variable Precision - to 100 nanoseconds Takes 6-8 bytes (same or less than DATETIME!) DATETIMEOFFSET 01-01-0001 to 31-12-9999 Gregorian Calendar Variable Precision - to 100 nanoseconds Time Zone Offset (From UTCTime) Preserved No Daylight Saving Time Support Takes 8-10 bytes
  • 86. Date/Time Types Compatibility New Data Types Use Same T-SQL Functions DATENAME (datepart, date) DATEPART (datepart,date) DATEDIFF (datepart, startdate, enddate) DATEADD (datepart, number, date) Datepart can also be microsecond, nanosecond, TZoffset MONTH DAY YEAR CONVERT
  • 87. Date Time Library Extensions Current date/time in higher precision SYSDATETIME SYSUTCDATETIME SYSDATETIMEOFFSET Original date/time uses GETDATE, GETUTCDATE, CURRENT_TIMESTAMP ISDATE(datetime/smalldatetime) Special functions for DATETIMEOFFSET SWITCHOFFSET(datetimeoffset, timezone) TODATETIMEOFFSET(datetime, timezone)
  • 88.
  • 89. Spatial Data Type Represent geometric data: Point Lines Polygons Multi-point/line/polygon
  • 90. Spatial Data Type SQL Server supports two spatial data types GEOMETRY - flat earth model GEOGRAPHY - round earth model Both types support all of the instanciable OGC types InstanceOf method can distinguish between them
  • 91. Spatial Data Type - Input Spatial data is stored in a proprietary binary format Instance of the type can be NULL Can be input as Well Known binary - ST[Type]FromWKB Well Known text - ST[Type]FromText Geography Markup Language (GML) - GeomFromGml Can also use SQLCLR functions Parse Point - extension function Input from SQLCLR Type - SqlGeometry, SqlGeography
  • 92. Spatial Data Type - Output Spatial Data Can Be Output As Well Known binary - STAsBinary Well Known text - STAsText GML - AsGml Text with Z and M values - AsTextZM SQLCLR standard method ToString - returns Well Known text As SQLCLR object - SqlGeometry, SqlGeography Other useful formats are GeoRSS, KML Not Directly Supported
  • 93. Useful Spatial Methods & Properties
  • 94.
  • 95. Management Studio Enhancements Multi Instance Queries Quickly run SQL statements on multiple instances Downside if you wish to insert the dataset to a single table, you better find some other tool. Useful for ad-hoc queries, not more than that… Custom status bar color (per server) Quick trace New Activity Monitor
  • 96.
  • 97.
  • 98.
  • 100. Mixed Dynamic & Static columns 2005 2008
  • 101. Enriched Visualizations – Dundas Charts
  • 102. Enriched Visualizations – Dundas Gauges
  • 103.
  • 104. Report Builder 2Reporting Services 2008 Usability features
  • 105.
  • 106. High-end disks are expensive
  • 107. Multiple copies required – test, HA, backups
  • 108. Cost of managing storage rises with database size
  • 109. Time taken for backups and maintenance operations (IO bound)
  • 110. Time taken to restore backups in a disaster
  • 111. Migration from other platforms (Oracle or DB2) that support compression is not possible
  • 112. Compressing data leads to better memory utilization
  • 113. SQL Server needs data compression!! (But only in Enterprise edition…) Data Compression
  • 114.
  • 115. SQL Server 2005 SP2 introduces vardecimal
  • 116. Same solution – variable length column, empty bytes are not stored
  • 117. But on a smaller scale:
  • 119. Decimal’s maximum capacity is 17 bytes (percision 29-38)
  • 120.
  • 121. Compresses fixed-length data types by turning them into variable-length (a step up from vardecimal).
  • 122. Row meta data (row header, null bitmap) is also saved in a new variable-length format.
  • 126.
  • 127. Row Compression Row compression CREATE TABLE Countries (ID INT, Name CHAR(50)) 4 bytes 50 bytes (4b + 50b) * 3 rows = 162 bytes (not including row overhead)
  • 128. Row Compression Row compression CREATE TABLE Countries (ID INT, Name CHAR(50)) 50 bytes 4 bytes Row Compression 1 byte 7 bytes 1 byte 11 bytes 1 byte 6 bytes
  • 129. Row Compression Row compression CREATE TABLE Countries (ID INT, Name CHAR(50)) 1 byte 7 bytes 1 byte 11 bytes 1 byte 6 bytes 162 bytes reduced to: 1+7+1+11+1+6 = 27 bytes (not including row overhead and 4 bits per column for offsets)
  • 130.
  • 131. The largest value for each column is stored in the compression information structure (CI).
  • 132. The in-row values are replaced with indicators of full or partial matches with the value in the CI.
  • 133.
  • 134. 2nd phase: Prefix compression example Prefix compression Page Compression
  • 135.
  • 136. The in-row values are replaced with pointers to the CI area.Dictionary compression
  • 137.
  • 138.
  • 139. Setting data compression on a table (CREATE/ALTER TABLE ) only affects the heap or the clustered index.
  • 140.
  • 141. When is data compressed? With ROW compression, compression occurs row by row, whenever a row is inserted or updated. With PAGE compression, it gets complicated. In heaps, PAGE compression only occurs in the following ways: On table REBUILD When data is inserted with BULK INSERT When data is inserted with INSERT INTO … WITH(TABLOCK)
  • 142. When is data compressed? In indexes, pages are only ROW compressed until they fill up. When the next insert occurs, it triggers PAGE compression. If there’s space left for the new row after PAGE compression, the row is compressed and inserted into the newly compressed page. If there’s no space, the page is not compressed and the row will be inserted on a new page
  • 143.
  • 144. Data Compression: Limitations Data compression is Enterprise Edition only Data compression cannot be used in conjunction with sparse columns Data compression doesn’t increase the capacity per row. You can’t insert more data per row with data compression. This ensures that disabling compression will always succeed
  • 145. Data Compression: Limitations Non-leaf level pages in indexes are only compressed using ROW compression Heap pages are not PAGE compressed during regular DML LOB values out-of-row are not compressed Data exported using BCP is always uncompressed. Data imported using BCP will be compressed causing increased CPU usage.
  • 146.
  • 150. Data Compression Performance Generalization No noticeable impact on INDEX SEEKs Noticeable impact on large data modification operations. Lower IO, higher CPU on index/table scans. Duration depends on overall system configuration. Data compression should be tested thoroughly before setting up in production
  • 151. So when should I use it? Read-intensive databases with low CPU usage Systems with small Buffer cache (relative to data size) Databases queried for few rows at a time (i.e. index seeks). There’s always a trade-off. Remember the equation: Data compression = Less IO = Smaller memory footprint But also Data compression = Higher CPU usage
  • 152.
  • 153. No workload differentiationMemory, CPU, Threads, … Resources
  • 154.
  • 155. Limit resource usage (e.g. CPU, memory, simultaneous requests)
  • 157. Limit resource usage of administrative tasks
  • 158.
  • 159. Thank you! Any questions?
  • 160. References SQL Server 2008 Developer Training Kit Introduction to New T-SQL Programmability Features in SQL Server 2008 / Itzik Ben Gan Using The Resource Governor / Aaron Bertrand Reporting Services in SQL Server 2008 / Ann Weber Data Compression: Strategy, Capacity Planning and Best Practices / Sanjay Mishra