Database Projects
You can use database projects to create new databases and to update existing databases and data-tier applications using Visual Studio just like any web or Windows desktop application.
Why a Database Project
We have our Windows desktop or web application's source code all under version control so that we can keep track of all the changes going on. However the database scripts, table changes, procedures and function updates and so on are ignored. Keeping the database in sync and managing all the changes being done is a challenging task. Also if we have multiple servers then the task of managing the database becomes even tougher.
A database project enables you to apply version control and project management techniques to your database development efforts in much the same way you apply those techniques to managed or native code. The development team manages changes to databases by putting it under version control using Team Foundation Server. Members of your team can then check out files to make, build, and test changes in an isolated development environment before sharing them with the team. To help ensure code quality, your team can finish and test all the changes for a specific release of the database in a staging environment before you deploy the changes into production.

Content List
- Getting Prepared
- Creating Database Project
- Creating various database objects, like tables, functions, procedures, triggers and so on
- Pre-deployment and post-deployment script
- Creating a Publish Profile and publishing the Database Project
- Importing an existing database to a new Database Project
1. Getting Prepared
So what do we need before creating a Database Project? First the SQL Server Database, obviously, and secondly Visual Studio.
However to create a Database Project you also need to check if your Visual Studio has SQL Server Data Tools installed.
If you have this installed then you can proceed otherwise you must install it first.
Open Visual Studio > Help > About Visual Studio. You can see SQL Server Data Tools in the list.

If Yes go ahead else you can download and install the SQL Server Data Tools.
2. Creating Database Project
Create a new project by clicking "File" -> "New" -> "Project..." then seelct "SQL Server" > "SQL Server Database Project".
If you don't find this item then it means SQL Server Data Tools is not installed. Refer to the preceding section for details.
3. Creating various Database Objects
Before creating a database object, get the project organised by creating various folders for multiple objects. Like create a "Tables" folder for keeping tables, "Functions" folder for functions, "View" for views, "Procedures" for Stored Procedures and so on.
You can also create a folder for multiple modules like "Product", "Sales" and under this create "Tables", "Procedures" and "Functions" folders.

Create a sample Table "Product" and "Order" by right-clicking on the tables folder then selecting Add > Table.
You get the Table Designer and Code view. Enter add fields from Designer or type in Code view.
The following is the "Product" table.

The following is the "Orders" Table

Create a sample function by right-clicking on the Functions folder then selecting Add > Scalar-Valued Function.

Create a sample Stored Procedure by right-clicking on the Procedures folder then selecting Add > Stored Procedure.

Create a sample Stored Procedure by right-clicking on the Triggers folder then selecting Add > New Item > Tables and Views > Trigger.

4. Pre-deployment and Post-deployment Script
Pre-deployment and Post-deployment scripts execute Transact-SQL statements before and after the main deployment script.
Like a pre-deployment script can copy data from a table that is being changed into a temporary table before re-formatting and applying the data to the changed table in a post-deployment script.
I included a Post-Deployment script to add few records to the "Product" table.

5. Creating a Publish Profile and Publishing the Database Project









kinjal patelPosted Jan 18, 2017, 1:19 AM
Nice explanation but i just want to know how to use this project used inside my window base applicaiton? can you please help me any one.
SubashPosted Oct 26, 2016, 3:54 AM
Useful article sir
kinjal patelPosted Oct 5, 2016, 5:51 AM
If adding new column in Product table then how to publish or changed in database project ?
Santhakumar MunuswamyPosted Aug 22, 2015, 7:45 AM
Good Article. Thanks for sharing
Yashwanth MuthineniPosted Aug 20, 2015, 7:58 AM
Nice Share
Rajeesh MenothPosted Aug 20, 2015, 7:52 AM
Good Explanation...
Upendra Pratap ShahiPosted Aug 20, 2015, 7:32 AM
great work....
Sibeesh VenuPosted Aug 20, 2015, 6:25 AM
Nice Share
Gowtham KPosted Aug 20, 2015, 5:47 AM
Good one
Gopi ChandPosted Aug 20, 2015, 2:57 AM
Nice explanation
Vaikesh K PPosted Aug 20, 2015, 2:44 AM
Good One :)
Ankit BansalPosted Aug 20, 2015, 1:43 AM
good one...
RakeshPosted Aug 20, 2015, 1:25 AM
Good work