SQL SERVER – 15 Best Practices for Better Database Performance

This blog post will discuss 15 best practices for improving database performance. I have listed 14 best practices below. Read through them and let me know what you think should be the 15th best practice.

SQL SERVER - 15 Best Practices for Better Database Performance bestpractices-800x799

  1. Store only relevant and necessary data in the database
    Avoid storing data in application structures or arrays when it belongs in the database.
  2. Use normalized tables
    Normalize your database to eliminate redundancy and maintain data integrity. Smaller, related tables are often better than one large table.
  3. Create lookup tables for enumerated fields
    For enumerated fields, use lookup tables to enforce consistency and maintain database integrity.
  4. Use small and efficient primary keys
    Choose short primary keys, such as integers or small character fields, to optimize performance.
  5. Store image paths or URLs instead of images
    Save image paths or URLs in the database and store the images in file storage to reduce overhead.
  6. Select appropriate data types
    Use precise data types for fields, such as DATETIME for date fields instead of VARCHAR(20).
  7. **Avoid SELECT ***
    Specify column names in SELECT statements to improve performance and readability.
  8. Use LIKE clauses sparingly
    When an exact match is required, use the = operator instead of LIKE for better efficiency.
  9. Write SQL keywords in uppercase
    Using uppercase for keywords such as SELECT, WHERE, and JOIN enhances code readability.
  10. Prefer JOINs over subqueries
    Use JOIN instead of subqueries or nested queries for improved performance and clarity.
  11. Utilize stored procedures
    Stored procedures improve execution speed, simplify maintenance, and enhance security.
  12. Comment and document your code
    Add comments to your SQL scripts for clarity and as a guide for future developers. Proper application documentation is equally important.
  13. Use proper indexing
    Create and maintain indexes to improve query performance, keeping in mind the trade-off with write operations.
  14. Test all changes thoroughly
    Test any database programming or administrative changes in a non-production environment before deployment.
  15. Monitor and optimize query performance
    Use tools like SQL Server Profiler or Query Store to identify and optimize slow-performing queries. Regularly review execution plans to ensure efficient operations.

These practices will help you design, maintain, and optimize databases and for database performance and long-term reliability. Let me know your thoughts or if you have additional tips to share!

Reference: Pinal Dave (https://blog.sqlauthority.com)

Best Practices, SQL Server
Previous Post
SQL SERVER – 2005 – Transferring Ownership of a Schema to a User
Next Post
SQL SERVER – 2005 – Restore Database Using Corrupt Datafiles (.mdf and .ldf)

Related Posts

108 Comments. Leave new

  • Chris Beardsley
    December 9, 2017 4:46 am

    15) avoid concatenating multiple fields into a primary key. There are edge case exceptions, but avoid as much as possible.

    Reply
  • #15 . follow proper naming standard for better design and readability

    Reply
  • I have noticed a significant performance gain using a correlated subquery instead of an OUTER JOIN, such as:
    SELECT C.CustomerName,
    (SELECT City FROM Address WHERE Address.Entity_ID = C.Customer_ID) AS City
    FROM Customer AS C

    Rather than:
    SELECT C.CustomerName, A.City
    FROM Customer AS C
    LEFT OUTER JOIN Address AS A
    ON C.Customer_ID = A.Entity_ID

    If multiple fields are required from Address, perhaps try OUTER APPLY.

    Reply
  • Esteban Flores
    April 17, 2018 10:59 pm

    Leave us to be free to design (after the respective analysis correct) ourselves the database without impositions of chiefs or project leaders.

    Reply
  • Keep enough free space in the server, user databases and tempdb. Drop unwanted indexes in the server

    Reply
  • Luca Astolfi
    July 31, 2018 3:24 pm

    !5.1 Create a dedicated database for each application that coexists in the same Server
    !5.2 Chose properly the Collation for database

    Reply
  • Reindex and shrink the database periodically for better performance

    Reply
  • Ashok Chitimilla
    December 10, 2018 2:16 am

    Do not prefix your stored procedure names with “sp_”. The prefix sp_ is reserved for system stored procedure that ship with SQL Server. Whenever SQL Server encounters a procedure name starting with sp_, it first tries to locate the procedure in the master database, then it looks for any qualifiers (database, owner) provided, then it tries dbo as the owner.

    Reply

Leave a Reply