An interview with Peter DeBetta
by Douglas Reilly
I have wanted to interview Peter DeBetta ever since I read his latest book, Introducing Microsoft SQL Server 2005 for Developers. Although it’s not the only book about SQL Server on the market, I found it particularly enjoyable.
Peter runs DeBetta Software, a consulting firm that develops data-driven enterprise solutions. He is also a programming instructor for Wintellect, a training and consulting company, and a frequent speaker on SQL Server and other subjects.
Peter answered the following questions via email.
Doug: One of the major divides among SQL Server developers is whether to use stored procedures or ad-hoc SQL. What side of the issue do you fall on?
Peter: I favor stored procedures. In SQL Server 2000, parameterized queries offered better flexibility than stored procedures. And ad-hoc queries, either via parameterized queries or within stored procedures, required exposing the underlying tables or views, which made possible a security breach such as SQL injection.
In SQL Server 2005, ad-hoc SQL in a stored procedure can encapsulate security via the Execute As clause, so underlying tables and views are not exposed. Stored procedures are also the publicly exposed interface to the database, and make the SQL code more manageable since it is located in one place rather than in various data access layer applications.
Doug: When you program in .NET, C# seems to be your favored language. Why?
Peter: I have been programming with Visual Basic since version 2.0 and wanted a challenge and a change of scenery. I knew transitioning to Visual Basic.NET would have been easier, but I also wanted to learn a new language syntax that would enable me to be more flexible for my clients.
Doug: Do you use unmanaged code?
Peter: I still have clients who use non-managed code, so I use it often. Although some companies will always be cutting edge, others will continue using legacy code because it works and it takes time and money to transition.
Doug: How did you start working on databases?
Peter: Before SQL Server 6.0, I had only worked with products such as Access, FoxPro and the like. I was thrown into the enterprise database system world at one job where I was told I was going to teach SQL Server. I attended a Microsoft class, then started using it and working with the consultants at the company. Since then I have been designing, developing, programming, consulting and teaching SQL Server.
Doug: How did you learn about databases?
Peter: The same way. I was thrown to the lions, so to speak, and was fortunate to come out alive.
Doug: Have you done much with XML?
Peter: I was very anti-XML when it first made the scene, thinking it was yet another unnecessary markup language. But I have seen the light, and realize its importance in a world of heterogeneous systems as a medium for structured storage. And although I knew about it for some time, I have been using it regularly for only the last few years.
Doug: Your most recent book targets SQL Server 2005 Beta 2. How difficult was it to write about a beta product?
Peter: Writing a book is not an easy task. Writing a book about a beta product is even more difficult, especially if it will be published long before the product is ready to market.
In my case, things were constantly changing, so I was updating code and concepts until the book was ready for press. The book has been out for about a year, and although the concepts are still mostly accurate, the code samples are out of date.
Doug: How did you get involved with writing books?
Peter: I was teaching a SQL Server 6.5 programming class and someone asked if SQL Server had crosstab abilities. I told the student no, but then thought about it and decided to write a stored procedure to return crosstab, or pivoted, data.
When I completed the monstrous procedure, I realized I knew the product pretty well, so I got up my nerve and wrote to a publisher. Within a few weeks, I had a contract for a SQL Server programming book that, after about two months, was canned due to a perceived lack of interest.
I almost gave up on the idea of writing a book. But I woke up one day about a month later and decided to try again. I got a contract with Sams Publishing to write an Unleashed-series book, which went to press and started my writing career.
Doug: What sort of work are you doing these days?
Peter: I maintain ASP and Visual Basic applications for a few clients, and for others I do .NET development against both SQL Server and Oracle back-ends. I have also been doing database optimization work.
I work with other clients on SQL Server 2005. One is implementing a SQL Server 2005 Reporting Services solution. Another needed to design and optimize data access. A third is implementing a new version of an enterprise application, and I am helping to migrate and upgrade the existing SQL Server 2000 database to SQL Server 2005.
Doug: One of the cool ways a software person can make a living is as a consultant, but with that comes the need to get and maintain clients. I discuss this subject in a recent blog entry, and wonder how you have managed it.
Peter: Word-of-mouth is your friend in this business. Work with Wintellect provides part of my income, and my consulting provides the rest. I have a couple of long-term clients, which is also helpful.
My wife was concerned when we first got engaged, but she has learned over the years that it’s possible to be an independent consultant and survive. Involvement in the community is important, too. I recently got some small, local jobs because of my involvement in local groups.
Doug: One of the benefits of my consulting work is that I discover connections between seemingly different businesses. I have found internal similarities between a paint selection system I worked on and a contract management system for a healthcare consulting company. Have you found similar connections?
Peter: Several clients have benefited from my previous experience. A reporting solution for one client saved time and money for a second client. Most applications enable users to input, retrieve and report on data. The implementations may vary, but in the end they all do the same thing.
Doug: Having worked with SQL Server 2005, what do you think of using VB.NET or C# for stored procedures?
Peter: One should use .NET for stored procedures or other database code when T-SQL won’t cut the mustard. But T-SQL will beat .NET when it comes to set-based data access. Even basic mathematical operations are faster in T-SQL than in .NET.
.NET should not be used to replace functionality that exists in T-SQL, but to enhance it. .NET provides better performance for complex operations, and it has features not available in T-SQL.
.NET can also be used for business logic that can move to the database server. An existing business process may require frequent round-trips to the database server, for example. As long as the database server can handle the load, the process is a candidate for moving to the database server. You can severely cut down on network traffic that occurs during the business process, and you will likely get results back to whomever called the code, since less time is spent transporting data over the wire.
.NET will also be a great replacement for existing extended stored procedures. There are many things you can do with .NET in SQL Server. My rule of thumb is to approach with enthusiasm and prudence.
Doug: Many years ago, I thought I had “discovered” markup languages until I came across the more elegant HTML. Have you ever “invented” anything, only to discover much better prior art?
Peter: Perhaps it was that fear of discovering better prior art that stopped me from being too inventive.
I was involved in one invention, which was later developed independently by someone else. Along with Byer Hill, a friend and colleague, I designed a system that provided data via http that Byer implemented and continues to refine. Essentially we created SOAP, but it was a proprietary binary format as opposed to an open standard using XML. It worked wonders for intranet solutions, and continues to do so today with several clients.
Doug: Have you read any good database or general programming books lately?
Peter: Roger Wolter’s The Rational Guide to SQL Server Service Broker Beta Preview from Rational Press is a great book. Since it was based on beta preview code, a few minor changes have occurred, but it gives a solid core explanation of SQL Server Service Broker. I am also eagerly awaiting Jeffrey Richter’s CLR via C#, which is the second edition of his Applied Microsoft .NET Framework Programming book.
Doug: Can you think of a particularly cool tip or trick that many database developers do not know about?
Peter: I stumbled onto something some months ago that may or may not be generally known: You can use parameterized constructors with user-defined types in SQL Server 2005.
SQL Server UDTs require a static parse method for getting data into the type instance. So if you have binary data that needs to be stored in a byte array field in your UDT, it is converted twice-once to a string in order to pass it to the parse method, and then back to a byte array within the parse method.
You can create an instance of the type using a static method that accepts the native type, in this case binary, and then call the parameterized constructor in that method and return the instance of the type. This prevents the second conversion, speeding the operation by about 15 percent.
Doug: What music do you listen to?
Peter: Listening and performing music is a big part of my life. I prefer acoustic folk music, although I do have an eclectic collection of more than 900 CDs that includes everything from classical, big band and jazz to modern pop and folk. I’m currently listening to some local bands out of Austin, including my favorite, Matt the Electrician.
I sing every chance I get, and try to play my acoustic guitar with regularity. I have performed in musicals in local theatre, and have even written my own music for acoustic guitar and voice.
Do you know someone who deserves to be a Database Geek of the Week? Or perhaps that someone is you? Send me an email at email@example.com and include “Database Geek of the Week suggestion” in the subject line.