SQL Server Database
Development Best Practices
Grant Fritchey, Red Gate Software
[email protected] Jeremy Kadlec, Edgewood Solutions
[email protected] Agenda
• Introductions
• Best Practices
– Design, Build, Test, Deploy, Tools
• Demos
• Q&A and Thank You
• Special offer for all attendees
Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved 2
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
•
[email protected] • 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
Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved 4
Design Best Practices
Build a Strong Foundation
Comprehensive Data Modeling
Right Technology @ Right Time
Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved 5
#1 – Build a Strong Foundation
Complete
Requirements
Stable Platform • Correct Level of
• Appropriate Detail
Cohesive Team Technology • Agreement
• Correct Skills and • Meet Performance
Needs
Scope & Training
Support • Accountability
Forward • Managerial
Thinking Support
• Business Goals • Reasonable
Expectations
• Long Term Needs
Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved 6
#2 – Comprehensive Data Model
Growth
Scalability
Flexibility
• 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
Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved 7
#3 - Right Technology @ Right Time
• Holistic view
• Build technical plan
Plan Options • Seek alternatives
• Mitigate risk with new
technologies
– Proof of concept
Proof of
Concept
Experience • Pull from experience
• Document and discuss
with team
Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved 8
Build Best Practices
Leverage Your Sandbox Environment
Build on Your Experience
Prioritize Security
Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved 9
#4 – Leverage Your Sandbox Environment
• Functional environment
to match production Feature
Enhancements
• Ability to setup quickly
and begin development
Functional
• Intended for personal or
environment
small group usage to match
• Ability to build and production
Prototype Greenfield
recreate as needed Development Development
• Isolated so no impact to
other team members
Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved 10
#5 – Build on Your Experience
Naming conventions No functions in WHERE clause
Comment code Avoid cursors, temp tables,
Parameters in tables triggers, etc. when a better
Consolidated error handling solution is available
Referential integrity, data No views on top of views on
types, indexes, etc. top of views
Select correct technology Don’t throw hardware at a
database design problem
Review query plans
Verify code before check-in
Code reviews
No code susceptible to SQL
Check-in procedures Injection
Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved 11
#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
Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved 12
Test Best Practices
Coordinate Parallel Development
Close the Loop
Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved 13
#7 - Coordinate Parallel Development
Release 1.1
Hot Fix 1.1.1 Customer Release
Issues
Object
Release 1.2.2
• Coordination requires communication, comments and notation
• Prevent “Code Jambalaya“ from causing chaos and frustration
Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved 14
#8 - Close the Loop
Review
Requirements
User Involvement Build Test Cases
Promote to Test Development
Verify
Track Changes
Requirements
Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved 15
Deployment Best Practices
Avoid Deployment Catastrophes
Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved 16
#9 – Avoid Deployment Catastrophes
Don’t deploy suspect code, Build rollback scripts as your
apply the brakes insurance policy
Don’t let any changes sneak Deploy the same scripts to
into the environment Test as Production
Don’t assume things will – Rollback deployment and re-
just work out deploy until error free
Don’t take someone’s word Double check your
that code is accurate deployment scripts for
accuracy
– Remember “Code Jambalaya“
Ensure deployment is
verified, do not find out
from users
Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved 17
Tools Best Practices
Build Re-Useable Templates
Standardize Tools and Methods
Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved 18
#10 – Build Re-Useable Templates
• T-SQL Templates • Benefits
– Integrate with SSMS – No “blank slate”
– Template projects syndrome
– Data dictionary – Standardization
• Integration Services – Set expectations
– Import processes – Time saver
– Export processes
• Reporting Services
– Connection objects
– Headers, footers, etc.
Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved 19
#11 – Standardize Tools and Methods
• Methods
– Data Access
– Comments
– Deployment
– Rollback
– Communication
• SQL Server Tools
– Development
– Continuous Integration
– Source Control
– Refactoring
Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved 20
Next Steps
Offer red-gate.com
For all webinar registrants
SQL Source Control - $99
SQL Developer Bundle - $200 discount
28-day free trial
Email
[email protected]Quote code “webinarmssqltipsmarch2012”
One offer per organization
14-day free trial