SlideShare a Scribd company logo
1 of 14
Download to read offline
SQL Server™ .NET
Programmability

José A. Blakeley
Architect
SQL Server

Background
l

Transact SQL (T -SQL)
Ø
Ø

SQL Server’s database programming language
Includes:
§
§

l

SQL DDL, SQL DML
Variables, assignment, iteration, procedures, functions

.NET Platform
Ø

.NET runtime (Common Language Runtime)
§
§
§

Ø
Ø

Verifiable Intermediate Language
Managed memory – garbage collection
Multiple languages (e.g, C#, C++, Cobol)
(e.g ,

Frameworks library (e.g., GUI, Files, XML)
Assemblies – New Dynamic Link Libraries
§
§

Contain code + metadata (class definitions, assembly
dependencies)
Unit of code deployment, security, versioning

PDC 2001
October 22-26, 2001
© 2001 Microsoft Corporation. All rights reserved.

1
Outline
l
l

Motivation
Basic Infrastructure
Ø
Ø
Ø

l

SQL features
Ø
Ø
Ø

l

Hosting overview
Data access inside process: ADO.NET
SQL types
Server assemblies
Functions, procedures, triggers
Types and aggregates

Summary

Motivation
l

Broaden the set of languages for running
datadata -intensive business logic in server
Ø
Ø
Ø
Ø
Ø

l

Packaged as .NET assemblies
Ø

l

Verifiable, secure

Deployed to SQL Server as
Ø

l

IT Developers and ISVs
Multiple languages: Visual Basic ®, C#, C++, J#, …
Same mid - and server -tier data access model
midserverSame tools: IDE, project model, debugging, …
TransactTransact-SQL still supported

Functions, procedures, triggers, types

Basis for SQL Server Extensibility

PDC 2001
October 22-26, 2001
© 2001 Microsoft Corporation. All rights reserved.

2
Development Steps
VB, C#, C++

VS
Project

Build

Runtime
hosted inside
SQL Server

SQL Queries:
select
sum(tax(sal,state)
sum(tax(sal,state) )
from Emp where county
= ‘King’

Assembly:
“TaxLib.dll”
TaxLib.dll”

SQL Data Definition:
create assembly …
create function …
create procedure …
create trigger …
create type …

SQL Server

Basic Infrastructure
l

Hosting common language runtime
inside SQL Server
Ø
Ø
Ø

l

Data access in process
Ø
Ø

l

4Ss: Safety, security, scalability, speed
Run verified, type-safe code inside
typeprocess
Multiple languages
Based on ADO.NET
Same data access programming model
as middle -tier
middle-

SQLTypes
Ø

SQL type semantics in managed code

PDC 2001
October 22-26, 2001
© 2001 Microsoft Corporation. All rights reserved.

3
Hosting .NET Runtime
l

Safety
Ø

Prevent user code from corrupting the server
process
§

Ø

Use runtime code permissions to control user code
when calling
§

l

Verifiable code

Unmanaged APIs, user interface, threads, synchronization

Security
Ø
Ø
Ø

Authorized access to SQL Server data from user
code via SQL Server authorization model
Authorized access to system resources from user
code via runtime code permissions
Administrators control permissions given
to assemblies

Three Code Permission Sets
l

SAFE
Ø

Execute & data access permission

Ø

No access to resources outside SQL Server
No unmanaged calls
Must be verifiable

Ø
Ø

l

EXTERNAL_ACCESS
Ø
Ø
Ø
Ø

l

SAFESQL + access to external resources (Net, File
permissions)
Requires EXTERNAL ACCESS permission to create
SQL Server will impersonate the caller
Must be verifiable

UNRESTRICTED
Ø
Ø

No controls: Can call unmanged code, can be un-verifiable
unOnly Administrators can create

PDC 2001
October 22-26, 2001
© 2001 Microsoft Corporation. All rights reserved.

4
Hosting .NET Runtime
l

Scalability
As many concurrent users as, as fast as
TransactTransact-SQL

Ø

§

Integrated SQL Server and runtime threads

§

Collaboration between SQL Server and GC
SQL Server becomes OS to the .NET runtime

§

l

Speed
Efficient data access in process
Compiled user code, not interpreted as
TransactTransact-SQL
Fast transitions in/out of runtime

Ø
Ø
Ø

Speed: Functions
.NET function vs. Transact-SQL inline

600

.NET function vs. Transact-SQL function

400
200

1000000

0
1

3

5

7

9

Query time (ms)

Query time (ms)

800

100000

10000
11 1 3 15 17 19 21
1000
Integer ops per func call
100
.NET func

23

25 27

29

10 TSQL inline
1
100

1000

10000

Integer ops per call

.NET functions approximating speed of TransactTransact.NET func
TSQL func
SQL inline expressions
.NET framework functions much faster than
TransactTransact-SQL functions for complex expressions

PDC 2001
October 22-26, 2001
© 2001 Microsoft Corporation. All rights reserved.

5
Outline
l
l

Motivation
Basic Infrastructure
Ø
Ø
Ø

l

SQL features
Ø
Ø
Ø

l

Hosting overview
Data access inside process: ADO.NET
SQL types
Server assemblies
Functions, procedures, triggers
Types and aggregates

Summary

ADO .NET Data Access
Controls,
Designers,
etc

XSL/T, X -Path,
XValidation, etc

XmlDataXmlDataDocument

XmlReader
XmlText- XmlNodeXmlText- XmlNode Reader
Reader

DataSet
Sync

SQL Server
Managed
Managed
Managed
Provider
Provider

Provider

XmlReader
XmlText- XmlNodeXmlText- XmlNode Reader
Reader

PDC 2001
October 22-26, 2001
© 2001 Microsoft Corporation. All rights reserved.

6
Data Access Inside SQL
using System.Data.SqlServer;
System.Data.SqlServer;
using System.Data.SqlTypes;
System.Data.SqlTypes;
public class ShippingCosts {
public static SqlMoney FreightByShipper( string ship ) {
FreightByShipper(
SqlCommand cmd = SqlContext.GetCommand( );
SqlContext.GetCommand(
cmd.CommandText = "select sum(o.freight) as freight " +
"from orders o join shippers s on o.shipvia = s.shipperid " +
"where s.companyname = @CompanyName " ;
@CompanyName
SqlParameter param = cmd.Parameters.Add("@CompanyName",
cmd.Parameters.Add("@CompanyName",
SqlDbType.NVarChar,
SqlDbType.NVarChar, COMPANY_NAME_COL_LENGTH);
param.Value = ship;
ship;
SqlMoney amount = cmd.ExecuteScalar( );
cmd.ExecuteScalar(
return amount;
}
}

SQL Types
l
l
l

Reduce impedance mismatch between
programming language and data
Consistent expression evaluation in
midmid- and server-tier programming
serverSQL Types library
Ø
Ø

Managed classes: System.Data.SqlTypes
Provide SQL semantics
§
§

Nullability, threeNullability , three-valued logic
Precision and scale in operations

PDC 2001
October 22-26, 2001
© 2001 Microsoft Corporation. All rights reserved.

7
SQL Types Example
Tax function using SQL types

l

using System;
using System.Data.SQLTypes
;
public class myFinances
{
public static SQLDouble tax( SQLDouble sal )
{
if ( sal < 50000.0 ) return sal * 0.15;
0.15;
if ( sal >= 50000.0 && sal <= 90000.0 ) return sal * 0.23
else return sal * 0.35;
0.35;
}
}

SQLDouble makes function NULL-aware
NULL-

Outline
l
l

Motivation
Basic Infrastructure
Ø
Ø
Ø

l

SQL features
Ø
Ø
Ø

l

Hosting overview
Data access inside process: ADO.NET
SQL types
Server assemblies
Functions, procedures, triggers
Types and aggregates

Summary

PDC 2001
October 22-26, 2001
© 2001 Microsoft Corporation. All rights reserved.

8
SQL Features
Assemblies
Functions
Procedures
Triggers
Types

l
l
l
l
l

Creating An Assembly
CREATE ASSEMBLY geom FROM ‘m1typesgeometry.dll’
‘ m1types
WITH PERMISSION_SET = SAFE
WITH AUTOREGISTER
DROP ASSEMBLY lib_geom
l

Assemblies stored in database
Ø

l

Ø

l

Safe (default), external access, unrestricted

Autoregister functions
Ø

l

Backup, restore with data

Code permissions assigned per assembly

Using .NET custom attributes

Assembly benefits
Ø
Ø

SelfSelf-describing metadata: Types, file dependencies
Unit of code deployment: Permissions, versioning

PDC 2001
October 22-26, 2001
© 2001 Microsoft Corporation. All rights reserved.

9
Altering An Assembly
l
l

Cannot invalidate persistent data or indexes
Implies
Ø
Ø

l
l

No tables with columns of UDT from this assembly
No indexes on functions of this assembly

Force option allows ALTER even if persistent
dependencies exist
Packaging considerations
Ø

Place routines and types in different assemblies

Creating A Function
CREATE FUNCTION distance (
@x1 int, @y1 int, @x2 int, @y2 int ) RETURNS float
int,
int,
int,
EXTERNAL NAME ‘geom:CPoint.Distance’
‘geom:CPoint.Distance’
DETERMINISTIC
RETURNS NULL ON NULL INPUT
DROP FUNCTION distance
l

Functions called from queries
Ø
Ø
Ø

l

Can be scalar or table -valued
Static class functions
Deterministic functions

Using a function in a query
SELECT s.name FROM Supplier s
WHERE dbo.distance ( s.x, s.y, @x, @y ) < 3
dbo.distance(

PDC 2001
October 22-26, 2001
© 2001 Microsoft Corporation. All rights reserved.

10
Creating A Procedure
CREATE PROCEDURE check_inventory
EXTERNAL NAME ‘events:CInventory.check_level’
‘events:CInventory.check_level’
DROP PROCEDURE check_inventory
l

Procedures not called from queries
Ø
Ø

Can contain SQL queries, updates or DDL
Can return results directly to client

Creating A Trigger
CREATE TRIGGER supplier_event ON supplier
AFTER INSERT, UPDATE
EXTERNAL NAME ‘events:CNotif.Supp_Event’
‘events:CNotif.Supp_Event’
DROP TRIGGER supplier_event
l
l

Similar to procedures, plus
Access to inserted, deleted tables

PDC 2001
October 22-26, 2001
© 2001 Microsoft Corporation. All rights reserved.

11
Creating A Type
l

Create or drop a type
CREATE TYPE Point
EXTERNAL NAME ‘geom:Point’
‘geom:Point’
DROP TYPE Point

l

Using a type
CREATE TABLE Supplier (
id
INTEGER PRIMARY KEY,
name
VARCHAR(20),
location
Point )

l

Using a type method in a query
SELECT s.name FROM Supplier s
WHERE s.location::distance( @point ) < 3

Query Optimization
l

Automatically gather function statistics
Ø

l

Reorder of predicate evaluation
Ø

l

Based on execution cost and statistics

Function indexes
Ø
Ø

l

Value histograms, execution cost

Speed up expensive functions
Extends computed column indexes
and index views

Implied and residual predicates

PDC 2001
October 22-26, 2001
© 2001 Microsoft Corporation. All rights reserved.

12
Summary
Richer server programming model

l

Ø
Ø
Ø

Any .NET framework language
Same mid - and server -tier data access:
midserverADO. NET
Same IDE, project model, debugging, tools

SQL Server hosting of .NET runtime

l

Ø

Safety, security, scalability, speed

SQL Server .NET features

l

Ø

Functions, stored procedures, triggers,
types, aggregates

Demos
l
l

Sample code for function, stored procedure, and type
Assemblies
Ø

l

Functions and stored procedures
Ø
Ø

l

Safe versus external access
Creation and execution
Data access in-process via ADO .NET
in-

Types
Ø
Ø
Ø
Ø
Ø

Type contract
Create type
Create table with column of user-defined type
userCreate index on column of user-defined type
userInsert and query the table

PDC 2001
October 22-26, 2001
© 2001 Microsoft Corporation. All rights reserved.

13
© 2001 Microsoft Corporation. All rights reserved.

PDC 2001
October 22-26, 2001
© 2001 Microsoft Corporation. All rights reserved.

14

More Related Content

What's hot

Scaling web applications with cassandra presentation
Scaling web applications with cassandra presentationScaling web applications with cassandra presentation
Scaling web applications with cassandra presentationMurat Çakal
 
Apache cassandra - future without boundaries (part3)
Apache cassandra - future without boundaries (part3)Apache cassandra - future without boundaries (part3)
Apache cassandra - future without boundaries (part3)Return on Intelligence
 
In-depth caching in Varnish - GOG Varnish Meetup, march 2019
In-depth caching in Varnish - GOG Varnish Meetup, march 2019In-depth caching in Varnish - GOG Varnish Meetup, march 2019
In-depth caching in Varnish - GOG Varnish Meetup, march 2019GOG.com dev team
 
Scala4sling
Scala4slingScala4sling
Scala4slingday
 
Kamaelia Protocol Walkthrough
Kamaelia Protocol WalkthroughKamaelia Protocol Walkthrough
Kamaelia Protocol Walkthroughkamaelian
 
Above the clouds: introducing Akka
Above the clouds: introducing AkkaAbove the clouds: introducing Akka
Above the clouds: introducing Akkanartamonov
 
Lambda Jam 2015: Event Processing in Clojure
Lambda Jam 2015: Event Processing in ClojureLambda Jam 2015: Event Processing in Clojure
Lambda Jam 2015: Event Processing in ClojureAndy Marks
 
Store and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and CassandraStore and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and CassandraDeependra Ariyadewa
 
Introduction to Apache Kafka- Part 2
Introduction to Apache Kafka- Part 2Introduction to Apache Kafka- Part 2
Introduction to Apache Kafka- Part 2Knoldus Inc.
 
Paris Cassandra Meetup - Cassandra for Developers
Paris Cassandra Meetup - Cassandra for DevelopersParis Cassandra Meetup - Cassandra for Developers
Paris Cassandra Meetup - Cassandra for DevelopersMichaël Figuière
 
Dynamic websites lec3
Dynamic websites lec3Dynamic websites lec3
Dynamic websites lec3Belal Arfa
 
NYC* Tech Day - New Cassandra Drivers in Depth
NYC* Tech Day - New Cassandra Drivers in DepthNYC* Tech Day - New Cassandra Drivers in Depth
NYC* Tech Day - New Cassandra Drivers in DepthMichaël Figuière
 
03 2017Emea_RoadshowMilan-WhatsNew-Mariadbserver10_2andmaxscale 2_1
03 2017Emea_RoadshowMilan-WhatsNew-Mariadbserver10_2andmaxscale 2_103 2017Emea_RoadshowMilan-WhatsNew-Mariadbserver10_2andmaxscale 2_1
03 2017Emea_RoadshowMilan-WhatsNew-Mariadbserver10_2andmaxscale 2_1mlraviol
 

What's hot (20)

Scaling web applications with cassandra presentation
Scaling web applications with cassandra presentationScaling web applications with cassandra presentation
Scaling web applications with cassandra presentation
 
Cassandra NoSQL
Cassandra NoSQLCassandra NoSQL
Cassandra NoSQL
 
Ad java prac sol set
Ad java prac sol setAd java prac sol set
Ad java prac sol set
 
Apache cassandra - future without boundaries (part3)
Apache cassandra - future without boundaries (part3)Apache cassandra - future without boundaries (part3)
Apache cassandra - future without boundaries (part3)
 
In-depth caching in Varnish - GOG Varnish Meetup, march 2019
In-depth caching in Varnish - GOG Varnish Meetup, march 2019In-depth caching in Varnish - GOG Varnish Meetup, march 2019
In-depth caching in Varnish - GOG Varnish Meetup, march 2019
 
Devtools cheatsheet
Devtools cheatsheetDevtools cheatsheet
Devtools cheatsheet
 
Scala4sling
Scala4slingScala4sling
Scala4sling
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
 
Kamaelia Protocol Walkthrough
Kamaelia Protocol WalkthroughKamaelia Protocol Walkthrough
Kamaelia Protocol Walkthrough
 
Above the clouds: introducing Akka
Above the clouds: introducing AkkaAbove the clouds: introducing Akka
Above the clouds: introducing Akka
 
Sqlapi0.1
Sqlapi0.1Sqlapi0.1
Sqlapi0.1
 
Lambda Jam 2015: Event Processing in Clojure
Lambda Jam 2015: Event Processing in ClojureLambda Jam 2015: Event Processing in Clojure
Lambda Jam 2015: Event Processing in Clojure
 
Store and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and CassandraStore and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and Cassandra
 
Introduction to Apache Kafka- Part 2
Introduction to Apache Kafka- Part 2Introduction to Apache Kafka- Part 2
Introduction to Apache Kafka- Part 2
 
Paris Cassandra Meetup - Cassandra for Developers
Paris Cassandra Meetup - Cassandra for DevelopersParis Cassandra Meetup - Cassandra for Developers
Paris Cassandra Meetup - Cassandra for Developers
 
Rstudio ide-cheatsheet
Rstudio ide-cheatsheetRstudio ide-cheatsheet
Rstudio ide-cheatsheet
 
Dynamic websites lec3
Dynamic websites lec3Dynamic websites lec3
Dynamic websites lec3
 
341 Rac
341 Rac341 Rac
341 Rac
 
NYC* Tech Day - New Cassandra Drivers in Depth
NYC* Tech Day - New Cassandra Drivers in DepthNYC* Tech Day - New Cassandra Drivers in Depth
NYC* Tech Day - New Cassandra Drivers in Depth
 
03 2017Emea_RoadshowMilan-WhatsNew-Mariadbserver10_2andmaxscale 2_1
03 2017Emea_RoadshowMilan-WhatsNew-Mariadbserver10_2andmaxscale 2_103 2017Emea_RoadshowMilan-WhatsNew-Mariadbserver10_2andmaxscale 2_1
03 2017Emea_RoadshowMilan-WhatsNew-Mariadbserver10_2andmaxscale 2_1
 

Viewers also liked

Viewers also liked (12)

Task 2 analysis of nme music magazine
Task 2  analysis of nme music magazineTask 2  analysis of nme music magazine
Task 2 analysis of nme music magazine
 
Teste 1º. 10ºe. 29 outubro 2010
Teste 1º. 10ºe. 29 outubro 2010Teste 1º. 10ºe. 29 outubro 2010
Teste 1º. 10ºe. 29 outubro 2010
 
Trt civil 02 (1)
Trt   civil 02 (1)Trt   civil 02 (1)
Trt civil 02 (1)
 
Trt português 02
Trt   português 02Trt   português 02
Trt português 02
 
Trt previdenciário (1)
Trt   previdenciário (1)Trt   previdenciário (1)
Trt previdenciário (1)
 
الشهادات٣
الشهادات٣الشهادات٣
الشهادات٣
 
YO, MI CULTURA, MI REGIÓN
YO, MI CULTURA, MI REGIÓNYO, MI CULTURA, MI REGIÓN
YO, MI CULTURA, MI REGIÓN
 
Leccion 5 tablas numericas con ceros fep rene
Leccion 5 tablas numericas con ceros fep reneLeccion 5 tablas numericas con ceros fep rene
Leccion 5 tablas numericas con ceros fep rene
 
Trabajo sobre edificios en word
Trabajo sobre edificios en wordTrabajo sobre edificios en word
Trabajo sobre edificios en word
 
Rúbrica
RúbricaRúbrica
Rúbrica
 
El derecho de autor
El derecho de autorEl derecho de autor
El derecho de autor
 
Comparatives nice two
Comparatives nice twoComparatives nice two
Comparatives nice two
 

Similar to Sql Server - Apresentação

Sql Summit Clr, Service Broker And Xml
Sql Summit   Clr, Service Broker And XmlSql Summit   Clr, Service Broker And Xml
Sql Summit Clr, Service Broker And XmlDavid Truxall
 
SQL Server 2005 CLR Integration
SQL Server 2005 CLR IntegrationSQL Server 2005 CLR Integration
SQL Server 2005 CLR Integrationwebhostingguy
 
Introduction to Threading in .Net
Introduction to Threading in .NetIntroduction to Threading in .Net
Introduction to Threading in .Netwebhostingguy
 
2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...
2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...
2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...Jürgen Ambrosi
 
SQLCLR For DBAs and Developers
SQLCLR For DBAs and DevelopersSQLCLR For DBAs and Developers
SQLCLR For DBAs and Developerswebhostingguy
 
Dr. Jekyll and Mr. Hyde
Dr. Jekyll and Mr. HydeDr. Jekyll and Mr. Hyde
Dr. Jekyll and Mr. Hydewebhostingguy
 
Expanding your impact with programmability in the data center
Expanding your impact with programmability in the data centerExpanding your impact with programmability in the data center
Expanding your impact with programmability in the data centerCisco Canada
 
Do you know what your drupal is doing? Observe it!
Do you know what your drupal is doing? Observe it!Do you know what your drupal is doing? Observe it!
Do you know what your drupal is doing? Observe it!Luca Lusso
 
Advanced SQL - Database Access from Programming Languages
Advanced SQL - Database Access  from Programming LanguagesAdvanced SQL - Database Access  from Programming Languages
Advanced SQL - Database Access from Programming LanguagesS.Shayan Daneshvar
 
SQL Server - CLR integration
SQL Server - CLR integrationSQL Server - CLR integration
SQL Server - CLR integrationPeter Gfader
 
SQL Server Security - Attack
SQL Server Security - Attack SQL Server Security - Attack
SQL Server Security - Attack webhostingguy
 
C# and ASP.NET Code and Data-Access Security
C# and ASP.NET Code and Data-Access SecurityC# and ASP.NET Code and Data-Access Security
C# and ASP.NET Code and Data-Access SecurityDarren Sim
 
SQL Server 2000 Research Series - Transact SQL
SQL Server 2000 Research Series - Transact SQLSQL Server 2000 Research Series - Transact SQL
SQL Server 2000 Research Series - Transact SQLJerry Yang
 
Logisland "Event Mining at scale"
Logisland "Event Mining at scale"Logisland "Event Mining at scale"
Logisland "Event Mining at scale"Thomas Bailet
 
SQL Server SQL Server
SQL Server SQL ServerSQL Server SQL Server
SQL Server SQL Serverwebhostingguy
 
SQL Server SQL Server
SQL Server SQL ServerSQL Server SQL Server
SQL Server SQL Serverwebhostingguy
 
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)lennartkats
 
LINQ-Introduction.ppt
LINQ-Introduction.pptLINQ-Introduction.ppt
LINQ-Introduction.pptssusera8c91a
 

Similar to Sql Server - Apresentação (20)

Sql Summit Clr, Service Broker And Xml
Sql Summit   Clr, Service Broker And XmlSql Summit   Clr, Service Broker And Xml
Sql Summit Clr, Service Broker And Xml
 
SQL Server 2005 CLR Integration
SQL Server 2005 CLR IntegrationSQL Server 2005 CLR Integration
SQL Server 2005 CLR Integration
 
Day2
Day2Day2
Day2
 
SQLCLR Tips & Trics
SQLCLR Tips & TricsSQLCLR Tips & Trics
SQLCLR Tips & Trics
 
Introduction to Threading in .Net
Introduction to Threading in .NetIntroduction to Threading in .Net
Introduction to Threading in .Net
 
2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...
2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...
2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...
 
SQLCLR For DBAs and Developers
SQLCLR For DBAs and DevelopersSQLCLR For DBAs and Developers
SQLCLR For DBAs and Developers
 
Dr. Jekyll and Mr. Hyde
Dr. Jekyll and Mr. HydeDr. Jekyll and Mr. Hyde
Dr. Jekyll and Mr. Hyde
 
Expanding your impact with programmability in the data center
Expanding your impact with programmability in the data centerExpanding your impact with programmability in the data center
Expanding your impact with programmability in the data center
 
Do you know what your drupal is doing? Observe it!
Do you know what your drupal is doing? Observe it!Do you know what your drupal is doing? Observe it!
Do you know what your drupal is doing? Observe it!
 
Advanced SQL - Database Access from Programming Languages
Advanced SQL - Database Access  from Programming LanguagesAdvanced SQL - Database Access  from Programming Languages
Advanced SQL - Database Access from Programming Languages
 
SQL Server - CLR integration
SQL Server - CLR integrationSQL Server - CLR integration
SQL Server - CLR integration
 
SQL Server Security - Attack
SQL Server Security - Attack SQL Server Security - Attack
SQL Server Security - Attack
 
C# and ASP.NET Code and Data-Access Security
C# and ASP.NET Code and Data-Access SecurityC# and ASP.NET Code and Data-Access Security
C# and ASP.NET Code and Data-Access Security
 
SQL Server 2000 Research Series - Transact SQL
SQL Server 2000 Research Series - Transact SQLSQL Server 2000 Research Series - Transact SQL
SQL Server 2000 Research Series - Transact SQL
 
Logisland "Event Mining at scale"
Logisland "Event Mining at scale"Logisland "Event Mining at scale"
Logisland "Event Mining at scale"
 
SQL Server SQL Server
SQL Server SQL ServerSQL Server SQL Server
SQL Server SQL Server
 
SQL Server SQL Server
SQL Server SQL ServerSQL Server SQL Server
SQL Server SQL Server
 
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
 
LINQ-Introduction.ppt
LINQ-Introduction.pptLINQ-Introduction.ppt
LINQ-Introduction.ppt
 

Recently uploaded

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
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
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 

Recently uploaded (20)

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
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
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 

Sql Server - Apresentação

  • 1. SQL Server™ .NET Programmability José A. Blakeley Architect SQL Server Background l Transact SQL (T -SQL) Ø Ø SQL Server’s database programming language Includes: § § l SQL DDL, SQL DML Variables, assignment, iteration, procedures, functions .NET Platform Ø .NET runtime (Common Language Runtime) § § § Ø Ø Verifiable Intermediate Language Managed memory – garbage collection Multiple languages (e.g, C#, C++, Cobol) (e.g , Frameworks library (e.g., GUI, Files, XML) Assemblies – New Dynamic Link Libraries § § Contain code + metadata (class definitions, assembly dependencies) Unit of code deployment, security, versioning PDC 2001 October 22-26, 2001 © 2001 Microsoft Corporation. All rights reserved. 1
  • 2. Outline l l Motivation Basic Infrastructure Ø Ø Ø l SQL features Ø Ø Ø l Hosting overview Data access inside process: ADO.NET SQL types Server assemblies Functions, procedures, triggers Types and aggregates Summary Motivation l Broaden the set of languages for running datadata -intensive business logic in server Ø Ø Ø Ø Ø l Packaged as .NET assemblies Ø l Verifiable, secure Deployed to SQL Server as Ø l IT Developers and ISVs Multiple languages: Visual Basic ®, C#, C++, J#, … Same mid - and server -tier data access model midserverSame tools: IDE, project model, debugging, … TransactTransact-SQL still supported Functions, procedures, triggers, types Basis for SQL Server Extensibility PDC 2001 October 22-26, 2001 © 2001 Microsoft Corporation. All rights reserved. 2
  • 3. Development Steps VB, C#, C++ VS Project Build Runtime hosted inside SQL Server SQL Queries: select sum(tax(sal,state) sum(tax(sal,state) ) from Emp where county = ‘King’ Assembly: “TaxLib.dll” TaxLib.dll” SQL Data Definition: create assembly … create function … create procedure … create trigger … create type … SQL Server Basic Infrastructure l Hosting common language runtime inside SQL Server Ø Ø Ø l Data access in process Ø Ø l 4Ss: Safety, security, scalability, speed Run verified, type-safe code inside typeprocess Multiple languages Based on ADO.NET Same data access programming model as middle -tier middle- SQLTypes Ø SQL type semantics in managed code PDC 2001 October 22-26, 2001 © 2001 Microsoft Corporation. All rights reserved. 3
  • 4. Hosting .NET Runtime l Safety Ø Prevent user code from corrupting the server process § Ø Use runtime code permissions to control user code when calling § l Verifiable code Unmanaged APIs, user interface, threads, synchronization Security Ø Ø Ø Authorized access to SQL Server data from user code via SQL Server authorization model Authorized access to system resources from user code via runtime code permissions Administrators control permissions given to assemblies Three Code Permission Sets l SAFE Ø Execute & data access permission Ø No access to resources outside SQL Server No unmanaged calls Must be verifiable Ø Ø l EXTERNAL_ACCESS Ø Ø Ø Ø l SAFESQL + access to external resources (Net, File permissions) Requires EXTERNAL ACCESS permission to create SQL Server will impersonate the caller Must be verifiable UNRESTRICTED Ø Ø No controls: Can call unmanged code, can be un-verifiable unOnly Administrators can create PDC 2001 October 22-26, 2001 © 2001 Microsoft Corporation. All rights reserved. 4
  • 5. Hosting .NET Runtime l Scalability As many concurrent users as, as fast as TransactTransact-SQL Ø § Integrated SQL Server and runtime threads § Collaboration between SQL Server and GC SQL Server becomes OS to the .NET runtime § l Speed Efficient data access in process Compiled user code, not interpreted as TransactTransact-SQL Fast transitions in/out of runtime Ø Ø Ø Speed: Functions .NET function vs. Transact-SQL inline 600 .NET function vs. Transact-SQL function 400 200 1000000 0 1 3 5 7 9 Query time (ms) Query time (ms) 800 100000 10000 11 1 3 15 17 19 21 1000 Integer ops per func call 100 .NET func 23 25 27 29 10 TSQL inline 1 100 1000 10000 Integer ops per call .NET functions approximating speed of TransactTransact.NET func TSQL func SQL inline expressions .NET framework functions much faster than TransactTransact-SQL functions for complex expressions PDC 2001 October 22-26, 2001 © 2001 Microsoft Corporation. All rights reserved. 5
  • 6. Outline l l Motivation Basic Infrastructure Ø Ø Ø l SQL features Ø Ø Ø l Hosting overview Data access inside process: ADO.NET SQL types Server assemblies Functions, procedures, triggers Types and aggregates Summary ADO .NET Data Access Controls, Designers, etc XSL/T, X -Path, XValidation, etc XmlDataXmlDataDocument XmlReader XmlText- XmlNodeXmlText- XmlNode Reader Reader DataSet Sync SQL Server Managed Managed Managed Provider Provider Provider XmlReader XmlText- XmlNodeXmlText- XmlNode Reader Reader PDC 2001 October 22-26, 2001 © 2001 Microsoft Corporation. All rights reserved. 6
  • 7. Data Access Inside SQL using System.Data.SqlServer; System.Data.SqlServer; using System.Data.SqlTypes; System.Data.SqlTypes; public class ShippingCosts { public static SqlMoney FreightByShipper( string ship ) { FreightByShipper( SqlCommand cmd = SqlContext.GetCommand( ); SqlContext.GetCommand( cmd.CommandText = "select sum(o.freight) as freight " + "from orders o join shippers s on o.shipvia = s.shipperid " + "where s.companyname = @CompanyName " ; @CompanyName SqlParameter param = cmd.Parameters.Add("@CompanyName", cmd.Parameters.Add("@CompanyName", SqlDbType.NVarChar, SqlDbType.NVarChar, COMPANY_NAME_COL_LENGTH); param.Value = ship; ship; SqlMoney amount = cmd.ExecuteScalar( ); cmd.ExecuteScalar( return amount; } } SQL Types l l l Reduce impedance mismatch between programming language and data Consistent expression evaluation in midmid- and server-tier programming serverSQL Types library Ø Ø Managed classes: System.Data.SqlTypes Provide SQL semantics § § Nullability, threeNullability , three-valued logic Precision and scale in operations PDC 2001 October 22-26, 2001 © 2001 Microsoft Corporation. All rights reserved. 7
  • 8. SQL Types Example Tax function using SQL types l using System; using System.Data.SQLTypes ; public class myFinances { public static SQLDouble tax( SQLDouble sal ) { if ( sal < 50000.0 ) return sal * 0.15; 0.15; if ( sal >= 50000.0 && sal <= 90000.0 ) return sal * 0.23 else return sal * 0.35; 0.35; } } SQLDouble makes function NULL-aware NULL- Outline l l Motivation Basic Infrastructure Ø Ø Ø l SQL features Ø Ø Ø l Hosting overview Data access inside process: ADO.NET SQL types Server assemblies Functions, procedures, triggers Types and aggregates Summary PDC 2001 October 22-26, 2001 © 2001 Microsoft Corporation. All rights reserved. 8
  • 9. SQL Features Assemblies Functions Procedures Triggers Types l l l l l Creating An Assembly CREATE ASSEMBLY geom FROM ‘m1typesgeometry.dll’ ‘ m1types WITH PERMISSION_SET = SAFE WITH AUTOREGISTER DROP ASSEMBLY lib_geom l Assemblies stored in database Ø l Ø l Safe (default), external access, unrestricted Autoregister functions Ø l Backup, restore with data Code permissions assigned per assembly Using .NET custom attributes Assembly benefits Ø Ø SelfSelf-describing metadata: Types, file dependencies Unit of code deployment: Permissions, versioning PDC 2001 October 22-26, 2001 © 2001 Microsoft Corporation. All rights reserved. 9
  • 10. Altering An Assembly l l Cannot invalidate persistent data or indexes Implies Ø Ø l l No tables with columns of UDT from this assembly No indexes on functions of this assembly Force option allows ALTER even if persistent dependencies exist Packaging considerations Ø Place routines and types in different assemblies Creating A Function CREATE FUNCTION distance ( @x1 int, @y1 int, @x2 int, @y2 int ) RETURNS float int, int, int, EXTERNAL NAME ‘geom:CPoint.Distance’ ‘geom:CPoint.Distance’ DETERMINISTIC RETURNS NULL ON NULL INPUT DROP FUNCTION distance l Functions called from queries Ø Ø Ø l Can be scalar or table -valued Static class functions Deterministic functions Using a function in a query SELECT s.name FROM Supplier s WHERE dbo.distance ( s.x, s.y, @x, @y ) < 3 dbo.distance( PDC 2001 October 22-26, 2001 © 2001 Microsoft Corporation. All rights reserved. 10
  • 11. Creating A Procedure CREATE PROCEDURE check_inventory EXTERNAL NAME ‘events:CInventory.check_level’ ‘events:CInventory.check_level’ DROP PROCEDURE check_inventory l Procedures not called from queries Ø Ø Can contain SQL queries, updates or DDL Can return results directly to client Creating A Trigger CREATE TRIGGER supplier_event ON supplier AFTER INSERT, UPDATE EXTERNAL NAME ‘events:CNotif.Supp_Event’ ‘events:CNotif.Supp_Event’ DROP TRIGGER supplier_event l l Similar to procedures, plus Access to inserted, deleted tables PDC 2001 October 22-26, 2001 © 2001 Microsoft Corporation. All rights reserved. 11
  • 12. Creating A Type l Create or drop a type CREATE TYPE Point EXTERNAL NAME ‘geom:Point’ ‘geom:Point’ DROP TYPE Point l Using a type CREATE TABLE Supplier ( id INTEGER PRIMARY KEY, name VARCHAR(20), location Point ) l Using a type method in a query SELECT s.name FROM Supplier s WHERE s.location::distance( @point ) < 3 Query Optimization l Automatically gather function statistics Ø l Reorder of predicate evaluation Ø l Based on execution cost and statistics Function indexes Ø Ø l Value histograms, execution cost Speed up expensive functions Extends computed column indexes and index views Implied and residual predicates PDC 2001 October 22-26, 2001 © 2001 Microsoft Corporation. All rights reserved. 12
  • 13. Summary Richer server programming model l Ø Ø Ø Any .NET framework language Same mid - and server -tier data access: midserverADO. NET Same IDE, project model, debugging, tools SQL Server hosting of .NET runtime l Ø Safety, security, scalability, speed SQL Server .NET features l Ø Functions, stored procedures, triggers, types, aggregates Demos l l Sample code for function, stored procedure, and type Assemblies Ø l Functions and stored procedures Ø Ø l Safe versus external access Creation and execution Data access in-process via ADO .NET in- Types Ø Ø Ø Ø Ø Type contract Create type Create table with column of user-defined type userCreate index on column of user-defined type userInsert and query the table PDC 2001 October 22-26, 2001 © 2001 Microsoft Corporation. All rights reserved. 13
  • 14. © 2001 Microsoft Corporation. All rights reserved. PDC 2001 October 22-26, 2001 © 2001 Microsoft Corporation. All rights reserved. 14