Skip to content

SQL Saturday Redmond

Yesterday I blogged about submitting to SQL Saturday Denver, which is about 5 months away, after writing that post, I realized that I haven’t even blogged about SQL Saturday Redmond which is occurring in just over 2 weeks.

sqlSatRedmond393

SQL Saturday #393 Redmond marks just 3 years since my first time speaking at a SQL Saturday #108 in Redmond. So lets take a look back, at Feb 5th, 2012, it was my first time presenting at a SQL Saturday ever, I had discovered this cool new query tool called the Common Table Expression, and I prepared my presentation. I practiced my presentation once before Saturday, and I was ready. Did I mention, that this was also my first time every attending a PASS event, or a SQL Saturday, and I was presenting. I was in the morning time slot after the keynote, and boy was I nervous. Over the next year I presented at I few other SQL Saturdays, and finally a book publisher, Joes 2 Pros noticed my presentation and asked me if I wanted to turn it into a book. In 2012 and 2013, I turned it into a book, which was released the same day as SQL Saturday #212 Redmond, where I again was selected to present on Common Table Expressions, this time I had books to give away as a prize.

Read More »SQL Saturday Redmond

SQL Saturday Denver

This year the Denver SQL Saturday is being held on September 19th.

SqlSatDenver

I believe it has been 2 years since I attended SQL Saturday in Denver.  Since the last time I was at SQL Saturday Denver, my employment has changed. Previously I was employed as a full time employee at a local company. Now I am a freelance database consultant at my own consulting firm, Stedman Solutions, LLC. The new role gives me more freedom to decide which events I am going to attend, and SQL Saturday Denver is certainly on my list.

Read More »SQL Saturday Denver

TSQL – Change Data Capture

You have a need to keep track of all insert, update and delete actions on a table, or multiple tables. As you consider solutions, you might think about using a trigger, however triggers have their own baggage. You consider using the OUTPUT clause to log to a changes table, but then realize that the output clause cant be enforced.

Then the SQL Server feature called Change Data Capture comes into play. CDC is a SQL Server Feature that monitors the transaction log, looking for changes to specific tables, when the changes are discovered, they are then written into a Change Table that can then be queried to find out what was changed and when it was changed.

Sample Code

Lets take a look, to start with, I create a database called [DemoCDC] to use for the demo. That database contains a single table called [History] that you may recognize from the Week 3 Database Corruption Challenge. Following that are a few insert statements to just start with some data in the table.

CREATE DATABASE [DemoCDC];
GO

USE [DemoCDC]
GO

CREATE TABLE [dbo].[People]
(
	[id] [int] IDENTITY(1,1) NOT NULL,
	[name] NVARCHAR(200) NULL,
	[dateAdded] DATETIME DEFAULT GETDATE()
);

INSERT INTO [dbo].[People] ([name])
VALUES ('Simba'), ('Annette'), ('Bobby'),
       ('Fred'), ('Mary'), ('Beth');

Read More »TSQL – Change Data Capture

Database Corruption Challenge Week 3 Results

Challeng3_RecoveryPending

It is my pleasure to announce the winners in the Week 3 Database Corruption Challenge. But first how about a rundown of challenge.

The challenge was issued at 10:00pm (pacific time) on Friday night. Yes, this was a difficult time for those on the East coast of the US, and if you are from EST, next week I promise the time will be better for you. Trying to switch up the times to give everyone across the planet a fair advantage. Those who had signed up for my Newsletter received early notification of when the corruption challenge would occur, but not details on what the challenge would be.

Once the challenge was issued, I received a couple of partial submissions, one contained the correct steps, but no results. The second one contained the right results, but was missing the steps to do it. The first correct submission that contained the steps, and proof that it was done correctly came in 37 minutes after the contest had started.  It was almost an hour later before the next winning solution was sent in.

Read More »Database Corruption Challenge Week 3 Results

Database Corruption Challenge Week 3 Approaching

After two great weeks of the database corruption challenge, week 3 is approaching. I have a few things to announce as we go into week 3.

The database corruption challenge will run over 10 weeks at which point another challenge will begin, and everyone will start out with a fresh score, sort of like bowling. This post I am going to cover scoring and prizes, just to keep it interesting.

Scoring the Challenge

I realized that I had never finalized the scoring of the competition. Here are the scoring criteria that I have come up with.

Read More »Database Corruption Challenge Week 3 Approaching

Deadlock and Trace Flags 1204 and 1222

When you are looking for deadlocks there are, like most things in SQL Server, more than one way to find the deadlocks. This article is specifically focused on using the SQL Server ERRORLOG file located in the LOG directory for the SQL instance. If you used the defaults on SQL Server 2012, this log would be at this location:

C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Log\ERRORLOG

For SQL Server 2014 it would be here:

C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Log\ERRORLOG

and in similar locations for other versions of SQL Server.

 

What is a Deadlock?

deadLock

A deadlock is a specific case in SQL Server and other databases where, in the simple case of two transactions, the first transaction gets stuck waiting on blocking from the second transaction, and the second transaction gets stuck waiting on blocking for the first transaction.

Imagine traffic so jammed up that one lane of travel is blocking another lane of travel, and vice versa. The deadlock in SQL Server is similar to this, but instead of traffic being blocked, it is queries and transactions being blocked.

Eventually in traffic when cars are blocking, one will give up and back out, and the other will be allowed to drive through. The one that backs out is known as the deadlock victim.

When one query is chosen as the deadlock victim, it looks something like this:

Read More »Deadlock and Trace Flags 1204 and 1222

Database Corruption Challenge #2 – Alternate Solution

With week two of the Database Corruption Challenge being just as interesting as week one, and after seeing yesterdays blog posting showing the solution by Rob Farley, you might be thinking you are ready to take on corruption. If you are interested in giving the corruption challenge a try, please sign up for my newsletter so that you will be notified of the next corruption challenge.

Lets take a look at one of the more interesting solutions submitted by Bogdan Sahlean, who was the first to solve using DBCC Page to find the exact corrupt bytes, and DBCC WritePage to fix those corrupt bytes.

Now if you are reading this, and don’t know about DBCC WritePage, I caution you…  DBCC WritePage is not something you should just play with, and it is certainly not something that you should ever run on a production database. Consider yourself warned.  One of the dangers of using Write page that it’s use will make the DB unsupported if Microsoft support is required.

Read More »Database Corruption Challenge #2 – Alternate Solution