SQL Server 2008 will have IntelliSense

With so many exciting new features in Visual Studio 2008 to play with, I haven’t had much time to look at the preview releases of SQL Server 2008, alias Katmai. The last I heard was there wouldn’t be much new stuff for developers, just features for DBAs and BI analysts with a few performance optimisations thrown in.

The previous upgrade, SQL Server 2000 to 2005, was a huge step forward for developers and added significant advances like CLR integration, SQL Server Management Objects (SMO), Integration Services (SSIS) and a native XML data type; as well as T-SQL enhancements like Common Table Expressions (CTEs), structured error handling with try/catch, pivot, apply, top(n) and row_number.

So I was surprised to see how much new stuff is packed into the latest SQL Server 2008 CTP release, even, finally, IntelliSense for Management Studio, which was much anticipated but conspicuously absent from 2005:

SQL Server 2008 IntelliSense

Also notice the new collapsible code regions, just like you get in Visual Studio. Editing T-SQL has never been such fun! Although, you have to feel a bit sorry for RedGate, whose SQL Prompt plug-in has been filling the auto-completion gap for the last few years.

The groovy new features don’t end with IntelliSense, there are plenty more being sneaked into SQL 2008. I’ll be looking at more soon.

kick it on DotNetKicks.com

MCPD Web Developer exam 70-547 hints and tips

Following my post about studying toward MCPD certification, I’ve now taken the exam and am pleased to say I passed with a good score. The exam 70-547 is about designing and developing web applications using ASP.NET 2.0. It focuses on the full software development lifecycle and covers planning, architecture, design, testing and deployment, where as the prerequisite MCTS exams cover more of the actual coding and implementation details.

My main study guide was the official Microsoft Press book, MCPD Self-Paced Training Kit (Exam 70-547). It covered the syllabus thoroughly enough to get me through the exam, but like most similar books wasn’t much fun to read. It’s over 700 pages, and after the first few hundred the content starts to get fairly monotonous. It’s also difficult to skim because you might miss something essential for the exam. If you’re an experienced developer then you might not learn much, but if you’re new to coding then you should find plenty of useful information about broader areas of software development, such as architecture, data modelling and unit testing.

A lot of the testing chapters read like an advert for Visual Studio Team System (VSTS) and aggressively promote its unit testing and web load testing capabilities. There’s nothing wrong with that, it’s a Microsoft exam after all, but you will need Visual Studio Team Test if you want to work through the practical exercises (an evaluation version is available). The unit testing in VSTS is impressive, but doesn’t seem to offer much over the freely available NUnit. The web load testing on the other hand is invaluable.

My best advice for the book is to read it in short frequent bursts. Try to read a little bit every day and you’ll easily work through it, so don’t be intimidated. If you find yourself slacking, just register for the exam and you’ll soon become motivated. And remember to use the 15% exam discount voucher that comes with the book.

My other study resource, which I also used for the MCTS exams, was the practice test from MeasureUp. The questions are very relevant to the actual exam, and helped highlight areas to focus my study. The most useful feature is that every answer has an explanation, so if you get one wrong you can see why and hopefully fill a gap in your knowledge.

The exam isn’t easy, but many questions appeal to common sense as well as technical expertise, and there aren’t any trick questions. There’s more than enough time to work through the 40 multiple-choice questions, so be careful to read each one closely and don’t panic. Some questions ask you to pick more than one answer so follow the instructions carefully. The passing score is 700 out of 1000.

According to Microsoft’s statistics there are only 2,147 MCPD web developers worldwide, so if you want to improve your skills, stand out in the job market, or negotiate a promotion then certification could be a great career move.

My next goal is MCTS certification for SQL Server and exam 70–431. Then it shouldn’t be too long before the next generation of .NET 3.5 MCTS are available.

Let me know your experiences of studying of taking the MCPD exams in the comments below.

Finding orphaned stored procedures and user-defined functions in SQL Server

I’m currently working on a group of ASP.NET 2.0 websites deployed across about thirty countries. The local flagship site runs on an upgraded version of the original code, and I’m now in the process of bringing all the other sites onto the new improved version.

Over time, new features have been introduced to the site, and old ones removed. Consequently the SQL Server database now contains many redundant tables that aren’t used. So, before cascading out the current schema to the other countries, it’s time for a clean up.

I managed to identify about 60 tables that aren’t used by the application and can safely can be dropped or archived. However, I’m now left with hundreds of stored procedures (SPs) and user-defined functions (UDFs) that were associated with these tables, which can also be removed.

The problem was how to find these orphaned objects. My first approach was a small .NET console application which uses SQL Server Management Objects (SMO). It loops through all SPs and UDFs and finds any that have no dependencies.

public List<string> FindOrphans()
{
    Server server = new Server(".");
    Database db = server.Databases["MyDatabase"];
    List<string> orphans = new List<string>();


    // get list of SPs
    UrnCollection urns = new UrnCollection();
    foreach (StoredProcedure sp in db.StoredProcedures)
    {
        // exclude these objects
        if (sp.IsSystemObject) continue;
        if (sp.Name.StartsWith("aspnet_")) continue;

        urns.Add(sp.Urn);
    }


    // get dependencies
    DependencyWalker dw = new DependencyWalker(server);
    DependencyTree tree = dw.DiscoverDependencies(urns, true);


    // find all objects without any dependencies
    DependencyTreeNode node = tree.FirstChild;
    do {
        if (!node.HasChildNodes)
        {
            string name = new Urn(node.Urn).GetAttribute("Name");
            orphans.Add(name);
        }
        node = node.NextSibling;
    } while (node != null);


    return orphans;
}

This works fine, and helped satisfy my current obsession with SMO. But it’s a bit awkward, and not easily portable or modifiable, to have this pure database operation wrapped up in an executable. So I looked into doing the same thing with just a TSQL query.

-- Find all SPs and UDFs have no dependencies
select
    object_name(obj.[object_id]) as [orphaned_object_name],
    obj.type_desc as [object_type],
    'DROP ' +
    case obj.type_desc
        when 'SQL_STORED_PROCEDURE' then 'PROCEDURE'
        else 'FUNCTION'
    end
    + ' [' + object_name(obj.[object_id]) + ']'
from
    sys.objects obj
    left join (select distinct [object_id] from sys.sql_dependencies) dep
        on obj.object_id = dep.object_id
where
    type_desc in ('SQL_STORED_PROCEDURE','SQL_SCALAR_FUNCTION','SQL_TABLE_VALUED_FUNCTION')
    and object_name(obj.[object_id]) not like 'aspnet_%'
    and dep.object_id is null
order by
    obj.type_desc, object_name(obj.[object_id])

The query works by checking for dependencies in the catalog view sys.sql_dependencies. This, I think, is a neater solution. I also included an auto-generated column that writes the SQL drop the SP or UDF, which I copied and executed.

Now, if only I could find a quick way to check for dependencies between my application’s data access layer and the database…

kick it on DotNetKicks.com