How to Create a SQL Database Project for ASP MVC in Visual Studio 2012

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

Create SQL Database Using SSDT VS2012 1 | SamuraiListing Example

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.

Create SQL Database Using SSDT VS2012 | SamuraiListing Example

4. Open Server Explorer

Right click > Open the created database. Right click on the “Table > Add new Table”.

Create SQL Database Using SSDT VS2012 | SamuraiListing Example

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.

Create SQL Database Using SSDT VS2012 | SamuraiListing Example

Likewise, do the same for Sector table.

Create SQL Database Using SSDT VS2012 | SamuraiListing Example

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”.

Create SQL Database Using SSDT VS2012 | SamuraiListing Example The completed CompanySectors table script should read like this.

Create SQL Database Using SSDT VS2012 | SamuraiListing Example

6. Check the create Tables in Database

Navigate to Server Explorer, right click on the “Tables” then “Refresh”, you should see the created tables.

Create SQL Database Using SSDT VS2012 | SamuraiListing Example

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.

Advertisements

2 comments

  1. Pingback: How to create a simple data access layer using Repository Pattern with Entity Framework | BizVise - Melaka Software Development

  2. Pingback: Simple KendoUI Example – SamuraiListing | BizVise - Melaka Software Development


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s