Accessing Sample Database Data (Part 1)

It’s always hard to figure out the best way to provide access to sample data in a book. No matter how you do it, someone is going to find the amount of data limited or unrealistic, too hard to understand, too hard to access, or too hard to install.

One of the most common ways to provide sample data is to use a predefined database, such as Northwind or the newer AdventureWorks, that the reader can download and install. However, there are several problems with using these databases. For one thing, installing Northwind requires running a script that may not succeed (and then I get questions about why my script failed—unfortunately, it isn’t my script, it’s Microsoft’s script). Using AdventureWorks requires a copy of the SQL Server tools because you install the actual database and the tools don’t come with Visual Studio’s copy of SQL Server Express any longer, so now I also need to tell the reader how to install the required tools. In both cases, many readers find the process of working with these predefined databases too complicated. Once the databases are installed, many readers find the database design unrealistic and overly complicated (especially in the case of AdventureWorks, which really is complex). In addition, as more of my books move toward the open source realm, I can’t assume the reader will even have a copy of SQL Server. (If someone has a suggestion for a great open source alternative, please let me know.)

Another technique is to create a predefined database that I supply with the book’s downloadable code and ask the reader to install it as necessary. When working with a book that uses SQL Server, this means including the actual database file or creating a script to reproduce it. Again, the reader would need to install these files in some way—either by running the script or installing the database file using the SQL Server tools. When writing open source books, I’m leaning toward using XML databases because they’re text-based, simple to work with, and work on any platform. At least XML databases don’t require installation or scripts because they appear in the same folder as the application does. Because these databases specifically model the book environment, readers don’t complain about complexity or applicability, but some readers complain that they also don’t model their environment very well.

Of course, there is always the approach that I take in some books of having the reader build the database as part of the learning experience and then typing the data into it. The amount of data is small in most cases, so it’s not as if the reader is working for hours to input the information. However, this solution garners criticism because it’s too simplistic (doesn’t model the real world well enough) and readers feel that it’s more important to see working code, rather than work with the database. After all, database design is an entirely different specialty (some developers will be surprised when their employer asks them to create databases as part of their job). There is also that constant problem with the availability of tools—many of which are solved with Server Explorer when working with Visual Studio, but again, many of my projects are moving more toward open source.

In an effort to address the complaint about not spending enough time in the IDE and in creating code, there is always the approach of having the reader build an application that creates the database and fills it with data. The complaint this time is that most readers will never build such an application (I disagree because such applications are used all the time for storing settings and other application-specific information). What the reader really wants to see is the code that manipulates the database data and lots of it (sometimes without the level of explanation that less experienced readers require to actually understand the example). It’s important that I address all reader needs with the examples I create, so you’ll continue to see examples that create the database and fill it with data. The examples will always include full explanations so that no one is left behind. However, I am providing more references to online examples that emphasize code, lots of it, over any sort of explanation.

The point is that there are a number of ways in which an author can attempt to satisfy reader needs when writing a book that contains database management techniques. To make the book useful, the reader must have a database of some sort to work with. Whether the database is XML-based, SQL Server-based, or some new type of data source isn’t the problem for the most part—it’s creating a database that works well with the book’s material, models a real world environment to some degree, and is still easy enough to understand that the reader doesn’t become lost in detail. In order to accomplish these goals, more of my books now employ multiple database scenarios so that each reader type has enough data of the right type to get the maximum possible benefit from the book examples.

Of course, undertaking such a gargantuan task isn’t easy. Every one of you seems to have an entirely different set of needs. The next post in this series is going to attempt to demystify the process of getting the databases installed when working with SQL Server and Visual Studio. I also include instructions in my books, but this additional information is based on feedback from less experienced readers who are having trouble gaining access to the databases. What I’d like is to hear your questions so that I can address them in future posts. If you’ve had a problem getting one of my database examples to work because you can’t access the data, please let me know at You can find the next post in this series at Accessing Sample Database Data (Part 2).