Wednesday, May 20, 2009

Creating a recycle bin for SQL Server 2005\2008

Recently while being shown around Oracle 10G (yes I said the 'O' word) I noticed that this product has a recycle bin. This recycle bin which stores only dropped tables falls under the Oracle flashback technology umbrella.

I was pretty sure I could do the same in SQL server using DDL triggers and schemas and prevent accidental drops of other objects as well. This article is the result of that challenge.

In a nutshell the SQL Server recycle bin is a combination of two schemas which act as bins (recycle bin and trash can) and a DDL trigger which determines which bin to place the dropped object (which is not dropped but renamed). A stored procedure (sp_undrop) is used to revert the object to its original name and schema.

Monday, May 4, 2009

SQL Server 2008 - Response Time Analysis using Extended Events

This tool demonstrates response time analysis at the session or statement level including waitstats using the new Extended Events infrastructure in SQL Server 2008. This tool is based on the simple principle:

Response time = service time + wait time

This tool allows you to drill down on the time spent in serving the user requests and the time spent in waiting for resources.

Download the application and documentation from http://sqlcat.codeplex.com/Wiki/View.aspx?title=ExtendedEventsWaitstats. Follow the User Guide to install and use the tool. The download also contains the source code for the project.


Tuesday, April 28, 2009

Comparison of Dates in SQL

Dealing with dates has always been a problem with SQL Server queries. Small things lead to critical errors, which are very difficult to detect. One of the common usages of dates is in 'where' clause of the query to filter out the records based on one or more datetime fields. Keeping few things in mind while writing such SQL queries will help you to write an effective query which does not miss any desired records. This article gives you an idea about writing such queries involving date comparisons.

Tuesday, April 14, 2009

Auto generate change scripts in SQL Server Management Studio (SSMS) for tables

As a part of my best practices, I always save the T-SQL scripts used for creation and modification of objects in SQL Server. When creating and modifying tables using SQL Server Management Studio designer it is easy to right click in the designer and select "Generate Change Script...", but is there a way to automatically script the creation and/or modification of tables made through of SQL Server Management Studio (SSMS) designer?  This tip shows you an option that exists within SSMS to automatically generate these scripts for all table changes when using the table designer.

Monday, April 13, 2009

Creating a merged (slipstreamed) drop containing SQL Server 2008 RTM + Service Pack 1

Today, I am going to show you how to create new source media that will slipstream the original source media and SQL Server 2008 Service Pack 1. Once you have created this drop, you can install SQL Server 2008 SP1 in a single step! These instructions are included with the Service Pack 1 release but there are some issues with the documentation that will be addressed in the next revision of the on-line documentation. There is not a lot of user interface that indicates you are slipstreaming, but there are a few clues, see at the bottom for screen shots.

Microsoft SQL Server 2008 Resource Governor primer

Managing workloads and consumption with Resource Governor

Resource Governor is a new feature and one of the most anticipated management features in SQL Server 2008. It bolsters SQL Server performance by allowing DBAs to establish resource limits and priorities on processor and memory-related workloads and resource pools. By defining resource limits on resource consumption, it is possible to prioritize multiple workloads in order to ensure consistent performance and maximize the experience of the end users and the efficiency of the applications without degradation.

It is important to realize from the start that Resource Governor will only throttle processes if SQL Server is experiencing CPU or memory pressure, and it will only throttle incoming requests. For example, a process that consumes high CPU will not be throttled, but the next process may be throttled. Resource Governor is unable to throttle high I/O consumers (processes that read and write excessively from disk) in the SQL Server 2008 release, but this is planned for a future release. 

Thursday, April 9, 2009

Collecting performance counters and using SQL Server to analyze the data

The following will explain how to select counters, how to collect data, how to load the data to SQL Server and how to query the data that has been saved.