Sometimes, all a DBA needs, to help with day-to-day work, is a checklist of best-practices and dos and don'ts. It provides a handy reminder.
- General DBA Best Practices
- High Availability Best Practices
- Performance Tuning Best Practices
- Application Design and Coding Best Practices
- SQL Server Component Best Practices
General DBA Best Practices
- Check OS Event Logs and SQL Server Logs for unusual events.
- Verify that all scheduled jobs have run successfully.
- Confirm that backups have been made and successfully saved to a secure location.
- Monitor disk space to ensure your SQL Servers won’t run out of disk space. For best performance, all disks should have 15% or more of free space.
- Throughout the day, periodically monitor performance using both System Monitor and Profiler/SQL Trace.
- Regularly monitor and identify blocking issues.
- Keep a log of any changes you make to servers, including documentation of any performance issues you identify and correct.
- Create SQL Server alerts to notify you of potential problems, and have them e-mailed to you. Take action as needed.
- Regularly restore backups to a test server in order to verify that you can restore them. You don’t need to restore all backups every day, but do so often to ensure that you are confident you have good backups.
- Take some time to learn something new as a DBA to further your professional development.
- Always fully document installs so that your SQL Server instances can easily be reproduced in an emergency.
- If possible, install and configure all of your SQL Server instances consistently, following an agreed-upon organization standard.
- Don’t install SQL Server services on instances that don’t use them, such as Microsoft Full-Text Indexing, Reporting Services, or Analysis Services.
- For best performance of SQL Server running under Windows, turn off any operating system services that aren’t needed.
- For optimum SQL Server performance, you want to dedicate your physical servers to only running a single instance of SQL Server, along with no other applications.
- For best I/O performance, locate the database files (.mdf) and log files (.ldf) on separate spindles to isolate disk access patterns.
- If tempdb will be used heavily, put it on its own separate spindles.
- Do not install SQL Server on a domain controller.
- Be sure that SQL Server is installed on an NTFS partition.
- Don’t use NTFS data file encryption (EFS) and compression on SQL Server database and log files.
- Run the SQL Server Upgrade Advisor before upgrading. Make any necessary changes before performing the upgrade.
- Perform a test upgrade of your test SQL Servers before you upgrade your production servers. And don’t forget to test your applications with the new version also.
- Before you upgrade, be sure you have a plan in place to fall back to in case the upgrade is problematic.
- Don’t upgrade SQL Server clusters in place. Instead, rebuild them on new hardware.
- If you upgrade from a previous version of SQL Server, you should update all of the statistics in all your databases. This is because statistics are not automatically updated during the upgrade process.
- Ensure the physical security of each SQL Server, preventing any unauthorized users from physically access your servers.
- Only install required network libraries and network protocols on your SQL Server instances.
- Minimize the number of sysadmins allowed to access SQL Server.
- As a DBA, log on with sysadmin privileges only when needed. Create separate accounts for DBAs to access SQL Server when sysadmin privileges are not needed.
- Assign the SA account a very obscure password, and never use it to log onto SQL Server. Instead, use a Windows Authentication account to access SQL Server as a sysadmin.
- Give users the least amount of permissions they need to perform their job.
- Use stored procedures or views to allow users to access data instead of letting them directly access tables.
- When possible, use Windows Authentication logins instead of SQL Server logins.
- Use strong passwords for all SQL Server login accounts.
- Don’t grant permissions to the public database role.
- Remove user login IDs who no longer need access to SQL Server.
- Disable the guest user account from each user database by using REVOKE CONNECT FROM GUEST.
- Don’t use cross database ownership chaining if not required.
- Never grant permission to the xp_cmdshell to non-sysadmins.
- Remove sample databases from all production SQL Server instances.
- Use Windows Global Groups, or SQL Server Roles to manage groups of users that need similar permissions.
- Avoid creating network shares on any SQL Server.
- Configure login auditing so you can see who has succeeded, and failed, to login.
- Don’t use the SA account, or login IDs who are members of the sysadmin group, as accounts used to access SQL Server from applications.
- Ensure that your SQL Servers are behind a firewall and are not exposed directly to the Internet.
- In SQL Server 2005 and earlier, remove the BUILTIN/Administrators group to prevent local server administrators from being able to access SQL Server. In SQL Server 2008, the BUILTIN/Administrators group does not exist by default.
- Run each separate SQL Server service under a different Windows domain account.
- Only give SQL Server service accounts the minimum rights and permissions needed to run the service. In most cases, local administrator rights are not required, and domain administrator rights are never needed.
- When using distributed queries, use linked servers instead of remote servers. Remote servers only exist for backward compatibility.
- Do not browse the web from a production SQL Server instance.
- Instead of installing virus/antispyware protection on a SQL Server, perform scans from a remote server during a part of the day when user activity is less.
- Add operating system and SQL Server service packs and hot fixes soon after they are released and tested, as they often include security enhancements.
- Encrypt all SQL Server backups with a third-party backup tool, such as Red Gate SQL Backup Pro.
- Only enable C2 auditing or Common Criteria compliance if required, as they add significant performance overhead.
- Consider running a SQL Server security scanner against your SQL servers to identify security holes.
- Consider enabling SSL or IPSEC for connections between SQL Server and its clients.
- If using SQL Server 2005/2008, enable password policy checking.
- If using SQL Server 2008 in a high security environment, consider implementing Transparent Data Encryption to protect confidential data.
- If using SQL Server 2005, don’t use the SQL Server Surface Area Configuration tool to unlock features you don’t absolutely need.
- If using SQL Server 2005/2008 and you create endpoints, only grant CONNECT permissions to the logins that need access to them. Explicitly deny CONNECT permissions to endpoints that are not needed by users.
- Avoid overlapping jobs on the same SQL Server instance. Ideally, each job should run separately at different times.
- When creating jobs, be sure to include error trapping, log job activity, and set up alerts so you know instantly when a job fails.
- Create a special SQL Server login account whose sole purpose is to run jobs, and assign it to all jobs.
- If your jobs include Transact-SQL code, ensure that it is optimized to run efficiently.
- Periodically (daily, weekly, or monthly), rebuild or reorganize the indexes of your databases to remove logical fragmentation and wasted space.
- Periodically, as part of your scheduled database maintenance tasks, run DBCC CHECKDB on all your databases to verify database integrity.
- Avoid running most DBCC commands during busy times of the day. These commands are often I/O intensive and can reduce performance of the SQL Server, negatively affecting users.
- If you rarely restart the SQL Server service, you may find that the current SQL Server log gets very large and takes a long time to load and view. You can close the current error log and create a new one by running sp_cycle_errorlog or DBCC ERRORLOG, so that the log doesn’t get overly large. Set this up as a weekly job.
- Script all jobs and store these scripts in a secure area so they can be used if you need to rebuild the servers.
SQL Server Configuration Settings
- SQL Server configuration settings should remain at their default settings. Any changes to these settings should only be made by an experienced DBA who understands the pros and cons of making changes.
- If you are using the 32-bit version of SQL Server, and if you are using 4 GB or more of RAM, ensure that you have all the AWE settings correctly set.
- In most cases, the settings for the “maximum server memory” and the “minimum server memory” should be left to their default values. This is because the default values allow SQL Server to dynamically allocate memory in the server for the best overall optimum performance. Exceptions to this rule of thumb can come into play if you use 32-bit AWE memory, or 64-bit memory, where you may have to change the “maximum server memory” to an amount that is less than the physical amount of RAM in your server.
- Leave the “auto create statistics” and “auto update statistics” options on for all user databases. Only in very rare cases should these be turned off, and if they are turned off, then you must manually update the statistics yourself.
- Don’t be tempted to use the “auto shrink” database option, as it can waste SQL Server resources unnecessarily and contribute to index fragmentation. Instead, if you need to shrink a database, do so manually.
- Don’t rely on AUTOGROWTH to automatically manage the size of your databases. Instead, proactively monitor and alter database size as circumstances dictate. Only use AUTOGROWTH to deal with unexpected growth.
- Replication needs should be clearly defined before creating a replication topology. Successful replication can be difficult and requires much pre-planning.
- Ideally, publishers, distributors, and subscribers should be on separate physical hardware.
- Create, document, and test a backup and restore strategy. Restoring replicated databases can be complex and requires much planning and practice.
- Script the replication topology as part of your disaster recovery plan so you can easily recreate your replication topology if needed.
- Use default replication settings, unless you can ensure that a non-default setting will actually improve replication performance or other issues. Be sure that you test all changes to ensure that they are as effective as you expect.
- Fully understand the implications of adding or dropping articles, changing publication properties, and changing schema on published databases, before making any of these changes.
- Periodically, validate data between publishers and subscribers.
- Regularly monitor replication processes and jobs to ensure they are working.
- Regularly monitor replication performance, and performance tune as necessary.
- Add alerts to all replication jobs so you are notified of any job failures.
High Availability Best Practices
General High Availability
- Physically protect your SQL Servers from unauthorized users.
- Physically document all of your SQL Server instances. Incorporate effective change management.
- Always use a RAID-enabled direct attached storage array, or SAN, for storing your data.
- Use SQL Server clustering, database mirroring, or log shipping to provide extra fault tolerance.
- Replication is not an effective means to protect your data from a high availability standpoint.
- Ensure that your entire IT infrastructure is redundant. It is only as strong as its weakest link.
- Always use server-class hardware, and standardize on the same hardware as much as possible.
- Use hardware and software monitoring tools so you can quickly become aware of when problems first arise.
- After thorough testing, apply all new service packs and hot fixes to the OS and SQL Server.
- Cross-train staff so that there are multiple people who are able to deal with virtually any problem or issue.
- You must create a disaster recovery plan and include every detail you will need to rebuild your servers.
- As your SQL Servers change over time, don’t forget to update your disaster recovery plan.
- Write the disaster recovery plan so that any computer literate person will be able to read and follow it. Do not assume a DBA will be rebuilding the servers.
- Fully test your disaster recovery plan at least once a year.
- Review all the best practices you know and implement them as appropriate. Remember, as DBAs, we are guardians of the organization’s data. This is a huge responsibility.
- All OLTP production databases should be set to use the full recovery model. This way, you can create transaction log backups on a periodic basis.
- Whenever possible, perform a daily full backup of all system and user databases.
- For all OLTP production databases, perform regular transaction log backups, at least once an hour.
- Perform full backups during periods of low user activity in order to minimize the impact of backups on users.
- Periodically perform test backup restores to ensure that your backups are good and can be restored.
- Encrypt your backups in case they should become “lost.”
- Store backups offsite and in a secure location.
- If using SQL Server encryption, be sure to back up the appropriate service master keys, database master keys, and certificates.
- If you find that backup times take longer than your backup window, or if backup file sizes are taking up too much space on your storage device, consider a third-party backup program, such as Red Gate SQL Backup Pro.
- Document, step-by-step, the process to restore system and user databases onto the same, or a different server. You don’t want to be looking this information up during an emergency.
- Detailed planning is critical to the success of every SQL Server cluster installation. Fully plan the install before performing the actual install.
- An expensive cluster is of little value if the supporting infrastructure is not also fault tolerant. For example, don’t forget power redundancy, network redundancy, etc.
- Run only a single instance of SQL Server per node. Whether you have two or eight nodes in your cluster, leave at least one node as a failover node.
- Cluster nodes must not be domain controllers, and all nodes must belong in the same domain and should have access to two or more domain controllers.
- All cluster hardware must be on the Microsoft Windows Clustering Hardware Compatibility List, and certified to work together as part of a cluster.
- Since clustering is not designed to protect data (only SQL Server instances), the shared storage device used by the cluster must incorporate fault tolerant technology. Consider log shipping, database mirroring, or SAN replication to further protect your production databases.
- Before installing Windows Clustering and SQL Server Clustering, be sure that all drivers and software are up-to-date, including the latest service packs or hot fixes.
- Each node of a cluster should have identical hardware, drivers, software, and configuration settings.
- Fiber channel shared arrays are preferred over SCSI when building a cluster, and Fiber channel has to be used if you include more than two nodes in your cluster.
- In conventional clusters, the quorum drive must be on its own fault-tolerant, dedicated, disk of 500MB or larger
- Once the cluster has been installed, test it thoroughly for every possible failure scenario.
- Do not run antivirus or antispyware on a SQL Server cluster.
- Before you begin to install Cluster Services or SQL Server clustering, determine your virtual names and gather your IP addresses ahead of time. This makes it easier when it is time to enter this information when installing and configuring your cluster.
- Monitor active production clusters on a daily basis, looking for any potential problems. Periodically test failover on production servers to ensure all is working well.
- Once you have a stable SQL Server Cluster running, be very leery about making any changes to it, whatsoever.
SQL Server 2005/2008 Mirroring
- The principal database and the mirror database should be on separate physical hardware, and ideally, in different physical locations.
- The witness server should be on separate physical hardware, and be on a separate network (best if at a third location).
- Initial database mirroring setup should be done during less busy times, as the setup process can negatively affect performance of the production database being mirrored.
- Use high availability mode whenever possible, and high performance mode only when required.
- For ease of administration, the hardware, along with the OS and SQL Server configuration, should be identical (at least very similar) between the two servers.
- While a fast connection is not required between mirrored servers, the faster the connection, and the better quality the connection, the better.
- You will want to optimize the performance of the mirrored database as much as possible to reduce the overhead caused by the mirroring process itself.
- Thoroughly test database mirroring before putting it into production.
- Monitor database mirroring daily to ensure that it is working properly, and is meeting performance goals.
- Develop a formal operational and recovery procedure (and document) to support mirroring. Periodically test the failover process to ensure that it works.
- If you don’t currently employ clustering or database mirroring for your SQL Servers because of cost, consider employing log shipping to help boost your high availability. It provides reasonably high availability at low cost.
- If you take advantage of SQL Server log shipping capability, you will want to keep the log shipping monitoring service on a SQL Server of its own, not on the source or destination servers participating in log shipping. Not only is this important for fault tolerance, but because the log shipping monitoring service incurs overhead that can affect the performance of the source and destination servers.
- Monitor log shipping daily to ensure that is working successfully.
- Learn what you need to know to fix log shipping if synchronization is lost between the production and backup databases.
- Document, and test your server recovery plan, so you will be ready in case of a server failure.
Performance Tuning Best Practices
- Regularly monitor system performance using System Monitor or similar tool.
- Regularly monitor system performance using Performance Monitor. Use Performance Monitor for both real-time analysis and for historical/baseline analysis.
- If running SQL Server 2005, SP2 or later, install the free SQL Server Performance Dashboard. It can be used for real-time monitoring and performance troubleshooting. If you are using SQL Server 2008, consider using the Performance Data Collector.
- Regularly monitor SQL Server activity using SQL Trace or Profiler. Be sure that traces are taken during times of the day that are representative of the typical activity that is going on in each server. When running the SQL Trace or Profiler, do not collect more data than you need to collect, in order to reduce the overhead of performing the trace.
- Perform performance monitoring from a computer that is not the SQL Server you are monitoring. Run monitoring tools on a separate desktop or server.
Hardware Performance Tuning
- Although heavy-duty hardware can help SQL Server’s performance, application and database design can play a greater part in overall performance than hardware. Keep this in mind, as throwing good money after bad on server hardware does not always fix SQL Server performance problems. Before getting faster hardware, be sure you have thoroughly tuned your applications, Transact-SQL, and database indexing.
- In many cases, adding RAM to a server is the cheapest and fastest way to boost hardware performance of a SQL Server. But before adding more RAM to a SQL Server, ensure first that it will be used by SQL Server. Adding more RAM doesn’t mean that SQL Server will always use it. If the current Buffer Hit Cache Ratio is consistently above 99% and you have well more than 100 MB of Available RAM, your server may not benefit from adding additional RAM.
- If your SQL Server’s total CPU utilization is consistently above 80% or more, you need more CPUs, faster CPUs, or you need to find a way to reduce the load on the current server.
- If the Logical Disk: % Idle Time counter is less than 50%; and the Logical Disk: Avg. Disk Sec/Read counter or the Logical Disk: Avg. Disk Sec/Write counter is more than 15ms, then you most likely are experiencing a disk I/O performance issue and need to start looking for solutions.
- Don’t run any applications on your server other than SQL Server, with the exception of necessary utilities.
- NTFS-formatted partitions should not exceed 85% of their capacity. For example, if you have a 100GB drive, it should never be fuller than 85GB. Why? NTFS needs room to work, and when you exceed 85% capacity, NTFS becomes less efficient and I/O can suffer for it. In addition, disk file fragmentation utilities need at least 15% of free disk space to work properly.
- If your SQL Server database experiences mostly reads, then a RAID 5 array offers good protection and adequate performance. If your SQL Server database is mostly writes, then use a RAID 10 array for best protection and performance.
- If your SQL Server’s tempdb database is heavily used, consider locating it on an array of its own spindles (such as RAID 1 or RAID 10). This will allow disk I/O to be more evenly distributed for the SQL Server instance, reducing disk I/O contention issues, and speeding up SQL Server’s overall performance.
- The more spindles you have in an array, the faster disk I/O will be. Be sure the disk controllers can handle the extra I/O provided by adding more spindles.
- Ensure that all hardware is running the latest, approved drivers.
- Periodically, run the Database Engine Tuning Advisor against current Profiler traces to identify potentially missing indexes.
- Remove indexes that are never used.
- Don’t accidentally create redundant indexes.
- As a rule of thumb, every table should have at least a clustered index. Generally, but not always, the clustered index should be on a column that monotonically increases – such as an identity column, or some other column where the value is increasing – and is unique. In many cases, the primary key is the ideal column for a clustered index.
- Since you can only create one clustered index per table, take extra time to carefully consider how it will be used. Consider the type of queries that will be used against the table, and make an educated guess as to which query (the most common one run against the table, perhaps) is the most critical, and if this query will benefit most from having a clustered index.
- When creating a composite index, and when all other considerations are equal, make the most selective column the first column of the index.
- Generally speaking, keep the “width” of your indexes as narrow as possible. This reduces the size of the index and reduces the number of disk I/O reads required to read the index, boosting performance.
- Avoid adding a clustered index to a GUID column (uniqueidentifier data type). GUIDs take up 16-bytes of storage, more than an Identify column, which makes the index larger, which increases I/O reads, which can hurt performance.
- Indexes should be considered on all columns that are frequently accessed by the JOIN, WHERE, ORDER BY, GROUP BY, TOP, and DISTINCT clauses.
- Don’t automatically add indexes on a table because it seems like the right thing to do. Only add indexes if you know that they will be used by queries run against the table.
- When creating indexes, try to make them unique indexes if at all possible. SQL Server can often search through a unique index faster than a non-unique index because in a unique index, each row is unique, and once the needed record is found, SQL Server doesn’t have to look any further.
- If you perform regular joins between two or more tables in your queries, performance will be optimized if each of the joined columns have appropriate indexes.
- Don’t automatically accept the default value of 100 for the fill factor for your indexes. It may or may not best meet your needs. A high fill factor is good for seldom changed data, but highly modified data needs a lower fill factor to reduce page splitting.
- Don’t over index your OLTP tables, as every index you add increases the time it takes to perform INSERTS, UPDATES, and DELETES. There is a fine line between having the ideal number of indexes (for SELECTs) and the ideal number to minimize the overhead that occurs with indexes during data modifications.
- If you know that your application will be performing the same query over and over on the same table, consider creating a non-clustered covering index on the table. A covering index, which is a form of a composite index, includes all of the columns referenced in SELECT, JOIN, and WHERE clauses of a query. Because of this, the index contains the data you are looking for and SQL Server doesn’t have to look up the actual data in the table, reducing I/O, and boosting performance.
SQL Server 2008 Compression Best Practices
- SQL Server 2008, Enterprise Edtition, offers both row and column compression, which can be used to reduce the amount of space data takes up on disk and in the buffer pool, potentially boosting performance.
- Compression requires the use of additional CPU cycles to implement. Because of this, if your server currently has a CPU bottleneck, then compression should probably be avoided.
- Compression works best for tables that experience mostly reads. Tables that experience a large number of DML activities should probably not be compressed.
- Don’t use compression on tables subject to heavy inserts, such as bulk inserts.
SQL Server 2008 Data Collector Best Practices
- The SQL Server 2008 Data Collector can be used to gather, store, and analyze many different types of SQL Server performance activities.
- Using the SQL Server 2008 Data Collector imposes some performance overhead, and because of this, you may want to minimize the amount of data that is collected by it.
- While the Management Data Warehouse can exist on each instance of SQL Server, it is recommended that a dedicated SQL Server be used to store the Management Data Warehouse used to store the collected data.
Best Practices for Resource Governor
- The SQL Server 2008 Resource Governor can be used to restrict how much CPU and memory resources are allocated to a particular user connection, allowing the DBA to give resource preference to some connections over other connections.
- If you use the Resource Governor, ensure that the DAC is turned on, as it is the only way to troubleshoot and fix a bad Resource Governor configuration.
- Classifier user-defined function should be well tested and optimized. If written incorrectly, a classifier function can cause connections to slow down, time out, and even create an infinite loop that locks up SQL Server.
- Monitor Resource Governor after implementation to confirm appropriate use. If you are not careful, you can introduce query performance problems that didn’t exist before using Resource Governor. For example, if memory is limited too much, it can cause a suboptimal execution plan to be created and executed, hurting performance.
- Test your Resource Governor implementation on test system before implementing it on production
Application Design and Coding Best Practices
- Bad logical database design results in bad physical database design, and generally results in poor database performance. So, if it is your responsibility to design a database from scratch, be sure you take the necessary time and effort to get the logical database design right. Once the logical design is right, then you also need to take the time to get the physical design right.
- When designing a new database, implement consistent naming standards for all of your objects.
- Take advantage of SQL Server’s built-in referential integrity. You don’t need to write your own.
- Always specify the narrowest columns you can. In addition, always choose the smallest data type you need to hold the data you need to store in a column. The narrower the column, the less amount of data SQL Server has to store, and the faster SQL Server is able to read and write data.
- When designing a new database, fully document every table, column, default, check constraint, and relationship, so others can easily find out what they mean, or how they are to be used.
Queries and Stored Procedures
- Maintain all code in a source control system.
- Keep transactions as short as possible. This reduces locking and increases application concurrently, which helps to boost performance.
- Avoid using query hints unless you know exactly what you are doing, and you have verified that the hint actually boosts performance.
- Encapsulate all transactions within stored procedures, including both the BEGIN TRANSACTION and COMMIT TRANSACTION statements in the procedure.
- Use the least restrictive transaction isolation level possible for your user connection, instead of always using the default READ COMMITTED. Of course, don’t do anything that could compromise the integrity of your data.
- Whenever a client application needs to send Transact-SQL to SQL Server, send it in the form of a stored procedure instead of a script or embedded Transact-SQL. Stored procedures offer many benefits, including:
- Reduced network traffic and latency, boosting application performance.
- Stored procedure execution plans can be reused, staying cached in SQL Server’s memory, reducing server overhead. This is also mostly true for Transact-SQL code sent to SQL Server outside of a stored procedure.
- Client execution requests are more efficient. For example, if an application needs to INSERT a large binary value into an image data column not using a stored procedure, it must convert the binary value to a character string (which doubles its size), and send it to SQL Server. When SQL Server receives it, it then must convert the character value back to the binary format. This is a lot of wasted overhead. A stored procedure eliminates this issue as parameter values stay in the binary format all the way from the application to SQL Server, reducing overhead and boosting performance.
- Stored procedures help promote code reuse. While this does not directly boost an application’s performance, it can boost the productivity of developers by reducing the amount of code required, along with reducing debugging time.
- Stored procedures can encapsulate logic. You can change stored procedure code without affecting clients (assuming you keep the parameters the same and don’t remove any result sets columns). This saves developer time.
- Stored procedures provide better security for your data.
- SET NOCOUNT ON at the beginning of each stored procedure you write.
- Before rolling a stored procedure out into production, review it for any unused code, parameters, or variables that you may have forgotten to remove while you were creating it, and remove them.
- Don’t be afraid to make liberal use of in-line and block comments in your Transact-SQL code, they will not affect the performance of your application and they will enhance your productivity when you or others come back to the code and try to modify it.
- If possible, avoid using SQL Server cursors. They generally use a lot of SQL Server resources and reduce the performance and scalability of your applications. If you need to perform row-by-row operations, try to find another method to perform the task.
- When using the UNION statement, keep in mind that, by default, it performs the equivalent of a SELECT DISTINCT on the final result set. In other words, UNION takes the results of two like recordsets, combines them, and then performs a SELECT DISTINCT in order to eliminate any duplicate rows. This process occurs even if there are no duplicate records in the final recordset. If you know that there are duplicate records, and this presents a problem for your application, then by all means use the UNION statement to eliminate the duplicate rows.
- Carefully evaluate whether your SELECT query needs the DISTINCT clause or not. Some developers automatically add this clause to every one of their SELECT statements, even when it is not necessary.
- In your queries, don’t return column data you don’t need. For example, you should not use SELECT * to return all the columns from a table if you don’t need all the data from every column. In addition, using SELECT * may prevent the use of covering indexes, further potentially hurting query performance.
- Always include a WHERE clause in your SELECT statement to narrow the number of rows returned. Only return those rows you need.
- If your application allows users to run queries, but you are unable in your application to easily prevent users from returning hundreds, even thousands of unnecessary rows of data, consider using the TOP operator within the SELECT statement. This way, you can limit how many rows are returned, even if the user doesn’t enter any criteria to help reduce the number or rows returned to the client.
- Try to avoid WHERE clauses that are non-sargable. If a WHERE clause is sargable, this means that it can take advantage of an index (assuming one is available) to speed completion of the query. If a WHERE clause is non-sargable, this means that the WHERE clause (or at least part of it) cannot take advantage of an index, instead performing a table/index scan, which may cause the query’s performance to suffer. Non-sargable search arguments in the WHERE clause, such as “IS NULL”, “<>”, “!=”, “!>”, “!<“, “NOT”, “NOT EXISTS”, “NOT IN”, “NOT LIKE”, and “LIKE ‘%500′” generally prevents (but not always) the query optimizer from using an index to perform a search. In addition, expressions that include a function on a column, expressions that have the same column on both sides of the operator, or comparisons against a column (not a constant), are not sargable.
- If you are using the SQL Server 2008 debugger, only run it against a test database, never a production database.
SQL Server CLR
- Use the CLR to complement Transact-SQL code, not to replace it.
- Standard data access, such as SELECT, INSERTs, UPDATEs, and DELETEs are best done via Transact-SQL code, not the CLR.
- Computationally or procedurally intensive business logic can often be encapsulated as functions running in the CLR.
- Use the CLR for error handling, as it is more robust than what Transact-SQL offers.
- Use the CLR for string manipulation, as it is generally faster than using Transact-SQL.
- Use the CLR when you need to take advantage of the large base class library.
- Use the CLR when you want to access external resources, such as the file system, Event Log, a web service, or the registry.
- Set CLR code access security to the most restrictive permissions as possible.
- XML is best used for modeling data with a flexible or rich structure.
- Don’t use XML for conventional, structured data.
- Store object properties as XML data in XML data types.
- When possible, use typed XML data types over untyped XML data to boost performance.
- Add primary and secondary indexes to XML columns to speed retrieval.
SQL Server Component Best Practices
- Schedule large data imports, exports, or transformation on your production servers during less busy periods of the day to reduce the impact on your users.
- Consider running large, resource-intensive SSIS packages on a dedicated physical server.
- Rename all default name and description properties using standard naming conventions. This will make it easier for you and others to debug or modify your packages.
- Include annotations in your packages to make it easier for you, and others, to understand what is going on.
- Use Sequence Containers to organize package structures into logical work units.
- Use Namespaces for your packages.
- Only scope variables for the containers for which they are needed.
- If you know that data is already pre-sorted, set IsSorted=TRUE. Doing so can help prevent unnecessary sorts, which use up resources unnecessarily.
- When selecting columns from a table to return, return only what is needed. In addition use Transact-SQL statements in an OLE DB Source component, or the Lookup Component, instead of selecting an entire table. This way, you prevent unnecessary data from being processed.
- When INSERTing data, use the SQL Server Destination instead of the OLE DB Destination to boost performance.
- Ideally, dedicate one or more physical servers for Reporting Services.
- The SQL Server databases used to produce the raw data for reports should be on their own dedicated physical servers.
- Only return the actual data you need in the report, no more or no less.
- Optimize the performance of the Transact-SQL code you are using to return data for your report before you actually design the physical appearance of the report.
- Manage all report code and .rdl files using a source control system.
- Always run OLAP applications on their own dedicated servers, never sharing a server running OLTP applications. The two types of applications are mutually exclusive when it comes to performance tuning.
- When designing OLAP cubes, don’t include measures or dimensions that your users won’t use. The way to prevent this is good systems analysis and design. Unused data will increase the size of your cubes and slow performance.
- When using the star schema design, at a minimum, you will create a non-clustered index on the primary key of each dimension table and a non-clustered index on each of the related foreign-keys. From there, you can create non-clustered indexes on additional columns that will be queried on frequently.
- When you create indexes on your data warehouses and datamarts, use a FILLFACTOR of 100 to ensure that the index pages are as full as possible. This reduces unnecessary I/O, speeding up performance.
- Schedule cube updates on your production servers during less busy periods of the day to reduce the impact on your users.
- Planning for a Service Broker implementation requires that you answer these questions:
- Decide the role that Service Broker will play in the application.
- Identify the required information for each step of a conversation in order to complete each task.
- Select where the message processing logic will run.
- Decide on the technology to be used to implement your application
- Identify which server components will your application use the most.
- Before rolling out a Service Broker application, test it thoroughly in a test environment that closely represents your actual production environment.
- After a Service Broker application has been designed and written, it must be rolled out. This is generally done with a set of installation scripts that are ran to create the necessary message types, contracts, queues, services, and stored procedures. Ideally, the DBA will review these scripts before running them.
- Once the installation scripts are run, it is the job of the DBA to configure the necessary security principals, certificates, remote service bindings, and required routes.
- Because a Service Broker installation can be complex, it must be fully documented so that it can be easily replicated and reinstalled if necessary.
Last Updated: 2021-06-13
Leave a message
Search Current Affairs by date
Other Category List
झारखण्ड से सवाल (इतिहास, भूगोल, समाज, संस्कृति एवं विरासत) (Questions from Jharkhand (History, Geography, Society, Culture and Heritage))
मिले-जुले विभिन्न सवाल जो किसी विशेष श्रेणी में नहीं आते हैं (Different mixed questions that do not fall into any particular category)
1947 से राज्य आर्थिक विकास का इतिहास, झारखण्ड का भूगोल – जंगल, नदी, पहाड़-पर्वत, खान-खनिज आदि (History of State Economic Development since 1947, Geography of Jharkhand - Jungle, River, Mountain - Mountain, Mine - Mineral etc.)
Folk literature, dance, music, instruments, sightseeing and tribal culture of Jharkhand (झारखण्ड का लोक साहित्य, नृत्य, संगीत, वाद्य, दर्शनीय स्थल एवं आदिवासी संस्कृति)
झारखण्ड की औद्योगिक नीति, विस्थापन और पुनर्वास नीति एवं अन्य नीतियाँ (Jharkhand's Industrial Policy, Displacement and Rehabilitation Policy and other policies)
झारखण्ड के प्रमुख उद्योग का नाम और स्थान तथा औद्योगिक विकास (Name and location of major industry of Jharkhand and industrial development)
झारखण्ड में जंगल प्रबंधन एवं वन्य जीव जन्तु संरक्षण कार्य (Forest management and wildlife conservation work in Jharkhand)
झारखण्ड राज्य के पर्यावरण सम्बन्धी तथ्य, हो रहे पर्यावरण परिवर्तन एवं उसके अपशमन एवं अनुकूलन (Facts related to environment of Jharkhand state, environmental changes happening and its abatement and adaptation)