by: matt batalon, mcitp twitter:@mattbatalon. another form of temporary storage that can be queried...

9
SNESSUG Lightning Talk: Table Valued Parameters By: Matt Batalon, MCITP Twitter:@MattBatalon

Upload: todd-logan

Post on 02-Jan-2016

221 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: By: Matt Batalon, MCITP Twitter:@MattBatalon.  Another form of temporary storage that can be queried or joined against, much like a table variable, temp

SNESSUG Lightning Talk:

Table Valued Parameters

By: Matt Batalon, MCITPTwitter:@MattBatalon

Page 2: By: Matt Batalon, MCITP Twitter:@MattBatalon.  Another form of temporary storage that can be queried or joined against, much like a table variable, temp

Another form of temporary storage that can be queried or joined against, much like a table variable, temp table or CTE

Based on user defined table type that describes schema for a table

Commonly referred to as Table Valued Parameters (TVP) or User Defined Table Types

Introduced in SQL Server 2008

Page 3: By: Matt Batalon, MCITP Twitter:@MattBatalon.  Another form of temporary storage that can be queried or joined against, much like a table variable, temp

Can be passed as a single parameter (set of rows) to a stored procedure or user defined function unlike a table variable or temp table

Can be passed between stored procedures or from client side application

Reusability; the schema for a TVP is centrally maintained

Table Valued Parameters or User Defined Table Types…

Page 4: By: Matt Batalon, MCITP Twitter:@MattBatalon.  Another form of temporary storage that can be queried or joined against, much like a table variable, temp

TVP types are displayed in SQL Server Management Studio unless manually dropped

Programmability Types User Defined Table Types

Can expand to see columns, constraints, indexes

Visible in SQL Server Management Studio

Page 5: By: Matt Batalon, MCITP Twitter:@MattBatalon.  Another form of temporary storage that can be queried or joined against, much like a table variable, temp

Ease of encapsulating multiple parameters into a single parameter

Reduces round trips to the server, which can aid in performance

Strongly typed with the CREATE TYPE…TABLE statement

Easily maintainable code because schema can be defined only once then can be reused

Other Benefits of Table Valued Parameters

Page 6: By: Matt Batalon, MCITP Twitter:@MattBatalon.  Another form of temporary storage that can be queried or joined against, much like a table variable, temp

Forced to send multiple parameters as arguments

Use String Manipulation to encapsulate multiple parameters

Individual Database calls, not a set based approach

Before Table Valued Parameters

Page 7: By: Matt Batalon, MCITP Twitter:@MattBatalon.  Another form of temporary storage that can be queried or joined against, much like a table variable, temp

Using a TVP vs. Delimited String

Bulk inserting a TVP

Bulk Update using a TVP

Encapsulate business logic using TVPs, and reducing round trips to server

Demo: Scenarios for Table Valued Parameters

Page 8: By: Matt Batalon, MCITP Twitter:@MattBatalon.  Another form of temporary storage that can be queried or joined against, much like a table variable, temp

Data cannot be modified, must be passed as READ ONLY

Cannot use ALTER table statement on a TVP, must be dropped and recreated

No support for Select INTO or INSERT Exec statement

Limitations of Table Valued Parameters

Page 9: By: Matt Batalon, MCITP Twitter:@MattBatalon.  Another form of temporary storage that can be queried or joined against, much like a table variable, temp

Books online◦ Examples for using with ADO.net ◦ Comparison with BCP◦ Connectivity

Books:Programming SQL Server 2008 by Leonard Lobel, Andrew Bust, Stephen Forte

For more on Table Valued Parameters