Database projects in Visual Studio 2010 offer great help for maintaining databases through the life-cycle of a software project. In this first post of the series I’ll introduce you to some of its features and possibilities.
Background
Some of you may be aware that the database project was available for Visual Studio 2008 as installable add-in (GDR) called “Data Dude” in casual speech. Because it wasn’t an out-of-a-box experience, most developers never really were aware of it at all or bothered installing it.
Now that the database project comes with Visual Studio 2010 (Premium/Ultimate; limited in Pro), there is no reason to avoid using it. There is also a new Data-tier application project (DAC), but I won’t go into it for now. Only SQL Server 2005 and 2008 [R2] are currently supported, by the way.
What can you do with the database project?
There are several benefits that make working with databases easier in normal project life-cycles, when using the database project:
- Keep database schema in version control
- Keep an offline copy of the database
- Track dependencies between database objects
- Refactor database objects
- Create deployment scripts for new and changed databases
- Compare database schemas and data and generate change scripts
- Generate unit tests for stored procedures and functions
- Generate test data
- Author and execute scripts directly from the Visual Studio
Architectural Overview of the Database Features of Visual Studio –page in MSDN expands these items more.
Getting Started – Import database
Getting started is easy:
- Add a new SQL Server Database Project to the solution:
- Name the database project after the database you want to work with, I’ll go with “NorthwindDB” as I’ll be using that familiar sample database for examples.
- Import existing database by right-clicking the new project in Solution Explorer and selecting “Import Database Objects and Settings”:
- Select an existing connection or create a new one. Default settings are fine for now, so you can just click Start to import the objects.
- You now have an offline copy of the database as a set of scripts:
- The project/solution can be added to the source control to check-in the current state of the database:
Conclusion
In this post I introduced you to the SQL Server 2005/2008 Database Project and showed how you can import an existing database for offline management and version control.
In the Part 2 I’ll introduce you to the Schema Comparisons and how they can be used to synchronize changes.
Comments