Here’s a simple step by step guide to create Microsoft SQL Server Database and project for ASP MVC application using Visual Studio 2012.
1. Download and install SQL Server Data Power Tools Extension
First, download and install SQL Server Data Tools Power Tools Extension (SSDT) from Visual Studio gallery. SSDT provides user interface to create tables and add records.
2. Create a Class Library project in Visual Studio 2012
3. Add Database item
Right click on our project and select Add New Item, then create a Service-based Database. You will be prompt to select a Datasource Model, click “Cancel” for now; we will add the model later.
4. Open Server Explorer
Right click > Open the created database. Right click on the “Table > Add new Table”.
For this example, we are creating a database for our Samurai Business Listing app. Below is the model I get from a database reference directory for business directory app. We are going to create 3 tables – Companies, Sectors, and CompanySectors.
5. Create Table
First, let’s create the table for Companies. Add fields of our company record and name our table – “Companies”. Make sure you click the “Update” button after you are done, this button will script and database and create the table based on the SQL code generated.
Likewise, do the same for Sector table.
and also “CompanySectors” table. But for “CompanySectors” we need to Add Foreign Key. Here’s the step – Right click on “Foreign Keys > Add New Foreign Key”.
The completed CompanySectors table script should read like this.
6. Check the create Tables in Database
Navigate to Server Explorer, right click on the “Tables” then “Refresh”, you should see the created tables.
Important Note: You are looking at one of the blog post I completed in a tutorial series about KendoUI and ASP MVC4, you can find out the Table of Content on - Simple KendoUI Example – SamuraiListing Step 1 – How to create KendoUI ASP MVC 4 project. Step 2 - How to Create a SQL Database Project for ASP MVC in Visual Studio 2012 Step 3 - How to create a simple data access layer using Repository Pattern with Entity Framework Step 4 - How to create a simple data access layer Unit of Work pattern with Entity Framework Step 5 - How to add Database and DataModel class to ASP MVC4 project. Step 6 - How to add KendoUI Grid Control and perform CRUD with ASP MVC.