Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / database

SQL Server Data Tools to Visual Studio 2013 - Database Reverse Engineering

4.79/5 (6 votes)
30 Oct 2015CPOL3 min read 16.1K  
SQL Server Data Tools to Visual Studio 2013 - Database Reverse Engineering

Introduction

Database Cycle Management is hard.

Microsoft created SQL Server Data Tools for Visual Studio 2013, to make development easier.

  • Single Tool to support developer’s needs
  • Can build, debug, test, maintain, and refactor databases
  • Developers can use familiar Visual Studio tools for database development
    • Code navigation, IntelliSense, C# language, platform-specific validation
      • Debugging, and declarative editing in the Transact-SQL editor
  • Works connected or disconnected (Tools work on top of design time)
  • Have Schema Model differencing capabilities (Compare and Update Model)
  • Schema and app under TFS control
  • Publish to all supported SQL platforms

STEP 1 - Create Project

Select SQL Server Database Project Template and call it DemoSSDT.

An empty project will be created.

Image 1

STEP 2 - Import Database

After the project creation, we need to import from our SQL Server database.

Select the project and with the right mouse button, select the option Import. The import could be made from three different options. In this demo, we will choose Database, since we have an existent SQL Server Database.

Image 2

A new screen will appear to select existent database. In this demo, we use the AdventureWorks2012.

Select the option Start.

Image 3

The import will start.

Image 4

After the import finishes, as we can see, all the schemas from our SQL Server database were imported to our Visual Studio project.

Image 5

STEP 3 - Create Table

Create a new table on DBO Schema call Currency.

Select Add New Item on project solution.

This option will open a new screen with several items divided from categories.

Select the category Tables and Views and choose the option Table. Call it Currency.

Image 6

Create a new table on DBO Schema an name it Currency.

The table was created with Id field pre generated.

Image 7

Create two new fields (Code and Description).

For that on the table designer add two new fields, like in the SQL Server. As you see, the script is automatically created, when we change the designer.

STEP 4 - Refactoring

One of the new features is the possibility to use refactoring.

Select one field on the script tab and with the right mouse button, select the option refactor like on the image below. One of the options is the Refactor option. This option like on the other Visual Studio Project, allows the user to rename in all solution (Functions, Store Procedures, …) the field of our table.

Image 8

STEP5 - Publish

After all our changes on the project, we could in an easy way Publish to SQL Server database the changes made on our project.

Select the project and select the option Publish.

Image 9

Select the target database. On our case will be the AdventureWorks2012 existent on SQL Server database.

Choose the Publish button.

Image 10

On the output window, we have access to result of our publish. One of the options give access to the script generated. If we click on it, we will see the script generated like we see in the image below.

Image 11

On the left tab, as we can see, the Currency table was published to our database, with the three fields created.

Image 12

References

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)