Presentation is loading. Please wait.

Presentation is loading. Please wait.

 Michael Wang Senior Program Manager Lead SQL Server Engine Microsoft Corporation BB25.

Similar presentations


Presentation on theme: " Michael Wang Senior Program Manager Lead SQL Server Engine Microsoft Corporation BB25."— Presentation transcript:

1  Michael Wang Senior Program Manager Lead SQL Server Engine Microsoft Corporation BB25

2

3 Date & Time Data type MERGE GROUPING SET Table value constructor support through the VALUES clause SQL language Table Value Parameter Declaring and initializing variables Compound assignment operators Procedure programming Object dependency Collation Beyond relational Others

4 Date or Time only data Historical date before year 1753 Datetime data with larger fractional precision Time zone offset aware CREATE TABLE Employee { FirstName VARCHAR(10), LastName VARCHAR(10), Birthday DATETIME, … } SELECT CONVERT(VARCHAR(20), Birthday, 101) AS BirthDay FROM Employee INSERT INTO T (datetime_col) VALUES (‘ ’) INSERT INTO T (datetime_col) VALUES (’12:30: ’) CREATE TABLE online-purchase-order { item-id int, item-name VARCHAR(30), qty int, purchase-time datetime, purchase-timezone varchar (10), … } // For value ‘ :20: :00’ INSERT INTO online-purchase-order VALUES (…., UDF_DT(..), UDF_TZ(..),..)

5 CREATE TABLE Employee { FirstName VARCHAR(10), LastName VARCHAR(10), Birthday DATE, … } SELECT Birthday AS BirthDay FROM Employee INSERT INTO T (datetime_col) VALUES (‘ ’) INSERT INTO T (datetime_col) VALUES (’12:30: ’) CREATE TABLE online-purchase-order { item-id int, item-name VARCHAR(30), qty int, purchase-time datetimeoffset, … } // For value ‘ :20: :00’ INSERT INTO online-purchase-order VALUES (…., ‘ :20: :00’,..) Large year range (1~9999) Storage saving Easy programming DATE Large or optional precision (0 ~ 100ns) Easy programming TIME Large year range Large or optional precision DATETIME2 Datetime + time zone offset UTC enabled Easy programming DATETIME OFFSET

6 SQLODBCOLEDBADO.NET DATESQL_TYPE_DATE/SQL_DATEDBTYPE_DBDATE DateTime TIMESQL_TIME/SQL_SS_TIME2DBTYPE_DBTIME/DBTYP E_DBTIME2 TimeSpan DATETIMEOFFSETSQL_SS_TIMESTAMPOFFSE T DBTYPE_DBTIMESTAMP OFFSET DateTimeOffset DATETIME2SQL_TYPE_TIMESTAMP SQL_TIMESTAMP DBTYPE_DBTIMESTAMPDateTime

7

8 Source Table (Stock Trading) Target Table (Stock Holding) Merged Table (Stock Holding) INSERT UPDATE

9 UPDATE TGT SET TGT.quantity += SRC.quantity, TGT.LastTradeDate = SRC.TradeDate FROM 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 TGT USING dbo.StockTrading AS SRC ON TGT.stock = SRC.stock WHEN MATCHED AND (t.quantity + s.quantity = 0) THEN DELETE WHEN MATCHED THEN UPDATE SET t.LastTradeDate = s.TradeDate, t.quantity += s.quantity WHEN NOT MATCHED THEN INSERT VALUES (s.Stock,s.TradeDate,s.Quantity) Pre-SQL 2008SQL 2008

10

11

12 SELECT customerType,Null as TerritoryID,MAX(ModifiedDate) FROM Sales.Customer GROUP BY customerType UNION ALL SELECT Null as customerType,TerritoryID,MAX(Modifie dDate) FROM Sales.Customer GROUP BY TerritoryID order by TerritoryID SELECT customerType,TerritoryID,MAX(ModifiedDa te) FROM Sales.Customer GROUP BY GROUPING SETS ((customerType), (TerritoryID)) order by customerType Pre-SQL 2008SQL 2008

