SQL Server Database Development Best Practices€¦ · SQL Server Database Development Best...

Post on 05-Jun-2018

225 views 2 download

transcript

SQL Server Database Development Best Practices

Grant Fritchey, Red Gate Software Grant.Fritchey@red-gate.com Jeremy Kadlec, Edgewood Solutions jeremyk@edgewoodsolutions.com

Agenda

Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved 2

• Introductions

• Best Practices

– Design, Build, Test, Deploy, Tools

• Demos

• Q&A and Thank You

• Special offer for all attendees

Grant Fritchey • Product Evangelist for Red Gate Software

• Microsoft SQL Server MVP

• Author: – SQL Server Execution Plans

– SQL Server 2008 Query Performance Tuning Distilled

– SQL Server MVP Deep Dives II

Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved 3

Jeremy Kadlec • Edgewood Solutions - CTO

• jeremyk@edgewoodsolutions.com • 410.591.4683

• MSSQLTips.com - Co-Founder • Twitter - @MSSQLTips • LinkedIn -

http://www.linkedin.com/ groups/MSSQLTips-2320891

• Baltimore SQL Server Users Group - Co-Leader • www.bssug.org

• SQL Server MVP

4 Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved

Design Best Practices

5 Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved

Build a Strong Foundation

Comprehensive Data Modeling

Right Technology @ Right Time

#1 – Build a Strong Foundation

Forward Thinking

• Business Goals

• Long Term Needs

Scope & Support

• Managerial Support

• Reasonable Expectations

Cohesive Team

• Correct Skills and Training

• Accountability

Stable Platform

• Appropriate Technology

• Meet Performance Needs

Complete Requirements

• Correct Level of Detail

• Agreement

6 Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved

#2 – Comprehensive Data Model

Flexibility Scalability

Growth

• Set the standard - Build a Data Modeling Checklist for your company • Make the Data Dictionary mandatory

• Store meta data in your SQL Server database • Include object, column, relationships, sample data, etc. • Maintain with your releases

• Include in code reviews and source control

7 Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved

#3 - Right Technology @ Right Time

Plan Options

Proof of Concept

Experience

• Holistic view

• Build technical plan

• Seek alternatives

• Mitigate risk with new technologies

– Proof of concept

• Pull from experience

• Document and discuss with team

8 Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved

Build Best Practices

9 Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved

Leverage Your Sandbox Environment

Build on Your Experience

Prioritize Security

#4 – Leverage Your Sandbox Environment

• Functional environment to match production

• Ability to setup quickly and begin development

• Intended for personal or small group usage

• Ability to build and recreate as needed

• Isolated so no impact to other team members

Functional environment

to match production

Feature Enhancements

Greenfield Development

Prototype Development

10 Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved

#5 – Build on Your Experience

Naming conventions

Comment code

Parameters in tables

Consolidated error handling

Referential integrity, data types, indexes, etc.

Select correct technology

Review query plans

Code reviews

Check-in procedures

No functions in WHERE clause

Avoid cursors, temp tables, triggers, etc. when a better solution is available

No views on top of views on top of views

Don’t throw hardware at a database design problem

Verify code before check-in

No code susceptible to SQL Injection

11 Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved

#6 – Prioritize Security • “From 2005 through to September 20, 2011, SQLinjection has been

responsible for 83% of successful hacking-related data breaches.”

– http://blog.imperva.com/2011/09/sql-injection-by-the-numbers.html

• “…from 2005 to September 20, 2011. There were 312,437,487 data records lost due to hacking with about 262 million records from various breaches including TJMax, RockYou and Heartland, all of which were SQL injection attacks.”

– http://blog.imperva.com/2011/09/sql-injection-by-the-numbers.html

• “In the wild, it has been noted that applications experience, on average, 71 attempts an hour.[1] When under direct attack, some applications occasionally came under aggressive attacks and at their peak, were attacked 800–1300 times per hour.”

– http://en.wikipedia.org/wiki/SQL_injection#cite_note-blog.imperva.com-0

12 Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved

Test Best Practices

13 Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved

Coordinate Parallel Development

Close the Loop

#7 - Coordinate Parallel Development

Customer Object

Release 1.1

Hot Fix 1.1.1

Release 1.2.2

• Coordination requires communication, comments and notation • Prevent “Code Jambalaya“ from causing chaos and frustration

14 Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved

Release Issues

#8 - Close the Loop

15

Review Requirements

Build Test Cases

Development

Track Changes Verify

Requirements

Promote to Test

User Involvement

Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved

Deployment Best Practices

16 Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved

Avoid Deployment Catastrophes

#9 – Avoid Deployment Catastrophes Don’t deploy suspect code, apply the brakes Don’t let any changes sneak into the environment Don’t assume things will just work out Don’t take someone’s word that code is accurate

Build rollback scripts as your insurance policy

Deploy the same scripts to Test as Production – Rollback deployment and re-

deploy until error free

Double check your deployment scripts for accuracy – Remember “Code Jambalaya“

Ensure deployment is verified, do not find out from users

17 Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved

Tools Best Practices

18 Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved

Build Re-Useable Templates

Standardize Tools and Methods

#10 – Build Re-Useable Templates • T-SQL Templates

– Integrate with SSMS

– Template projects

– Data dictionary

• Integration Services – Import processes

– Export processes

• Reporting Services – Connection objects

– Headers, footers, etc.

• Benefits – No “blank slate”

syndrome

– Standardization

– Set expectations

– Time saver

19 Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved

#11 – Standardize Tools and Methods

• Methods – Data Access

– Comments

– Deployment

– Rollback

– Communication

• SQL Server Tools – Development

– Continuous Integration

– Source Control

– Refactoring

20 Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved

Next Steps Offer For all webinar registrants

SQL Source Control - $99

SQL Developer Bundle - $200 discount

Email michael.francis@red-gate.com

Quote code “webinarmssqltipsmarch2012”

One offer per organization

red-gate.com

28-day free trial

14-day free trial