what's new for developers in sql server 2008?
DESCRIPTION
TRANSCRIPT
Eric NelsonDeveloper [email protected] – I will replyhttp://blogs.msdn.com/ericnel - tends to be about .NET and datahttp://blogs.msdn.com/goto100 - all about Visual Basichttp://twitter.com/ericnel - pot luck :-)http://blogs.msdn.com/ukdevevents The ONLY LINK you need!
1. First PC – ZX80 in 1980 (then BBC Micro, Atari 520STFM and Macintosh LC)
2. First computer job... FORTAN in 19863. Wrote most LOC on... Unix using C4. Favourite IDE of all time ...GNU Emacs5. Joined Microsoft DRG in 19966. Early adoption work on ASP, SQL 6.5, MTS...7. Went “Back to development” in July 2008 – in VB8. I Geek to Live (not Live to Geek)9. I am editor of the UK MSDN Flash10. I am fascinated by ALT.NET values and practices
http://blogs.msdn.com/ukdevevents The ONLY LINK you need!
I live near Bath with wife, 2 kids, 1 dog (and many pet graves in the garden)I originally intended to be a naval officerI am very shy...seriously!
http://blogs.msdn.com/ukdevevents The ONLY LINK you need!
Sign up to the MSDN FlashFeedback, vote etc
Technical articles for the UK MSDN Flash
400 to 500 words
War stories around VB6 to .NETYour right (or left) arm in the air
NB: not all the time
Give a flavour of the new “stuff” in SQL Server 2008
for development and
an insight into the direction we are taking with data
TSQL EnhancementsSQL-2006Major and minor
Beyond RelationalFilestreamFull text search SpatialSemi-structured
Futures*Object Relational ManagementSQL Data Services
In one hourIn one hour
Released August 6th 2008Many versions!
• Date & TimeDate types
• Table value constructor using VALUES clause• MERGE• Table Types and Table Value Parameters• GROUPING SET
SQL language
• IDE improvements• Compound assignment operators• Declaring and initializing variables
Delighters
IDE ImprovementsDebugging is back!Intellisense has made it in
Compound Assignment operators: +=, -=, *=, /=
Variable initialization during declaration
UPDATE Inventory SET quantity += s.quantityFROM Inventory AS i INNER JOIN Sales AS s ON i.id = s.id
DECLAER @v int = 5;DECLARE @v1 varchar(10) = ‘xxxxx’;
Insert multiple rows based on values in a single INSERT statementSQL 2006 standard compatible
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'), (4, 'cust 4', '(444) 444-4444', 'address 4'), (5, 'cust 5', '(555) 555-5555', 'address 5');
Single statement that combines multiple DML operationsOperates on a join between source and targetSQL-2006 compliant
UPDATE TGT SET TGT.quantity = TGT.quantity + SRC.quantity, TGT.LastTradeDate = SRC.TradeDateFROM dbo.StockHolding AS TGT JOIN dbo.StockTrading AS SRC ON TGT.stock = SRC.stock;
INSERT INTO dbo.StockHolding (stock, lasttradedate, quantity) SELECT stock, tradedate, quantity FROM dbo.StockTrading AS SRC WHERE NOT EXISTS (SELECT * FROM dbo.StockHolding AS TGT WHERE TGT.stock = SRC.stock);
MERGE INTO dbo.StockHolding AS TGTUSING dbo.StockTrading AS SRCON TGT.stock = SRC.stockWHEN MATCHED AND (t.quantity + s.quantity = 0) THEN DELETEWHEN MATCHED THEN UPDATE SET t.LastTradeDate = s.TradeDate,
t.quantity += s.quantityWHEN NOT MATCHED THEN INSERT VALUES (s.Stock,s.TradeDate,s.Quantity)
Pre-SQL 2008 SQL 2008
Source Table(Stock
Trading)Target Table
(Stock Holding)
Merged Table(Stock
Holding)
INSERT
UPDATE
DELETE
A new user defined type - TableCan define indexes and constraints
Can be used for declaring table variablesInput parameters of Table type on SPs/Functions
Optimized to scale and perform better for large dataBehaves like BCP inside serverIn ADO.NET SqlDbType.Structured
CREATE TYPE myTableType AS TABLE (id INT, name NVARCHAR(100),qty INT);
CREATE PROCEDURE myProc (@tvp myTableType READONLY) AS…
Define multiple groupings in the same queryProduces a single result set that is equivalent to a UNION ALL of differently grouped rowsSQL 2006 standard compatiable
SELECT customerType,Null as TerritoryID,MAX(ModifiedDate)FROM Sales.Customer GROUP BY customerTypeUNION ALLSELECT Null as customerType,TerritoryID,MAX(ModifiedDate)FROM Sales.Customer GROUP BY TerritoryID order by TerritoryID
SELECT customerType,TerritoryID,MAX(ModifiedDate)FROM Sales.Customer GROUP BY GROUPING SETS ((customerType), (TerritoryID)) order by customerType
Pre-SQL 2008 SQL 2008
CREATE TABLE Employee { FirstName VARCHAR(10), LastName VARCHAR(10), Birthday DATE, …}
SELECT Birthday AS BirthDay FROM Employee
INSERT INTO T (datetime2_col) VALUES (‘1541-01-01’)
INSERT INTO T (time_col) VALUES (’12:30:29.1176548’)
CREATE TABLE online-purchase-order { item-id int, item-name VARCHAR(30), qty int, purchase-time datetimeoffset, …}// For value ‘2005-09-08 12:20:19.345 -08:00’INSERT INTO online-purchase-order VALUES (…., ‘2005-09-08 12:20:19.345 -08:00’ ,..)
• Large year range (1~9999)
• Storage saving• Easy programming
DATE
• Large or optional precision (0 ~ 100ns)
• Easy programmingTIME
• Large year range• Large or optional
precisionDATETIME
2
• Datetime + time zone offset
• UTC enabled• Easy programming
DATETIMEOFFSET
SQL Server SQL Server 20052005
SQL Server SQL Server 20052005 SQL Server 2008SQL Server 2008SQL Server 2008SQL Server 2008
•HierarchyID•Large UDTs•Sparse Columns•Wide Tables•Filtered Indices•XML Upgrades
Relational Semi Structured
•User Defined Types•XML Data Type and Functions
• Full Text IndexingDocuments
& Multimedia
• Filestream• Integrated FTS
Spatial
• Fully supported Geometry and Geography data types and Functions
Remote BLOB StorageRemote BLOB Storage FILESTREAM StorageFILESTREAM StorageSQL BLOBSQL BLOB
Documents &
Multimedia
Use File Servers
Use File Servers
DBDB
ApplicationApplication
BLOBBLOB
Dedicated BLOB Store
Dedicated BLOB Store
DBDB
ApplicationApplication
BLOBLOBB
Store BLOBs in Database
Store BLOBs in Database
DBDB
ApplicationApplication
BLOBBLOB
Store BLOBs in DB + File
System
Store BLOBs in DB + File
SystemApplicationApplication
BLOBBLOB
DBDB
Storage Attribute on VARBINARY(MAX)Works with integrated FTSUnstructured data stored directly in the file system (requires NTFS)Dual Programming Model
TSQL (Same as SQL BLOB)Win32 Streaming APIs with T-SQL transactional semantics
AdvantagesIntegrated ManageabilitySQL Server Security StackDual model
Documents &
Multimedia
Store BLOBs in DB + File System
Store BLOBs in DB + File System
ApplicationApplication
BLOBBLOB
DBDB
Full-Text Engine and Indexes fully integrated
Catalog, index and stopword lists now inside the database
Better performance in many common scenarios
Make mixed queries perform and scaleOptimizer has knowledge about FT index
Documents &
Multimedia
SELECT * FROM candidates WHERE CONTAINS(resume,’”SQL Server”’)
AND ZipCode = ‘98052’
SELECT * FROM candidates WHERE CONTAINS(resume,’”SQL Server”’)
AND ZipCode = ‘98052’
Populating an index of 20million rows of 1k data on identical hardware (time in minutes)
Documents &
Multimedia
2 min 1 min
Proliferation of geographical dataGPS Systems, Virtual Earth, Live Search Maps etcNew opportunities for spatially aware apps
Storage and retrieval of spatial data using standard SQLNew Spatial Data Types + methods + indexes
geometry - Flat Earth (Planar) geography - Round Earth (Geodetic)
Offers full set of Open Geospatial Consortium components
Spatial
11
22334455
HierarchyID Store arbitrary hierarchies of data and efficiently query them
Large UDTs No more 8K limit on User Defined Types
Sparse Columns Optimized storage for sparsely populated columns
Wide Tables Support thousands of sparse columns
Filtered Indices Define indices over subsets of data in tables
11 33
44
55
22
// Create a Filtered Indexes
// Sparse columnCreate Table Products(Id int, Type nvarchar(16)…, Resolution int SPARSE, ZoomLength int SPARSE);
// Filtered IndicesCreate Index ZoomIdx on Products(ZoomLength) where Type = ‘Camera’;
// HierarchyID CREATE TABLE [dbo].[Folder]( [FolderNode] HIERARCHYID NOT NULL UNIQUE, [Level] AS [FolderNode].GetLevel() PERSISTED, [Description] NVARCHAR(50) NOT NULL);
// Create a Filtered Indexes
// Sparse columnCreate Table Products(Id int, Type nvarchar(16)…, Resolution int SPARSE, ZoomLength int SPARSE);
// Filtered IndicesCreate Index ZoomIdx on Products(ZoomLength) where Type = ‘Camera’;
// HierarchyID CREATE TABLE [dbo].[Folder]( [FolderNode] HIERARCHYID NOT NULL UNIQUE, [Level] AS [FolderNode].GetLevel() PERSISTED, [Description] NVARCHAR(50) NOT NULL);
Relational Semi Structured
What is it?Technique for working with relational tables as if they were objects in memoryIntention is to hide away the complexity of the underlying tables and give a uniform way of working with data
Why use it?ProductivityRetain database independence
Which ORM?There are many ORMs for .NET developers already in existence. E.g.
LLBLGen Pro http://www.llblgen.com/Nhibernate http://www.hibernate.org/343.htmlEntitySpaces http://www.entityspaces.net/Portal/Default.aspx
LINQ to SQL.NET Framework 3.5, Nov 2007Only SQL ServerSimpleEasy to learn and master
LINQ to Entities (ADO.NET Entity Framework)
.NET Framework 3.5 SP1, Aug 2008“Any” RDBMSComplexEasy to learn, hard to masterStrategic
HTTP (AtomPub)
Clients(Tools, Libraries, etc)
Clients(Tools, Libraries, etc)
SQL Data ServicesSQL Data ServicesSQL Data ServicesSQL Data ServicesADO.NET Data ADO.NET Data Services FrameworkServices Framework
ADO.NET Data ADO.NET Data Services FrameworkServices Framework
SQL Server
(On premises data service)
(Cloud data service)
Data Data Access Access
LibLib
Data Data Access Access
LibLib
SDS SDS RuntimRuntim
ee
SDS SDS RuntimRuntim
ee
REST / REST / SOAPSOAP
REST / REST / SOAPSOAP
Data Data Access Access
LibLib
Data Data Access Access
LibLib
SDS SDS RuntimRuntim
ee
SDS SDS RuntimRuntim
ee
REST / REST / SOAPSOAP
REST / REST / SOAPSOAP
Data Data Access Access
LibLib
Data Data Access Access
LibLib
SDS SDS RuntimRuntim
ee
SDS SDS RuntimRuntim
ee
REST / REST / SOAPSOAP
REST / REST / SOAPSOAP
Data Data Access Access
LibLib
Data Data Access Access
LibLib
SDS SDS RuntimRuntim
ee
SDS SDS RuntimRuntim
ee
REST / REST / SOAPSOAP
REST / REST / SOAPSOAP
Data Data Access Access
LibLib
Data Data Access Access
LibLib
SDS SDS RuntimRuntim
ee
SDS SDS RuntimRuntim
ee
REST / REST / SOAPSOAP
REST / REST / SOAPSOAP
Data Data Access Access
LibLib
Data Data Access Access
LibLib
SDS SDS RuntimRuntim
ee
SDS SDS RuntimRuntim
ee
REST / REST / SOAPSOAP
REST / REST / SOAPSOAP
Data Data Access Access
LibLib
Data Data Access Access
LibLib
SDS SDS RuntimRuntim
ee
SDS SDS RuntimRuntim
ee
REST / REST / SOAPSOAP
REST / REST / SOAPSOAP
Mgmt. Mgmt. ServicesServices
Mgmt. Mgmt. ServicesServices
DistribuDistributed ted
Data Data FabricFabric
DistribuDistributed ted
Data Data FabricFabric
SQL SQL ServerServer
SQL SQL ServerServer
Mgmt. Mgmt. ServicesServices
Mgmt. Mgmt. ServicesServices
DistribuDistributed ted
Data Data FabricFabric
DistribuDistributed ted
Data Data FabricFabric
SQL SQL ServerServer
SQL SQL ServerServer
Mgmt. Mgmt. ServicesServices
Mgmt. Mgmt. ServicesServices
DistribuDistributed ted
Data Data FabricFabric
DistribuDistributed ted
Data Data FabricFabric
SQL SQL ServerServer
SQL SQL ServerServer
Mgmt. Mgmt. ServicesServices
Mgmt. Mgmt. ServicesServices
DistribuDistributed ted
Data Data FabricFabric
DistribuDistributed ted
Data Data FabricFabric
SQL SQL ServerServer
SQL SQL ServerServer
Mgmt. Mgmt. ServicesServices
Mgmt. Mgmt. ServicesServices
DistribuDistributed ted
Data Data FabricFabric
DistribuDistributed ted
Data Data FabricFabric
SQL SQL ServerServer
SQL SQL ServerServer
Mgmt. Mgmt. ServicesServices
Mgmt. Mgmt. ServicesServices
DistribuDistributed ted
Data Data FabricFabric
DistribuDistributed ted
Data Data FabricFabric
SQL SQL ServerServer
SQL SQL ServerServer
Mgmt. Mgmt. ServicesServices
Mgmt. Mgmt. ServicesServices
DistribuDistributed ted
Data Data FabricFabric
DistribuDistributed ted
Data Data FabricFabric
SQL SQL ServerServer
SQL SQL ServerServer
Unit ofgeo-location and billingTied toDNS nameCollectionof Containers
Entity properties may differ in type and instance
Drop me an email if I confused you about anything!
http://blogs.msdn.com/UKDevEvents
Post event resources for all Microsoft UK developer focused sessions
The teamEric Nelson http://blogs.msdn.com/ericnel Mike Ormond http://blogs.msdn.com/mikeormond Mike Taulty http://mtaulty.com