Are you following SQL Server Development Best Practices?

Slides:



Advertisements
Similar presentations
Yukon – What is New Rajesh Gala. Yukon – What is new.NET Framework Programming Data Types Exception Handling Batches Databases Database Engine Administration.
Advertisements

Module 13: Performance Tuning. Overview Performance tuning methodologies Instance level Database level Application level Overview of tools and techniques.
Big Data Working with Terabytes in SQL Server Andrew Novick
Database Optimization & Maintenance Tim Richard ECM Training Conference#dbwestECM Agenda SQL Configuration OnBase DB Planning Backups Integrity.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 11 Database Performance Tuning and Query Optimization.
Architecting a Large-Scale Data Warehouse with SQL Server 2005 Mark Morton Senior Technical Consultant IT Training Solutions DAT313.
Chapter 9: Creating Database Conventions & Standards MCITP Administrator: Microsoft SQL Server 2005 Database Server Infrastructure Design Study Guide (70-443)
Module 8: Server Management. Overview Server-level and instance-level resources such as memory and processes Database-level resources such as logical.
Irwin/McGraw-Hill Copyright © 2000 The McGraw-Hill Companies. All Rights reserved Whitten Bentley DittmanSYSTEMS ANALYSIS AND DESIGN METHODS5th Edition.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Database Performance Tuning and Query Optimization.
IT The Relational DBMS Section 06. Relational Database Theory Physical Database Design.
An Investigation of Oracle and SQL Server with respect to Integrity, and SQL Language standards Presented by: Paul Tarwireyi Supervisor: John Ebden Date:
Physical Database Design & Performance. Optimizing for Query Performance For DBs with high retrieval traffic as compared to maintenance traffic, optimizing.
Ashwani Roy Understanding Graphical Execution Plans Level 200.
1 CS 430 Database Theory Winter 2005 Lecture 16: Inside a DBMS.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
By Shanna Epstein IS 257 September 16, Cnet.com Provides information, tools, and advice to help customers decide what to buy and how to get the.
Indexes / Session 2/ 1 of 36 Session 2 Module 3: Types of Indexes Module 4: Maintaining Indexes.
IT System Administration Lesson 3 Dr Jeffrey A Robinson.
Session 1 Module 1: Introduction to Data Integrity
Database Systems, 8 th Edition SQL Performance Tuning Evaluated from client perspective –Most current relational DBMSs perform automatic query optimization.
How to kill SQL Server Performance Håkan Winther.
SQL Basics Review Reviewing what we’ve learned so far…….

Configuring SQL Server for a successful SharePoint Server Deployment Haaron Gonzalez Solution Architect & Consultant Microsoft MVP SharePoint Server
3 Copyright © 2006, Oracle. All rights reserved. Designing and Developing for Performance.
Doing fast! Optimizing Query performance with ColumnStore Indexes in SQL Server 2012 Margarita Naumova | SQL Master Academy.
Data Integrity & Indexes / Session 1/ 1 of 37 Session 1 Module 1: Introduction to Data Integrity Module 2: Introduction to Indexes.
SQL IMPLEMENTATION & ADMINISTRATION Indexing & Views.
N5 Databases Notes Information Systems Design & Development: Structures and links.
With Temporal Tables and More
Practical Database Design and Tuning
Table General Guidelines for Better System Performance
Jonathan Walpole Computer Science Portland State University
Tuning Transact-SQL Queries
Module 11: File Structure
Indexes By Adrienne Watt.
Top 50 SQL Interview Questions & Answers
CS 540 Database Management Systems
The Basics of Data Manipulation
Lecture 16: Data Storage Wednesday, November 6, 2006.
UFC #1433 In-Memory tables 2014 vs 2016
Database Performance Tuning &
Parameter Sniffing in SQL Server Stored Procedures
100% Exam Passing Guarantee & Money Back Assurance
Presented by: Warren Sifre
Database Performance Tuning and Query Optimization
SQL Server May Let You Do It, But it Doesn’t Mean You Should
Marcos Freccia Stop everything! Top T-SQL tricks to a developer
DATABASE MANAGEMENT SYSTEM
Teaching slides Chapter 8.
Physical Database Design
Module 11: Data Storage Structure
The Basics of Data Manipulation
Practical Database Design and Tuning
Transactions, Locking and Query Optimisation
Microsoft SQL Server 2014 for Oracle DBAs Module 7
Table General Guidelines for Better System Performance
Manipulating Data.
Indexing For Optimal Performance
Contents Preface I Introduction Lesson Objectives I-2
Relational Database Design
Chapter 8 Advanced SQL.
Chapter 11 Database Performance Tuning and Query Optimization
Query Tuning Fundamentals
Chapter 11 Managing Databases with SQL Server 2000
SQL Server Query Design and Optimization Recommendations
Sourav Mukherjee Are you following SQL Server Development Best Practices? March 30, 2019 Cincinnati.
Manipulating Data Lesson 3.
INTRODUCTION A Database system is basically a computer based record keeping system. The collection of data, usually referred to as the database, contains.
Presentation transcript:

Are you following SQL Server Development Best Practices? Sourav Mukherjee Are you following SQL Server Development Best Practices?

Microsoft Certified Trainer since 2017 More than 12 years experience Microsoft SQL Server and AWS cloud Pursuing PhD Distributed Database Technologies MCDBA MCTS MCSE PMP ITIL AWS Solution Architect

