Powershell Remoting with SQL Server

PowerShell
One of the best things to come out with Powershell V2 is remoting and asynchronous calls. Between the two of these, you can basically send commands simultaneously to a number of SQL Server instances. BUT... and there always seems to be one of those, there is a lot of work required to get this running right. I'm going to outline what I did recently to test the ability of PowerShell to begin administering my servers remotely. Hopefully this provide the basis for a checklist and a how-to. I'll update this post over time so that I get things right. Enable remoting on the machines you wish to call This requires admin privileges, but it's pretty simple unless you need to modify which ports are available, etc. But to get it going the easiest…
Read More

SQL University: Introduction to Indexes, Part the Third

SQL Server, T-SQL
Nice to see most of you have managed to fight your way through the shoggoths outside to attend another lecture at the Miskatonic branch of SQL University. This will be the third and final part of the introduction to indexes lecture. Please, if you're going mad, step out into the hall. Our previous two lectures introduced the concept of indexes and then talked about two types of indexes, clustered and nonclustered. This lecture will cover the concept of statistics as they relate to indexes. If you followed the previous lecture then you know that indexes are stored in a Balanced Tree or B-Tree structure. You know that this storage mechanism is intended to provide fast retrieval of data. But, how can the query engine inside SQL Server know which index…
Read More

SQL University: Introduction to Indexes, Part the Second

SQL Server, T-SQL
Welcome once more to the Miskatonic branch of SQL University. Please try to concentrate. I realize the whipoorwills singing outside the window in a coordinated fashion that sounds almost like laboured breathing can be distracting, but we're talking about indexes here. We left last class with a general idea what an index is, now it's time for some specifics. There are several different kinds of indexes, as we talked about last class. But the two you're probably going to work with the most are clustered, non-clustered. Each of these indexes is stored in a structure called a B-Tree, a balanced tree, not a binary tree. That's a very important distinction. A B-Tree is a double-linked list that is defined by the keys of the indexes on the top and intermediate pages, and…
Read More

SQL University: Introduction to Indexes, Part the First

PowerShell, Spatial Data, SQL Server, T-SQL
Right, all eldritch tomes are to be closed and Elder Signs are to be put away during this course. Welcome to the History department here at the Miskatonic branch of SQL University. Why the History department? Well, first, because I like history and have frequently thought I would enjoy teaching it. Second, because I needed a hook upon which to hang part of the story I want to tell. What story is that you ask? Why, the story of the Dewey Decimal System. We are interested in studying history and historians must classify our subjects carefully. For advanced students we'll be covering the Library of Congress Classification System and the... Right, I give, this is the introductory class on indexes. If you thought we were covering something exciting and sexy like PowerShell,…
Read More

Steve Jones to Run for PASS Board

PASS
I couldn't hide the lead. Steve Jones (blog|twitter) has announced he's running for the PASS board. I'm excited. I'm almost as excited as if I were going to run. Steve is not simply a major influencer in what we call the SQL Community. He brings two things to the party that I think are going to make him very successful on the board. First, he gets things done. He just does. He's one of those guys that seems to keep it together, just enough, to accomplish stuff. Second, he has real ideas. He's not someone who is simply going to iron out a wrinkle or three at the Summit. He's going to propose stuff that will make a difference. Put those two things together and I think we've got reason to…
Read More

In the Clouds

Misc
The July meeting for the Southern New England SQL Server Users Group is tonight. Andrew Novick will be talking about SQL Azure. It'll be a great meeting. Our sponsor is Red Gate. They bought pizza.
Read More

Red Gate SQL Source Control

SQL Server, T-SQL, Tools
You just have to love Red Gate tools. They find the small area that they want to cover and then they cover it extremely well. I rave regularly about SQL Prompt and SQL Compare and SQL Search (free one, btw). I've got SQL Data Compare and SQL Data Generator open & working on my desk regularly. I'm dabbling in their other tools fairly often as well. I just like Red Gate tools. I guess my constant & consistent praise is why I'm a "Friend of Red Gate." I like to mention that before I start praising their tools some more, just so no one thinks I'm hiding it. Why would I hide it? I'm proud to say it. I am a Friend of Red Gate! ... anyway... where was I... right, new software.…
Read More

Delivering the Bad News

Misc
It's a Friday, the day governments & companies traditionally deliver bad news. I recived the bad news earlier in the week, but I'm passing it on now: The Standard is dead. Let me first say, a couple of authors are right in the middle of finishing up articles. Those will be completed and published and you'll get paid. Andy sums up some of the reasons why the Standard failed very nicely in his blog post. I agree with them, if not where the responsibility lies. Andy takes most of it on himself because, well, he's that kind of guy, may the gods bless him. But, the fact is, I took on the job and just wasn't prepared for what it would entail. The "editing" part of the job was hard.…
Read More

Small PowerShell Script

PowerShell
I'm still trying to learn PowerShell better. The opportunity to answer simple questions and problems with the tool is hard to pass up. We had a need to clean up data directories where data files were left behind or people put inappropiate files, so I wrote the following Powershell script: [sourcecode language="powershell"]param([string]$filelocation="",[string]$sqlinstance="(local)") Set-Location $filelocation foreach($file in get-childitem) {$base = $file.Name; $result = Invoke-Sqlcmd -ServerInstance $sqlinstance -Query "SELECT DB_NAME(mf.database_id) AS db FROM sys.master_files mf WHERE RIGHT(mf.physical_name,LEN('$Base')) = '$Base' UNION ALL SELECT 'NoDb' AS db WHERE NOT EXISTS (SELECT DB_NAME(mf.database_id) AS db FROM sys.master_files mf WHERE RIGHT(mf.physical_name,LEN('$Base')) = '$Base');" ; if($result.DB -eq "NoDb" -and $file.Extension -ne ".cer"){Remove-Item $base}} It's a very simple script. It takes a UNC and a server instance and then walks through the files in the UNC and validates…
Read More