13 INSERT INTO dbo.Customers(custid, companyname, phone, address) VALUES (1, 'cust 1', '(111) ', 'address 1'), (2, 'cust 2', '(222) ', 'address 2'), (3, 'cust 3', '(333) ', 'address 3'), (4, 'cust 4', '(444) ', 'address 4'), (5, 'cust 5', '(555) ', 'address 5'); SELECT * FROM (VALUES (1, 'cust 1', '(111) ', 'address 1'), (2, 'cust 2', '(222) ', 'address 2'), (3, 'cust 3', '(333) ', 'address 3'), (4, 'cust 4', '(444) ', 'address 4'), (5, 'cust 5', '(555) ', 'address 5') ) AS C(custid, companyname, phone, address); Multi-Row InsertDefine table expressions

14 TABLE ( [CustomerID] int NULL, [FirstName] varchar(50) NOT NULL, [LastName] varchar(50) NOT NULL, [CompanyName] [nvarchar](128) NULL )

15

16

17

18 CREATE TYPE myTableType AS TABLE (id INT, name NVARCHAR(100),qty INT); CREATE PROCEDURE myProc myTableType READONLY) AS UPDATE Inventory SET qty += s.qty FROM Inventory AS i INNER AS tvp ON i.id = tvp.id GO

19

20

21 UPDATE Inventory SET quantity += s.quantity FROM Inventory AS i INNER JOIN Sales AS s ON i.id = s.id UPDATE Inventory SET quantity += s.quantity FROM Inventory AS i INNER JOIN Sales AS s ON i.id = s.id int = 5; varchar(10) = ‘xxxxx’; int = 5; varchar(10) = ‘xxxxx’; select from t1, t2 where convert(char(4), t1.col1_of_type_binary,1) = t2.col1_of_type_char

22

23 CREATE PROCEDURE myUDT OUTPUT AS INT; SELECT = = MAX(c) FROM t1 WHERE a EXEC p2; = AS myUDT; GO SELECT FROM sys.sql_expression_dependencies WHERE referencing_id = OBJECT_ID(‘p1’);

24 USE db1 CREATE PROCEDURE dbo.p2 SELECT * FROM t1; … CREATE PROCEDURE p3 UPDATE dbo.t1 … CREATE VIEW v1 WITH SCHEMABINDING SELECT t1.*, t2.* FROM dbo.t1 INNER JOIN dbo.t2 … CREATE FUNCTION s.foo INT) RETURNS TABLE AS BEGIN SELECT * FROM t1 WHERE a END USE db2 CREATE PROCEDURE p4 -- cross db dependency doesn’t -- show up as a referencing entity SELECT * FROM db1..t1; SELECT referencing_schema_name, referencing_entity_name, referencing_id, is_caller_dependent FROM sys.dm_sql_referencing_entities (‘dbo.t1’);

25

26 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 for hundreds of thousands of sparse columns Filtered Indices Define indices over subsets of data in tables // Create a Filtered Indexes // Sparse column Create Table Products(Id int, Type nvarchar(16)…, Resolution int SPARSE, ZoomLength int SPARSE); // Filtered Indices Create 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 column Create Table Products(Id int, Type nvarchar(16)…, Resolution int SPARSE, ZoomLength int SPARSE); // Filtered Indices Create 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 ); BB07 - SQL Server 2008: Developing for Beyond-Relational Data

27 BB24 - Microsoft SQL Server 2008: Deep Dive into Spatial Data

28 Intuitive and familiar Language Constructs Ease of Programming Against Query Results Rich & Easy to use modeling of data in Data Tier Easy to use Data Tier App definition & management Rich Framework Scalable, Mission- Critical Runtime SQLCLR for type/function extensibility Powerful and efficient language tools and services blocks

29

30 Please fill out your evaluation for this session at: This session will be available as a recording at:

31 © 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

32


Download ppt " Michael Wang Senior Program Manager Lead SQL Server Engine Microsoft Corporation BB25."

Similar presentations


Ads by Google