« A Place to Gather Intelligence on 1-800 CallersIsolated Big Baby Syndrome »

SQL Server 2000 Gotcha With Uniqueidentifiers

09/15/07

  12:01:28 am, by Nimble   , 164 words  
Categories: Programming

SQL Server 2000 Gotcha With Uniqueidentifiers

If you're considering using uniqueidentifiers on your tables, particularly as primary keys, then you might want to upgrade your SQL Server or just check your SQL carefully if you're still running SQL Server 2000.

In particular, doing a COUNT(field) on a uniqueidentifier comes up with a bizarre error on SQL Server 2000:

Msg 409, Level 16, State 2, Line 1

The count aggregate operation cannot take a uniqueidentifier data type as an argument.

It's truly a weird error. Why on earth would there be difficulties in counting any field?

Now you can go COUNT(*) without difficulty, or use a different field. COUNT(field) is useful when you're doing cross-database SQL, since it's actually faster than COUNT(*) on some databases, but if you can tune your SQL to the particular database, it helps. SQL Server 2005 also combats this silliness, but this only helps if you can deprecate support for SQL Server 2000.

Just wanted to post this, since there really wasn't anything helpful around the 'Net on that particular error message.

1 comment

Comment from: Lauren [Visitor]  
Lauren

Thanks for putting up this info about the SQL error. It must have been because I was trying to write my join late on a Friday that my brain was fried and I couldn’t figure out my problem. Hooray, I fixed it :)

03/14/08 @ 17:20
August 2020
Sun Mon Tue Wed Thu Fri Sat
 << <   > >>
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Ritchie Annand's blog of everything except sports (...and who knows? I may break that rule some day)

Search

  XML Feeds

powered by open-source CMS software