To create the Visual Studio 2010 SQL Database Project, open the Visual Studio (VS) 2010 as a administrator.
- Click on File -> New -> Project : In the opened “New Project” window, under installed templates click on Database -> SQL Server and select “SQL Server 2008 Database Project”, select the location and click “OK” button.
- Open the solution explorer, you will find the database project has been created with the default folders.
- Expand Schema Objects folder, expand Schemas folder, expand dbo folder and expand Tables folder.
- Right click on Tables, select Add -> New Item. In the opened New Item window, select Table and enter the name Books, click Add.
- Double click on added Books.Table.sql script file and include create table script.
- Right click on Tables, select Add -> New Item. In the opened New Item window, select Primary Key, enter name and click Add. Open the script file and add script to add primary key for the Books table.
- You can add other scripts under respective folder names like Constraints, Indexes, Triggers etc.
- Under programmability folder you can add Functions, Stored Procedures, Types, Defaults and Rules scripts.
- We have added table script and primary key script, now set the SQL server connection string settings.
- Right click on the project and click on the properties. In the properties page, click on Deploy tab.
- Set the target database connection, change the Deploy action to create a deployment script and deploy to the database, you can change the other default setting values if you want.
- Save the settings and right click on the project and click on Deploy. Check the Output window, the deployment is succeeded or not.
- Open SQL Server Management Studio, and connect to server localhost. Check the database is created or not. The BookStore database should be created with the table Books.
- Expand Scripts folder in the project, you will find post and pre deployment scripts. You can include the post and pre deployment scripts in the Scripts folder.