Reading Gail Shaw’s post All indexes are unique, reminded me of an interesting piece of trivia I discovered back in SQL Server 7. The error message for running out of uniqueifier values is 666.

SELECT TEXT FROM sys.messages WHERE message_id = 666

Returns:

The maximum system-generated unique value for a duplicate group was exceeded for index with partition ID %I64d. Dropping and re-creating the index may resolve this; otherwise, use another clustering key.

Here is what SQL Server 2008 Books Online – Clustered Index Design Guidelines says :

If the clustered index is not created with the UNIQUE property, the Database Engine automatically adds a 4-byte uniqueifier column to the table. When it is required, the Database Engine automatically adds a uniqueifier value to a row to make each key unique. This column and its values are used internally and cannot be seen or accessed by users.

Someone on the SQL Server team definitely had a sense of humor, because to actually see this message, you would have to insert over 4,294,967,296 duplicate entries into your clustered index column. Anyone who would do that is truly evil.

{ 5 comments }

If you are in the Portland area, you won’t want to miss the OSQL-d meeting tomorrow. We have two great sessions planned.

Wednesday, Feb 11th, 2009 at 6:30 pm (Pizza and networking start at 6:00 pm)
Microsoft Portland Office – 10260 SW Greenburg Rd, Suite 600

Using SQL Server Management Studio, Intellisense, and SQL 2008 T-SQL Enhancements
Speaker: Buck Woody

Come hear Buck Woody, Microsoft’s “Real World DBA” as he explains the new enhancements in SQL Server Management Studio that will help you write better T-SQL code -faster. He’ll also cover some of the new Transact-SQL Enhancements. Come ready to learn and share!

http://buckwoody.com/BResume.html

Solutions to Vexing T-SQL Problems (Continued)
Speaker: Arnie Rowland

Time permitting, Arnie will continue a discussion on finding ordinary solutions to complex problems. He will be demonstrating several query problems that are often difficult to conceptualize, and providing code examples for the solutions. If you want to have your T-SQL code skills challenged and perhaps expanded, you will want to see this presentation.

Visit OSQL-d for more information.

{ 0 comments }

I just stumbled across this Windows 7 feature. In the sound properties dialog there is now a Communications tab. Supposedly, it will detect when you are on an audio call and mute or reduce the volume of all other sounds. So far, I’ve tried Skype and Live Messenger and neither one caused the sounds to mute. I really like the idea though and hope to see it working in a later build.

Windows 7 - Sound Dialog Box - Communications Tab

{ 0 comments }

FizzBuzz in T-SQL

February 3, 2009 · 10 comments

Pinal Dave posted yesterday about how to solve the Fizz Buzz problem using T-SQL.

Definition of FizzBuzz Puzzle : Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

His solution works, but he is using procedural logic. Some of the biggest causes of performance problems in SQL Server are caused by application developers who try to use procedural logic instead of using the set-based logic that databases are meant for.

Here is how to solve the FizzBuzz problem using set-based logic in T-SQL:

WITH Numbers(Number) AS (
  SELECT 1
  UNION ALL
  SELECT Number + 1
  FROM Numbers
  WHERE Number < 100
)
SELECT
  CASE 
    WHEN Number % 3 = 0 AND Number % 5 = 0 THEN 'FizzBuzz'
    WHEN Number % 3 = 0 THEN 'Fizz'
    WHEN Number % 5 = 0 THEN 'Buzz'
    ELSE CONVERT(VARCHAR(3), Number)
  END
FROM Numbers
ORDER BY Number

Update 3/15/2010:
Here is another, much faster solution, taken from ideas I found here.

DECLARE @num INT = 1000000
 
SET STATISTICS TIME ON;
SET STATISTICS IO ON;
 
;WITH
  L0   AS(SELECT 1 AS c UNION ALL SELECT 1),
  L1   AS(SELECT 1 AS c FROM L0 AS A, L0 AS B),
  L2   AS(SELECT 1 AS c FROM L1 AS A, L1 AS B),
  L3   AS(SELECT 1 AS c FROM L2 AS A, L2 AS B),
  L4   AS(SELECT 1 AS c FROM L3 AS A, L3 AS B),
  L5   AS(SELECT 1 AS c FROM L4 AS A, L4 AS B),
  Numbers AS(SELECT ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) AS Number FROM L5)
 
SELECT TOP (@num)
  Number,
  CASE 
    WHEN Number % 15 = 0 THEN 'FizzBuzz'
    WHEN Number % 3 = 0 THEN 'Fizz'
    WHEN Number % 5 = 0 THEN 'Buzz'
    ELSE CONVERT(VARCHAR(7), Number)
  END AS FizzBuzz
INTO #FizzBuzz
FROM Numbers
 
SET STATISTICS TIME OFF;
SET STATISTICS IO OFF;
 
--SELECT FizzBuzz FROM #FizzBuzz ORDER BY Number
 
DROP TABLE #FizzBuzz

{ 10 comments }

The SQL Server Customer Advisory Team (SQLCAT) just posted a great article listing some of the best new SQL Server 2008 features for the DBA. Here they are:

  1. Activity Monitor
  2. SQL Server Audit
  3. Backup Compression
  4. Central Management Servers
  5. Data Collector and Management Data Warehouse
  6. Data Compression
  7. Policy-Based Management
  8. Predictable Performance and Concurrency
  9. Resource Governor
  10. Transparent Data Encryption

