Posts Tagged ‘SQL Server’

Easy win – index candidates on SQL Server 2005

Monday, December 1st, 2008

Below is my real life story telling how easy it can be to find index candidates if you use your tools.

This weekend we deployed a new version of a medium/large solution to the production environment for one of our customers. Normally this is not a big issue, as we are always prepared to roll back to the previous version – the one currently in production. The deployment and configuration processes are well-prepared and highly automated to minimize faults and late-night-bug-hunting-frenzy.

After the deployment is complete we smoke test the setup to make sure that it is configured correctly and all is sound.

This weekend after the successful deployment the smoke test failed miserably. We received TimeOutExceptions all over. It was coming from the user repository service.

We decided to investigate a little before the decision of aborting the deployment of the new version and therefore rolling back to the previous version.

The steps to resolve the issue is what I want to share with you.

A quick look in the source repository showed that almost no changes to the user repository service – none that could cause TimeOutExceptions.

With the SQL Server Profiler it was easy to spot the cause of the exception.

This simple select statement was isolated and copied into the Management Studio to view the Actual Execution Plan. The execution plan did show much, but by execution the below statement which instructs the SQL Server not to execute the Transact-SQL  statements. Instead, SQL Server returns detailed information about how the statements are going to be executed in the form of a well-defined XML document.

SET SHOWPLAN_XML ON

The SQL Server will include loads in information and one of these are suggested indexes which you will not see with the graphical execution plan in Management Studio. Look for the MissingIndex elements:

<missingindexes>
  <missingindexgroup Impact="96.6222">
    <missingindex Database="[DOIPEI]" Schema="[dbo]" Table="[OrganisationalUnit_Stack]">
      <columngroup Usage="EQUALITY">
        <column Name="[org_pkid]" ColumnId="2" />
      </columngroup>
    </missingindex>
  </missingindexgroup>
</missingindexes>

By creating this single index on [DOIPEI].[dbo]. [OrganisationalUnit_Stack]. [org_pkid] the TimeOutExceptions disappeared, as the query no longer took minutes but milliseconds.

We were able to continue and successfully deploy the new version of the solution with only minimal disruption and a delay of only half an hour. Why the index where missing is still a mystery.

It makes all the difference in the world if you know the capabilities of your tools at hand.

SQL Server 2008 Microsoft ISV Partner events presentations

Saturday, November 15th, 2008

This week I hosted two sessions at two different events for Microsoft Denmark. One at Radisson SAS Scandinavia Hotel in Århus and one in Microsoft Denmark’s headquarter in Hellerup.

It was fun at the feedback was very positive. The best part was during the breaks with great edifying technical discussions. All the slides are available at Miracle’s homepage.

Disable and enable all database constraints

Thursday, August 21st, 2008

We (my colleagues at Miracle and I) are currently in the process of upgrading a customer’s solutions. One of task is migrating 100 gigs of data into an existing database schema. This can easily become a tedious task and can take considerable calendar time. Therefore we decided to disable all constraints on the database, move the data and then enable them again, as we know the data integrity is sound.
We could have written a script that gets all the constraints in the database and generates a SQL script, but there is an easier way…

-- Disable all Constraints
exec sp_MSforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'

--Enable all Constraints
exec sp_MSforeachtable 'ALTER TABLE ? CHECK CONSTRAINT ALL'

That’s easy… :-P

I found this on the Internet somewhere – the sp_MSforeachtable procedure is nowhere to be found in books online.
You can check if foreign keys and check constrains are disabled via the sys.foreign_keys  and sys.check_constraints views.

Another obvious triviality in our situation is disabling and enabling triggers – that is easy too:

-- Disable all Triggers
exec sp_MSforeachtable 'ALTER TABLE ? DISABLE TRIGGER ALL'

-- Enable all Triggers
exec sp_MSforeachtable 'ALTER TABLE ? ENABLE TRIGGER ALL'

Great conference

Wednesday, March 14th, 2007

The Miracle SQL Server Open World conference was a great success. There were lots of informative sessions and great networking. I spoke to a lot of interesting people from all over the world including Microsoft SQL Server guys from Redmond and one as far away as from Brisbane, Australia. Bear in mind that this conference is held in the countryside, far away from anything, two hours drive from Copenhagen, Denmark.

I promised the attendances’ at my session “Transactions with Windows Communication Foundation” to post a guide to setup the Distributed Transaction Coordinator (DTC) for WCF. I have posted two guides:

Hope to see all of these interesting people again at next year’s Miracle SQL Server Open World conference.

SQL Server Open World

Wednesday, February 21st, 2007


I’ll attend the Miracle SQL Server Open World conference from March 8-10, 2007 where I will speak about Windows Communication Foundation (WCF) and .Net Garbage Collection on the business intelligence & .Net development track.

Smart guys like Mark Souza, Lubor Kollar, Poul Randall from Microsoft and Kimberly Tripp will be there – will you?