Structured Query Language Is SQL Server a Structured Query Language? Standard query language for requesting information from database using insert/update/delete and select statement. Follows ANSI standards. Set based approach. Remember! Not a procedural approach. What is Set based approach? Optimizer generates an execution plan first. Execution engine executes the plan to retrieve the data from physical storage Processes the output in an efficient manner. What is Procedural approach? We query the database to obtain the result set. We write data operational and manipulation logic using loops, conditions and processing statements to produce the final results. Same, as like Cursor!

Moving on.

Queries and Stored Proc SQL Server Edition DB Design DB Config Settings Data Modeling Perf Tests Purging Database Objects Index Transact-SQL Version Control Queries and Stored Proc Process Improve Consult

SQL Server Edition 1 GB Max SQL Server Memory used by DB Engine 10 GB Max size of each relational database No SQL Agent Buffer Cache limit for each instance 1 MB of RAM Relational DB engine is restricted to lesser of 1 socket/4 cores. Developers use Developer Edition. Not SQL Express because of limitations.

Database Design Maintain Referential Integrity at all the times. Primary Key  Foreign Key Choose the narrowest size of the columns you can. Choose the smallest and required Data type. Remember Varchar is not Nvarchar. Nvarchar uses 2 bytes / character and Varchar uses 1 byte Varchar stores ASCII Data Nvarchar stores UNICODE Data.

Database Configuration Settings Create appropriate Database File Sizes Initial DB size Equal data file sizes under the database. Filegroups use a proportional fill strategy. Appropriate database db file growth value (use in MB, avoid %). Such as 64 MB and in its multiple. BEST OPTION: Increase DB file appropriately so that SQL Engine will not busy allocating size. Maintain the same configuration across different environment.

Performance/Load Tests Before you start Performance Load tests, adjust DB File sizes which we discussed earlier. Suspend the maintenance job during the period (such as Rebuild Index)

Moving on.

Index Use appropriate Naming Convention to avoid creating duplicate indexes. Use appropriate column sequence/Precedence while you create Indexes. DO NOT Create duplicate index. It hurts performance. Identify Missing, unused indexes. Create and discard as needed. Test thoroughly in Non Prod before taking to PROD. Put heavily accessed tables and the non-clustered indexes that belong to those tables on different filegroups. This Improves Performance! Keep the “width” of the indexes as narrow as possible. This reduces the size of the index, reduces I/O reads and also index maintenance. Avoid adding Clustered Indexes to a GUID column. It takes 16-bytes storage!! More than an Identity column. Makes it very larger, increases I/O reads, hurts performance. Prefer creating unique index over Non-Unique Index. SQL Server can often search through unique index faster than the other.

Data Purging/Cleanup Remove old data from your tables if the application does not need to display old records such as older than 90 days or 120 days. Create appropriate strategy to write your own script to cleanup the records from tables. Identify the base table and delete the records from other child tables using the primary key. Use Primary key as the cleanup condition. Use Temp table over Table Variables Before you initiate cleanup ensure you have correct indexes, if not create accordingly based on delete condition column. If needed create appropriate Non Clustered Index on temp table. Think of Table Partition as one other Best Practice.

Database Objects Use user-defined constraint names, rather using system-generated names. This is a standard naming convention that is used in the master database. If you do not specify the database where the object is, SQL Server will first search the master database to see if the object exists there and then it will search the user database. While creating your own procedure make it start using “Usp_” rather using “sp_” User objects to go to its respective filegroups. Do not create user objects and data to sit in the system/primary filegroup. All system tables are allocated to primary filegroup.

Transact-SQL Regular join statements in two/more tables in your query will be performed faster using proper indexes are present. Do not over-index your OLTP tables. Use appropriate Begin Tran .. Commit/ Rollback Tran inside the code block. Use TRY..Catch blocks. Find the key columns which really required to be encrypted. Do not Overdo! Create Non-Clustered covering index on frequently performing same queries. Choose correct fill factor. Page Split hurts the performance!

Version/Source Control Maintain all code in a source control system. Update the source control always for all type of changes done in the code.

Queries/Stored Procedures Keep smaller transaction. Avoid using *. Instead choose the right columns. Avoid using the query hint when you are not exactly sure. Use SET NOCOUNT ON/OFF Do not use unnecessary SELECT statement in the CODE. Carefully choose UNION, UNION all and Distinct clauses Avoid using RTRIM() and LTRIM(). Instead correct the data. Avoid unnecessary use of DISTINCT operator. Use WHERE Clause always. Design your system to fetch records using TOP operator. Avoid accidental SELECT * Remove temporary tables from database after the operation. Those consume space, increase maint time. Carefully choose special characters. If not, may change execution plan and lead to bad performance. Parameter Sniffing! Avoid SQL Server to do Implicit type conversion. Instead use correct data types.

Process Improvement Document common mistakes in the lessoned learned page or in your best practice guidelines. Do review the upcoming SQL Server editions and change your scripts accordingly.

It can be both Internal and External Consultation It can be both Internal and External Check with your in-house developers, DBAs for any advice related to Microsoft SQL Server Best Practices they are following. Seek training Request to procure third party vendor tools may be RedGate, SQLSentry, Foglight, Solarwinds, Idera or any other products and check if by using the tools and the recommendation helping you by anyway. Use Trial Version to assess the benefits.

Questions Thank you so much for your time!