If you’ve ever needed to work with sp_who2 to figure out what’s going on, then you know it would be nice to be able to sort the results, right? Well, if you use the following code, then you’ll get exactly that functionality. Enjoy! CREATE TABLE #who2 ( spid INT , [status] SYSNAME , [sid]…
Month: December 2005
Moving Data Between Tables
Very early into my SQL career I had to get comfortable moving records around between tables and databases. There are several ways to do it, you just have to get used to some of the requirements in moving the records. Moving records into a temporary table The first time you move records, you’ll probably need…
70-432:Multiple Solutions, Multiple Instances
At work our database server is humming along. It runs a little under 50% on the CPU, the RAM is a bit high, and the IO is very responsive. But, it could be better. About a quarter of the load on that server comes from one application. It’s a reporting solution built to handle end…
T-SQL Challenge: Find Days of the Week
My personal goal is to post an article every Monday, Wednesday and Friday. What I’d like to do is create stubs in my content database with each of those days already set aside. That way, I can look at the next stub available and simply start writing. The challenge for today is to create a…
Incomplete Tables
One of the things I’ve noticed while performance tuning is many of the tables in my current environment are incomplete. They all have columns defined, and they all have data, but they’re still missing something. Many are missing a primary key. You don’t always have to have a primary key, but when you’re joining against…
SQL 201 – Combining Query Results
Overview There comes a point in your SQL career where you will need to combine the results of several queries into one data set, and present it in one view. When you get to this point, you’ll need to be familiar with the UNION command. With Microsoft SQL 2005, there are two new functions, similar…
SQL 101 – JOIN
Overview I want to cover a fundamental topic for SQL programming. This is the topic you should start studying right after you have a basic understanding of what a relational database, what tables are, and that tables can be related to each other. If you’re a fan of Duct tape, then Joins will become the…