Best Practices for Stored Procedures in SQL Server 2000/2005

1,041 views
988 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,041
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
45
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Founded in 1987, Quest Software, Inc. is a publicly traded company that provides software to simplify IT management to 18,000 customers worldwide, including 75 percent of the Fortune 500. Quest products for application, database and Windows management help customers develop, deploy, manage and maintain the IT enterprise without expensive downtime or business interruption. Since its IPO in 1999, Quest has maintained continued growth, year over year, even against sector trends in in 2001 and 2002. Today, Quest has 2,200 employees around the world.
  • Industry experts also agree. Quest continues to win significant industry awards from partners, press and market analysts who each underscore the prowess of Quest solutions and our market share leadership. As an aside, Quest is also ranked #1 in Windows Management by IDC and Gartner
  • Quest has the most breadth and depth of any other vendor. We have the most extensive product portfolio. And our products fit at all spectrums of the development and production environment for delivering and managing your SQL Server Environment.
  • Best Practices for Stored Procedures in SQL Server 2000/2005

    1. 1. Top 10 Most Common Mistakes on Microsoft SQL Server By Kevin Kline SQL Server MVP
    2. 2. Agenda <ul><li>Speaker Bio </li></ul><ul><li>About Quest Software </li></ul><ul><li>Accolades & Awards </li></ul><ul><li>The Top 10 Most Common Mistakes on Microsoft SQL Server </li></ul><ul><li>Call to Action </li></ul><ul><li>Q & A </li></ul>
    3. 3. <ul><li>Started in IT in 1986 </li></ul><ul><ul><li>BS in MIS in 1989 from University of Alabama </li></ul></ul><ul><li>Microsoft SQL Server MVP since 2004 </li></ul><ul><li>Author of 7 database books </li></ul><ul><ul><li>1 on Oracle, 2 on SQL Server, 2 on SQL, 1 on DB design, 1 on DB benchmarking </li></ul></ul><ul><li>President of PASS ( www.sqlpass.org ) </li></ul><ul><ul><li>Conference is next Sept in Denver, CO </li></ul></ul><ul><ul><li>Over 130 sessions on SQL Server, BI & Dev </li></ul></ul><ul><li>Blogs for SQLMag.com and SQLBlog.com </li></ul><ul><li>Writes monthly columns for Database Trends & Applications and SQL Server Magazine </li></ul><ul><li>Prior to joining Quest worked for NASA, US Army, and Deloitte & Touche </li></ul>Speaker Bio
    4. 4. About Quest Software <ul><li>Profitable & Growing </li></ul><ul><ul><li>Over a half-billion in ’06 revenues </li></ul></ul><ul><ul><li>Continued growth in ’01 through ‘06 against sector trends </li></ul></ul><ul><li>Founded in 1987 </li></ul><ul><li>Public in 1999 </li></ul><ul><ul><li>Nasdaq: QSFT </li></ul></ul><ul><li>Customers: 18,000 Worldwide </li></ul><ul><ul><li>Including 75 percent of the Fortune 500 </li></ul></ul><ul><li>over 2,750 employees </li></ul><ul><ul><li>Over 950 in R&D </li></ul></ul><ul><ul><li>Nearly a dozen R&D centers around the globe </li></ul></ul><ul><li>Headquarters: Aliso Viejo, CA </li></ul>
    5. 5. Accolades & Awards <ul><li>TechTarget Product of the Year 2006 - LiteSpeed </li></ul><ul><li>Best of Tech Ed award 2006 with Spotlight on SQL Server </li></ul><ul><li>SQL Server Magazine, Platinum reader’s choice award </li></ul><ul><li>SQL Server Magazine Readers Choice Awards, winner in 11 categories, 2005 </li></ul><ul><li>No. 1 vendor in Distributed Data Management Facilities, IDC, 2005 </li></ul><ul><li>Microsoft TechEd Europe Best of Show Winner, 2005 </li></ul><ul><li>No. 1 vendor in Application Management Software, Gartner Dataquest, 2005 </li></ul><ul><li>Jolt Productivity Award Winner </li></ul><ul><li>Network Computing Editor’s Choice Winner </li></ul><ul><li>No. 8 in the “Who’s Who in Enterprise Software,” Investor’s Business Daily </li></ul>
    6. 6. The Top 10 List <ul><li>Includes issues covering: </li></ul><ul><ul><li>Database Design </li></ul></ul><ul><ul><li>Database Administration </li></ul></ul><ul><ul><li>Application Development </li></ul></ul><ul><li>Includes an explanation for each item on the list </li></ul><ul><li>Includes resources to alleviate the mistake </li></ul>
    7. 7. Placeholder for Polling Question #1 <ul><li>How many servers are you currently responsible for managing: </li></ul><ul><ul><li>1-20 </li></ul></ul><ul><ul><li>21-50 </li></ul></ul><ul><ul><li>51-70 </li></ul></ul><ul><ul><li>71-100 </li></ul></ul><ul><ul><li>More than 100 servers </li></ul></ul>
    8. 8. Placeholder for Polling Question #2 <ul><li>In your day-to-day activities, which of the following require the most time and attention cause you the most aggravation: </li></ul><ul><ul><li>Backup / Recovery / Replication </li></ul></ul><ul><ul><li>Finding and fixing performance problems </li></ul></ul><ul><ul><li>Managing database changes </li></ul></ul><ul><ul><li>Evaluating resource consumption / planning for future requirements </li></ul></ul><ul><ul><li>Tuning and optimizing your SQL Server environment </li></ul></ul><ul><ul><li>Job and Schedule maintenance </li></ul></ul><ul><ul><li>Performing other routine maintenance (i.e. degragmenting indexes, writing stored procedures, physical server maintenance) </li></ul></ul>
    9. 9. Alternate way to ask Polling Question #2 <ul><li>In your day-to-day activities, which of the following causes you the most aggravation: </li></ul><ul><ul><li>Backup / Recovery / Replication </li></ul></ul><ul><ul><li>Finding and fixing performance problems </li></ul></ul><ul><ul><li>Managing database changes </li></ul></ul><ul><ul><li>Evaluating resource consumption / planning for future requirements </li></ul></ul><ul><ul><li>Tuning and optimizing your SQL Server environment </li></ul></ul><ul><ul><li>Job and Schedule maintenance </li></ul></ul><ul><ul><li>Performing other routine maintenance (i.e. degragmenting indexes, writing stored procedures, physical server maintenance) </li></ul></ul>
    10. 10. 10. Unknown Scalability Requirements <ul><li>DBAs and Developers must understand the scalability requirements of their application and database design. Without it, the following problems occur: </li></ul><ul><ul><li>Inadequate development testing </li></ul></ul><ul><ul><ul><li>Often times, requirements don’t include performance goals </li></ul></ul></ul><ul><ul><ul><li>Even more often, requirements don’t include scalability goals </li></ul></ul></ul><ul><ul><li>Performance shortcomings </li></ul></ul><ul><ul><li>Additional QA needed </li></ul></ul><ul><ul><ul><li>Often, no or very little time to fix findings of QA process </li></ul></ul></ul><ul><ul><li>What about the future? </li></ul></ul><ul><ul><ul><li>No capacity planning or forecasting </li></ul></ul></ul>
    11. 11. 9. Improperly Normalized Tables <ul><li>DBAs and Developers must perform a thorough database design phase. Without it, the following problems occur: </li></ul><ul><ul><li>Duplicate data </li></ul></ul><ul><ul><li>Normalization performance anomalies, such as the classic Insert, Update, and Delete anomalies </li></ul></ul><ul><ul><li>No or poor indexing </li></ul></ul><ul><ul><li>No or poor key relationships </li></ul></ul><ul><ul><li>Bad or non-existent naming standards </li></ul></ul><ul><ul><li>Missed opportunities to denormalize </li></ul></ul>
    12. 12. 8. Indexing Issues <ul><li>DBAs and Developers must do a thorough job indexing their database. Without it, the following problems occur: </li></ul><ul><ul><li>Too many page splits </li></ul></ul><ul><ul><ul><li>Alleviated by using fill factor and sometimes pad_indexes </li></ul></ul></ul><ul><ul><li>Poor non-clustered indexing </li></ul></ul><ul><ul><ul><li>Doesn’t help with SQL transactions </li></ul></ul></ul><ul><ul><ul><li>Not applied to foreign key fields </li></ul></ul></ul><ul><ul><ul><li>Missed opportunity for covering indexes </li></ul></ul></ul><ul><ul><ul><li>Too many columns on composite indexes </li></ul></ul></ul><ul><ul><li>Non-existent or bad clustered index </li></ul></ul><ul><ul><li>Non-existent or poorly selective primary key </li></ul></ul><ul><li>Many times, DBAs and Developers forget to update statistics on indexes </li></ul>
    13. 13. 7. No Baselines or Benchmarks <ul><li>DBAs and Developers frequently have no idea what their server load is, nor can they tell you what it’s peak load might be. Without this knowledge, the following problems occur: </li></ul><ul><ul><li>Manage the user experience solely by call volume </li></ul></ul><ul><ul><li>Cannot meet SLAs </li></ul></ul><ul><ul><li>Cannot predict behavior </li></ul></ul><ul><ul><ul><li>Will it be busy at the end of the week, month, or quarter? </li></ul></ul></ul><ul><ul><ul><li>Will it be busy after lunch? After a major holiday? </li></ul></ul></ul><ul><ul><li>Don’t know if where to start fixing problems: </li></ul></ul><ul><ul><ul><li>Throw more hardware at it? </li></ul></ul></ul><ul><ul><ul><li>Tune SQL/app code? </li></ul></ul></ul><ul><ul><li>May add additional apps/databases to a server that cannot sustain the combined load </li></ul></ul>
    14. 14. 6. Disks – Thinking Space but not IO <ul><li>DBAs and Developers frequently think about their disk subsystems only in terms of disk space not IO load. Without this knowledge, the following problems occur: </li></ul><ul><ul><li>Inadequate fault tolerance </li></ul></ul><ul><ul><li>Insufficient IO: </li></ul></ul><ul><ul><ul><li>OLTP requires high transactions/sec </li></ul></ul></ul><ul><ul><ul><li>OLAP requires high MB transfers/sec </li></ul></ul></ul><ul><ul><li>Poor choice of RAID type </li></ul></ul><ul><ul><li>Not enough disk spindles </li></ul></ul><ul><ul><li>Poor use of controllers and/or channels </li></ul></ul><ul><ul><li>Let the SAN administrator tell them what they get </li></ul></ul>
    15. 15. 5. Error Notification <ul><li>DBAs and Developers don’t take advantage of easy to use error notification built into SQL Server. Without this feature, the following problems occur: </li></ul><ul><ul><li>Important schedule jobs fail without intervention </li></ul></ul><ul><ul><li>Must rely upon end-users to notify of problems: </li></ul></ul><ul><ul><ul><li>Squeaky wheel, but not most important problem, gets the grease </li></ul></ul></ul><ul><ul><ul><li>Miss problems that occur when users not on the system </li></ul></ul></ul><ul><ul><li>Valuable diagnostic and troubleshooting time wasted </li></ul></ul><ul><ul><li>Must manually check all managed servers </li></ul></ul><ul><ul><li>Impossible to be truly proactive </li></ul></ul>
    16. 16. 4. Backups <ul><li>DBAs and Developers do not test backups nor recoveries as they should. Without this activity, the following problems occur: </li></ul><ul><ul><li>Not certain that backups are good: </li></ul></ul><ul><ul><ul><li>Verified </li></ul></ul></ul><ul><ul><ul><li>Available </li></ul></ul></ul><ul><ul><li>Not certain where to get all data, files, DLLs, etc for backup </li></ul></ul><ul><ul><li>Haven’t tested a full, ground-up restore: </li></ul></ul><ul><ul><ul><li>What if you have to reinstall everything? </li></ul></ul></ul><ul><ul><ul><li>The importance of recovery: the Lost Job scenario </li></ul></ul></ul><ul><ul><li>Cannot actually perform a full restore on archived data </li></ul></ul>
    17. 17. 3. Query Tuning <ul><li>DBAs and Developers don’t know how to tune a query. Without this proficiency, the following problems occur: </li></ul><ul><ul><li>Don’t know which tools to use: </li></ul></ul><ul><ul><ul><li>PerfMon </li></ul></ul></ul><ul><ul><ul><li>SQL Profiler </li></ul></ul></ul><ul><ul><ul><li>Graphic Showplan and SET SHOWPLAN </li></ul></ul></ul><ul><ul><ul><li>SET STATISTICS IO </li></ul></ul></ul><ul><ul><li>Don’t know how to read a query plan: </li></ul></ul><ul><ul><ul><li>Why is an index seek better than a table scan? </li></ul></ul></ul><ul><ul><ul><li>Why are logical reads better than physical reads? </li></ul></ul></ul><ul><ul><li>Cannot suggest or try alternative plans that improve performance </li></ul></ul><ul><ul><li>Application will not scale beyond a few users </li></ul></ul><ul><ul><li>May spend more money on hardware to fix an “eternal” problem </li></ul></ul>
    18. 18. 2. Ignorance of Internals <ul><li>DBAs and Developers don’t know the basics of the SQL Server internals, such as the storage engine and query engine. Without this knowledge, the following problems occur: </li></ul><ul><ul><li>Write terrible queries and them place into production </li></ul></ul><ul><ul><ul><li>Too much IO </li></ul></ul></ul><ul><ul><ul><li>Too much locking and/or deadlocking </li></ul></ul></ul><ul><ul><ul><li>Missed opportunities for indexes </li></ul></ul></ul><ul><ul><li>Don’t realize impact of checkpointing and lazywriter </li></ul></ul><ul><ul><ul><li>Cause false alarms when checking performance </li></ul></ul></ul><ul><ul><li>Miss opportunities to read from cache </li></ul></ul><ul><ul><ul><li>E.G. Force recompiles of stored procedures </li></ul></ul></ul><ul><ul><li>Miss the chance to utilize partitions and file group distribution for better IO </li></ul></ul>
    19. 19. 1. Cursors <ul><li>Ok for small, one-off applications with very limited number of rows </li></ul><ul><li>Deprecated by Microsoft. Try to find it in SQL2005 documentation! </li></ul><ul><li>DBAs and Developers don’t know the basics of set theory versus row theory. Without this knowledge, the following problems occur: </li></ul><ul><ul><li>Locking problems </li></ul></ul><ul><ul><li>Memory problems </li></ul></ul><ul><ul><ul><li>Remember to deallocate those cursors </li></ul></ul></ul><ul><ul><li>Iterations can take a long time </li></ul></ul>
    20. 20. Polling Question #3 <ul><li>What best describes the type of environment for which you’re responsible? </li></ul><ul><ul><li>Production environment supporting business critical apps </li></ul></ul><ul><ul><li>Production environment supporting non-critical apps </li></ul></ul><ul><ul><li>Pre-Production environment (Test/Development) </li></ul></ul><ul><ul><li>All of the above </li></ul></ul>
    21. 22. Quest Solutions <ul><li>10. Unknown Scalability Requirements </li></ul><ul><ul><li>Capacity Manager for SQL Server </li></ul></ul><ul><li>9. Improperly Normalized Tables </li></ul><ul><ul><li>Toad Data Modeler </li></ul></ul><ul><li>8. Indexing Issues </li></ul><ul><ul><li>Toad Xpert for SQL Server </li></ul></ul><ul><ul><li>Performance Analysis for SQL Server </li></ul></ul><ul><li>7. No Baselines or Benchmarks </li></ul><ul><ul><li>Capacity Manager for SQL Server </li></ul></ul><ul><ul><li>Benchmark Factory </li></ul></ul><ul><li>6. Disks – Thinking Space but not IO </li></ul><ul><ul><li>Capacity Manager </li></ul></ul><ul><ul><li>Spotlight on SQL Server Enterprise </li></ul></ul><ul><ul><li>Performance Analysis for SQL Server </li></ul></ul>
    22. 23. Quest Solutions <ul><li>5. Error Notification </li></ul><ul><ul><li>Spotlight on SQL Server Enterprise </li></ul></ul><ul><li>4. Backups </li></ul><ul><ul><li>LiteSpeed for SQL Server </li></ul></ul><ul><li>3. Query Tuning </li></ul><ul><ul><li>Toad Xpert for SQL Server </li></ul></ul><ul><ul><li>Performance Analysis for SQL Server </li></ul></ul><ul><ul><li>Coefficient </li></ul></ul><ul><li>2. Ignorance of Internals </li></ul><ul><ul><li>Spotlight on SQL Server Enterprise </li></ul></ul><ul><ul><li>Performance Analysis for SQL Server </li></ul></ul><ul><li>1. Cursors </li></ul><ul><ul><li>Spotlight on SQL Server Enterprise </li></ul></ul><ul><ul><li>Performance Analysis for SQL Server </li></ul></ul>
    23. 24. Resources <ul><li>See my other webcasts on YouTube. Search for “Kevin Kline SQL”. </li></ul><ul><li>Refer to my white papers at www.quest.com /whitepapers . </li></ul><ul><li>Check out the fantastic webcasts at TechNet and MSDN: </li></ul><ul><ul><li>http://www.microsoft.com/technet/community/en-us/sql/webcasts.mspx </li></ul></ul><ul><ul><li>http://msdn2.microsoft.com/en-us/sql/default.aspx </li></ul></ul><ul><li>Refer to learning resources at www.sqlpass.org . </li></ul>
    24. 25. Q & A <ul><li>Send questions to me at: [email_address] </li></ul><ul><li>Send broader technical questions to: [email_address] </li></ul><ul><li>Send sales & licensing questions to: [email_address] </li></ul><ul><li>More information about Quest’s solutions for SQL Server and to download trial software: www.quest.com/sql_server </li></ul><ul><li>Today’s presentation was recorded. </li></ul><ul><ul><li>On-demand archive and slide deck will be available this week </li></ul></ul><ul><ul><li>Links will be sent to all of today’s participants </li></ul></ul><ul><li>THANK YOU! </li></ul>

    ×