necessary evils, building optimized crud procedures

20
Necessary Evils, Building Optimized CRUD Procedures

Upload: jason-strate

Post on 22-Jun-2015

508 views

Category:

Technology


1 download

DESCRIPTION

Every developer loves them and a lot of DBAs hate them. But there are many and valid reasons for creating generic SELECT, INSERT, UPDATE, and DELETE procedures. In this session, we’ll go through designing CRUD procedures that utilize new and existing SQL features to create CRUD procedures that are optimized for performance.

TRANSCRIPT

Page 1: Necessary Evils, Building Optimized CRUD Procedures

Necessary Evils, Building Optimized CRUD Procedures

Page 2: Necessary Evils, Building Optimized CRUD Procedures

Jason Strate

e: [email protected]

e: [email protected]

b: www.jasonstrate.com

t: StrateSQL

Resources jasonstrate.com

Introduction

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 3: Necessary Evils, Building Optimized CRUD Procedures

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

• Industry leaders in Microsoft BI and SQL Server Platform

• SQL Server Professionals - PASS Board of Directors, Speakers, Authors and MVP’s

• National Sales Team Divided by Microsoft Territories

• National System Integrator (NSI)• Gold Certified in Business Intelligence and Data

Platform• Platform Modernization/Safe Passage• Premier Partner for PDW SI Partner Program

MS PDW Partner of Year FY13Frontline Partnership Partner of the Year for Big DataExecutive sponsor - Andy Mouacdie, WW sales director PDW

• Over 7,200 customers worldwide• Over 186,000 people in PW database for demand

generation

About Pragmatic Works

Page 4: Necessary Evils, Building Optimized CRUD Procedures

Session Goals

1. Describe the uses for CRUD procedures in databases

2. Identify the common problems associated with CRUD procedures

3. Demonstrate methods for writing performantCRUD procedures

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 5: Necessary Evils, Building Optimized CRUD Procedures

What is CRUD?

CREATE, READ, UPDATE, DELETE

• ABCD: add, browse, change, delete• BREAD: browse, read, edit, add, delete• QDIM: query, delete, insert, modify• SAID: show, alter, insert, delete• VEDAS: view, edit, delete, add, search• VADE(R): view, add, delete, edit

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 6: Necessary Evils, Building Optimized CRUD Procedures

Code Generation

• Many tools available:

– T-SQL Script

– Code Smith

– Entity Framework

– LINQ to SQL

– NHibernate

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 7: Necessary Evils, Building Optimized CRUD Procedures

CRUD Issues?

• Treat tables as objects– People?

– Relationships?

– Relationship Type?

• Overly generic– All columns touched

– One procedure to rule them all

• Performance– Set versus Singleton

– Index selection

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 8: Necessary Evils, Building Optimized CRUD Procedures

Perspectives

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 9: Necessary Evils, Building Optimized CRUD Procedures

CREATE, UPDATE, AND DELETE

Overview

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 10: Necessary Evils, Building Optimized CRUD Procedures

CREATE

CREATE = INSERT

Issues:

• Singleton insert

• All columns affected

INSERT INTO dbo.Foo

(Column1, Column2)

VALUES(@Column1,

@Column2)

EXEC CRUD.FooInsert

@Column1 = 'Value‘,

@Column2 = 2

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 11: Necessary Evils, Building Optimized CRUD Procedures

UPDATE = UPDATE

Issues:

Singleton update

All columns affected

UPDATE

UPDATE dbo.Foo

SET Column1 = @Column1

WHERE Column2 =

@Column2

EXEC CRUD.FooUpdate

@Column1 = 'Value‘,

@Column2 = 2

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 12: Necessary Evils, Building Optimized CRUD Procedures

DELETE

DELETE = DELETE

Issues:

• Singleton delete

DELETE FROM dbo.Foo

WHERE Column2 = Column2

EXEC CRUD.FooDelete

@Column2 = 2

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 13: Necessary Evils, Building Optimized CRUD Procedures

T-SQL Features

• Performance

– Table Valued Functions (TVF)

– Table Valued Parameters (TVP)

– XML document

– Merge statement

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 14: Necessary Evils, Building Optimized CRUD Procedures

CREATE, UPDATE, AND DELETE

Demos

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 15: Necessary Evils, Building Optimized CRUD Procedures

READ

Overview

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 16: Necessary Evils, Building Optimized CRUD Procedures

READ

• READ = SELECT

Issues

• Index selectivity

SELECT Column1

,Column2

FROM dbo.Foo

WHERE (@Column1 IS NULL

OR Column1 = @Column1)

AND (@Column2 IS NULL

OR Column2 = @Column2)

EXEC CRUD.FooSelect

@Column1 = NULL

,@Column2 = 2

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 17: Necessary Evils, Building Optimized CRUD Procedures

READ

Demo

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 18: Necessary Evils, Building Optimized CRUD Procedures

Summary

1. CRUD isn’t necessarily bad

2. Generic templates offer ability to tune and extend data model behind the scenes.

3. Be cautious in choosing a template for CRUD

4. Know what SQL Server is doing

5. Leverage RECOMPILE as needed

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 19: Necessary Evils, Building Optimized CRUD Procedures

Learn More About Performance

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 20: Necessary Evils, Building Optimized CRUD Procedures

ServicesSpeed development through training, and rapid development services from Pragmatic Works.

ProductsBI products to covert to a Microsoft BI platform and simplify development onthe platform.

FoundationHelping those who do not have themeans to get into information technologyachieve their dreams.

For more information…

Name: Jason Strate

Email: [email protected]

Blog: www.jasonstrate.com