Nerd Dinner Part 2 Discussion and Database Setup Script
Posted in Uncategorized on August 30th, 2010 by matt – 2 CommentsThis post is a discussion of Part 2 of the online NerdDinner ASP.NET MVC tutorial.
NerdDinner Part 2 is about setting up the database for future work.
There’s a lot of table creation and data entry. This is all done via the Server Explorer tool inside Visual Studio. If you want the practice setting up your tables and data manually, follow along with the tutorial–it’s carefully laid out with lots of useful screenshots.
If you don’t need the practice and would rather take a shortcut, here’s a script you can use instead: NerdDinner database setup script. This script will create the Dinners and RSVP tables (including keys), and populate the Dinner table with data matching what we see in the screenshot.
The setup script relies on you creating the NerdDinner.mdf database yourself. If you want to use the script, be sure you finish the database creation steps of the tutorial (“Creating a new SQL Server Express database”) first.
To apply the script, just run it as a query against your new NerdDinner database. If you’re not used to running queries, here’s a step by step:
- Copy the complete text of the setup script to your clipboard.
- Open Server Explorer (it’s near the top of the View menu in Visual Studio, or you can use Ctrl-W, L).
- Expand the tree for your new NerdDinner.mdf database so you can see the folders underneath, right click on the database name, and choose New Query.
- Immediately close the Add Table window that popped up over the query interface.
- Find the SQL pane in the query interface. It’s third from the top, and should already have “SELECT FROM” displayed there.
- Delete the “SELECT FROM” so that the SQL pane is completely blank, and paste in the complete text of the setup script into that pane.
- Click on the orange exclamation point button shown in the toolbar (or, press Ctrl-R while you have focus in the SQL pane).
- You’ll get a warning. Server Explorer has a degraded understanding of SQL, and you’re scaring it. Don’t worry about the warning, click Continue. You may notice a delay while the query runs.
- You should get a message “7 rows affected by last query”. Close the message, you’re done.
(A special note: to create the INSERT statements used in the setup script, I used a stored procedure called sp_generate_inserts written by Narayana Vyas Kondreddi. If you work with SQL Server, I recommend taking a look at this sp, it’s very handy. Thanks Vyas!)
I didn’t encounter any problems working through Part 2, and there aren’t any code changes from Part 1 to zip up.
In Part 3, we’ll set up an interface to our new tables from our application, and talk about the Model in Model-View-Controller.