Read the full article.

{ 0 comments }

I just read Brent Ozar’s post about Stack Overflow adding a “reputation bounty” for answering questions. Brent said:

Thank God they’re not using real money, only reputation scores.  If they used real money, I’d probably stay up all night hitting refresh, waiting for new questions to come in.

Real money might not be such a bad idea. They could tie in to something like tipjoy and when people thought an answer was helpful, they could tip a small amount (maybe enough to buy the person lunch). I could see someone willing to toss out $100 or more, if they were under a deadline and working with a somewhat obscure technology. The biggest problems I see would be measuring the quality of the answer and collecting payment. It could be run similar to 99designs.

{ 0 comments }

SSIS Resources

January 29, 2009 · 3 comments

***UPDATED 2/10/2009 – Added links***
***UPDATED 2/23/2009 – Added MSDN SSIS Forum and Jeff Wharton’s link list.***

Last Thursday I gave a talk at the Oregon SQL Server Developers Professional Association and promised to post some Integration Services resources.

SSIS Best Practices

SQLCAT – Top 10 SQL Server Integration Services Best Practices
Matthew Roche – SSIS Best Practices, Part 2
Jamie  Thomson – SSIS: Suggested Best Practices and naming conventions

SSIS Tools and Samples

BIDS Helper is a very useful add-in for Visual Studio. Works with both SQL Server 2005 and 2008. Version 1.4 was just released on Jan 27th.

PacMan – batch package management tool by Matthew Roche.

Integration Services Product Samples

SSIS Blogs

Andy Leonard
BI Polar – Matthew Roche
BI Thoughts and Theories – John Welch
Brian Knight
Chris Randall
Dougbert.com – Douglas Laudenschlager
Jessica M. Moss
John Klein’s Microsoft Business Intelligence Blog
Michael Entin’s Notebook
Rafael Salas
Rushabh Mehta
SQLIS.com
SSIS bits ‘n’ bobs BLOG – Paul Ibison
SSIS Junkie – Jamie Thomson
SSIS Talk – Phil Brammer
SSIS Team Blog

I’ve shared an opml file of all the SSIS blogs if you would like to import them into an aggregator such as Google Reader.

Microsoft Links

MSDN: SQL Server 2008 – Integration Services
MSDN: SQL Server 2005 – Integration Services
Product page: SQL Server 2008 – Integration Services
Product page: SQL Server 2005 – Integration Services
MSDN: SQL Server Integration Services Forum

Other Links

Jeff Wharton – Favourite SQL Server Integration Services Articles

{ 3 comments }

I just read Jason Massie’s new Capt. Varchar(MAX) comic. If you have spent much time interviewing SQL Server candidates I’m sure this will bring back some memories.

I was helping a company phone screens candidates for a Senior DBA position a while back. We went through such a bad string of candidates that the three of us started taking bets. Half way through each phone screen we would vote if we thought the candidate would know what the “DELETE <table>” statement was used for, loser bought the others lunch. The really sad thing was that these were supposed to be senior level candidates.

What’s your best SQL Server interview story?

For those of you interviewing for an IT job. Brent Ozar just posted The Top 10 Questions To Ask When Taking an IT Job.

{ 5 comments }

I mentioned before that I was using an IIS7 shared plan on GoDaddy.com. Their shared hosting plans are supposed to support multiple domains. Unfortunately, they implement the domains using some kind of URL rewriting that conflicted with the URL rewriting I setup for WordPress. After trying several different configurations that resulted in my blog being down for an extended period of time, I decided it is impossible (or at least more painful then I wanted) for me to host multiple sites.

I really don’t like shopping for hosting companies, because there are so many of them and a lot of different feature combinations. I wanted one that ran Windows 2008 with IIS7, had support SQL Server 2008, as well as PHP and MySQL (for WordPress). It also had to be affordable. After looking around quite a bit I decided on SoftSys Hosting. The reviews online were mixed, with some people really liking them, and others complaining. It’s hard to know who to believe, because it seems like there are a lot of fake reviews on the sites in both directions. Time will tell how good they are.

{ 4 comments }

Tweetbacks

January 9, 2009 · 0 comments

UPDATE: I stopped using tweetbacks because they just weren’t that interesting.

I came across a post on Mashable today talking about Tweetbacks (A Tweetback is like a trackback or pingback from Twitter). The Mashable post linked to a post by Dan Zarrella who has an easy to implement script you can throw on your blog to insert the tweetbacks.

I tried out Dan’s script, but couldn’t get it to work and it killed the performance of my blog, probably because everyone else who read the Mashable post is trying it out too. Fortunately, there was a comment by Jeremy Hilton that linked to a version he wrote that you can host on your own site.

I installed Dan’s script and it worked. I changed his current version (0.2)  by moving the files to a subdirectory, adding links to twitter profiles, and right aligning the dates. In another comment Dan wrote that he was hard a work on a new version that will give more control over formatting. Thanks Dan!

Let me know what you think.

{ 0 comments }