Gunnar Peipman's ASP.NET blog

ASP.NET, C#, SharePoint, SQL Server and general software development topics.

Sponsors

News

 
 
 
 
 
DZone MVB

Links

Social

Visual Studio 2010: Database projects

Visual Studio 2008 introduced us database projects. These projects are also present in Visual Studio 2010. I noticed some differences already when building my photo gallery application. Let’s see how these projects work under Visual Studio 2010.

Why database projects?

Database projects are good for more than one reason. Main reason is simple – all database objects are defined in same solution where is code that is using this database. Because database project is project like the others then it is possible to add it to code repository – you get versioning this way.

You can build and deploy database projects so you get SQL-scripts and up to date database on your database server. And… I’ve heard that database projects are also able to incremental deployments.

Structure of database projects

Mygallery2010: Database project In my last posting about my photo gallery system, Packaging my gallery code, I wrote about how to separate files from web project to other projects. One of there projects was database project called MyGallery2010.Database.

You can see my database project structure on right. Currently I have definitions for tables, primary keys and foreign keys. I think it is enough for now. When project gets some more complex requirements on database then I will add new features.

One difference I noticed is that empty database project is created without deep folder structure in Visual Studio 2010. Visual Studio 2008 database projects created also folders for tables, keys and so on. Visual Studio 2010 let’s you decide how do you want to organize the definitions of your database projects.

The internal structure of database projects is very rich. Take a look at properties section – there are settings for SQL command variables, deployments, permissions and other settings. You can also add database references to Visual Studio database projects.

And one thing more – take a look at Post-Deployment and Pre-Deployment folders. You can add there special SQL-scripts that are run before and after database deployment.

Adding database objects to project

After creating new database project it is easy to start adding definitions for database objects. You can right-click on database project and select database object type from menu as show on following screenshot fragment.

Visual Studio 2010: Database menu

You can also use "Add New Item” menu selection to add new database object definition from database objects menu as shown on following screenshot.

Visual Studio 2010: Add new database object

After adding new object definition Visual Studio 2010 creates file for it and adds example definition to it. You can use it to build up your own object definition. Building your database using Visual Studio database projects guarantees pretty well that you pay attention to every object you define. I think it may decrease also bugs in database definitions.

Building and deploying database

Building and deploying database projects is not different from other projects. What is different is output.

MyGallery2010: Build results of database project

You can see that before any deployments database scripts are validated and also object dependencies are analyzed. It means that before deployment the order of changes is already clear and deployment scripts have no errors.


kick it on DotNetKicks.com pimp it Progg it 顶 Shout it

Comments

PimpThisBlog.com said:

Thank you for submitting this cool story - Trackback from PimpThisBlog.com

# July 29, 2009 6:20 AM

DotNetKicks.com said:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# July 29, 2009 6:21 AM

progg.ru said:

Thank you for submitting this cool story - Trackback from progg.ru

# July 29, 2009 6:22 AM

9eFish said:

9efish.感谢你的文章 - Trackback from 9eFish

# July 29, 2009 6:23 AM

Gunnar Peipman's ASP.NET blog said:

Here are my postings about Visual Studio 2010 and .Net Framework 4.0 that may be interesting to my readers

# July 29, 2009 6:25 AM

Gunnar Peipman's ASP.NET blog said:

MyGallery2010 is my simple photo gallery system built on Visual Studio 2010 and .Net Framework 4.0 technologies

# July 29, 2009 6:26 AM

Visual Studio 2010: Database projects | ASP Scribe said:

Pingback from  Visual Studio 2010: Database projects | ASP Scribe

# July 29, 2009 7:20 AM

Webmaster Crap » Blog Archive » Visual Studio 2010: Database projects - Gunnar Peipman's ASP.NET blog said:

Pingback from  Webmaster Crap  » Blog Archive   » Visual Studio 2010: Database projects - Gunnar Peipman's ASP.NET blog

# July 31, 2009 10:09 PM

smith said:

so cool ~~ thanks share

# August 3, 2009 3:06 AM

Jaipal Reddy said:

Good article.More about Microsoft technologies can be found at microsoftuniverse.blogspot.com.thanks for the share

# August 8, 2009 5:43 AM

Gunnar Peipman's ASP.NET blog said:

I am using Visual Studio database project and data generation plan to populate my database with random

# September 15, 2010 4:56 AM

Jason said:

It is of my concern!?  I cannot longer when I find the code you have replied that this will be of little dangerous help.  Yes or sure I may have not this code much but Can you of course help?  It error of database...... of course.  Thank you!

# December 2, 2010 1:18 PM

Gunnar Peipman's ASP.NET blog said:

During development it is possible that database schema changes and usually it changes are same sure to

# December 14, 2010 1:40 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)