Creating the DB
12 Jun 2009 @ 01:52PM

Updated: 25 Jan 2010 @ 01:55PM
Now that we have our basic DB setup, let's actually create it. I won't go through the nuts and bolts of creating everything... I think that's been covered sufficiently in previous tutorials. I'll be using SQL Server 2008 Express for this project, as it's now available. However, I won't be leveraging any of the new features, so if you have 2005 installed it shouldn't matter. I'll also be using SQL Server Management Studio Express 2008 as my front-end into the DB, so if you're using 2005 don't be surprised if things look a bit different.

First we'll create the DB... I'll call it Blog to keep the "obviousness" factor going.

Creating Our DB

Next I'll create the tables. First is the user table, laid out as described in the planning stage. All fields are required (none allow nulls) and the userid field is set as the autonumber identity column. I chose to use the tinyint field type for ShowEmail to serve as our boolean. There are other options, such as bit or char(1). Use whatever you want. If you notice, I've camelCased the field names. Some people consider this bad form, other people like it because it makes the fields more readable. Do what you will. If you prefer to make the full field name all lower case and separate words with underscores, feel free.

The User Table

I've created the blog table as well. Like the users table, the blogID is the autonumber identity. I've limited the blog title to a 50 character varchar and made the blogText field a text field. Once again, I used a tinyint to hold our boolean value.

The Blog Table

Last we have our comment table. The name field I've allowed to contain nulls in case the comment is either from a logged-in user, or the commentor would prefer to leave the field empty. Everything else should be fairly self-explanatory.

The Comment Table

That completes our DB structure. Now let's start writing some code.
Comments (0)