Click here to Skip to main content
13,198,563 members (43,298 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

17.4K views
4 bookmarked
Posted 2 Aug 2011

Creating a Database Project From An Existing Database

, 2 Aug 2011
Rate this:
Please Sign up or sign in to vote.
How to create a database project from an existing database

Here is my second article about the database project. This time, we’ll talk about the case when the project is already started and where database scripts are managed manually.

Imagine, you arrive at a project and somebody explains to you how to use the script file. You have to be careful about where you paste your script in the big file. You must check that all the tables you need are created before your part of the script is executed…

Seeing this, you talk about the database project that allows to manage all of these things alone, but somebody tells you: “Oh! I don’t know that and it’s too late, we already started the project, it would be too long to refactor all the script.”

You can answer: “It’s not too late, the database project will generate all the scripts automatically, synchronizing from the database”. Here is how to do it!

First, we open Visual Studio and we create a new database project as described in the previous article. We have our empty project created and we will know how to update it with the existing object in the database.

Go to the menu Data -> Schema Compare -> New schema comparison. A new window opens where we can select the source database and the target VS project to update:

On the left side, Source Schema, select Database and configure the connection string. On the right side, Target Schema, select Project and find the project in the list.

If you want, you can tell to the project not to synchronize some type of objects of the database. For that, go to Options:

When we have to configure all the options we want, we can launch the comparison. We obtain something like that:

We can see here that tables will be created and going down in the Columns directory, we see that columns will also be created. In the second table, we can see that a foreign key will be created.

We can also see that the synchronization option can be modified. If we don’t want to create the foreign key, we can select Create and change the value to Skip.

As we are satisfied, we are going to update the project. In the toolbar, we can see the “Write Updates” button. Let’s click it and the project is updated.

After a confirm message, you should see that the operation went successfully. Let’s check! Go to the project and, YEAH! We can see scripts for our two tables and our foreign key. It works!

Now, we know how to create a database project for an existing database. In the next article, we will see how to update this project when the database is modified directly.

License

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

Share

About the Author

Nadege Rouelle
Architect
France France
I'm coding in .Net since 9 years, most with ASP.Net and SharePoint and a little using WPF, MVC, Windows Phone 8 and WinRT technology.
I have learned so much reading others experience and tutorials, or tips so I try to do the same, keeping learning from others of course.
You can also find my blog here : http://sharemstips.wordpress.com/

You may also be interested in...

Pro
Pro

Comments and Discussions

 
GeneralMy vote of 5 Pin
EngBol6-Dec-11 5:37
memberEngBol6-Dec-11 5:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171020.1 | Last Updated 2 Aug 2011
Article Copyright 2011 by Nadege Rouelle
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid