I have a database ready which I am maintaining manually, I would like to now use that database to create an SQL project. I am creating also but not able to import the existing Tables, Views, Stored Procedures or any other object. Is there any way to do it. If yes please let me know.
Thanks,
Piyush
Using the Database Edition of Visual Studio (not to be confused with the older 'Database Project') you can generate a complete set of scripts that can be added to source control. Data and schema comparison tools are also included.
This tool was originally known as 'Data Dude' and is available for Visual Studio 2005 and higher.
I'm not aware of any reverse-engineering support for databases in Visual Studio.
What you need to do is script out your existing SQL database into *.sql files from SQL Server Management Studio:
and then import those as "Create Scripts" into your database project in Visual Studio. Any further changes can be added as "Change Scripts" to your project.
Related
SQL Server 2008 provides a solution explore. I have an existing database with many stored procedures, triggers, functions, views.
So I want to all those scripts and DDL can be maintained like .NET codes with Visual Studio connect to TFS.
How can I do this?
If you are using Visual Studio 2010, you can create a Database project, import the DDL from your database into the project, then commit to source control like any other project.
I enjoy using SQL Server Management Studio for change and updating my database. Its easier, faster, and safer than writing changes myself.
I was looking into using some sort of version control for databases and read about using a SQL Server Database Project in Visual Studio 2010.
I scripted out an existing database and imported it into a new SQL Server Database Project. Now, from what I can tell, there is no GUI to edit the database; I can't add columns, change datatypes, or edit existing data without scripting it myself. For instance, in SQL Server Management Studio I can right click on a table-name and select "Design" and then add/edit columns, change datatypes, etc from there.
While Visual Studio's Database Projects has some features SQL Management Studio does not have I don't think I can live without a "table designer".
Is there a table designer built into VS's Database Project I'm just not seeing?
No, there's no table designer.
If you're starting to think about version controlling your database, you ought also to be thinking about writing actual SQL to implement your database objects. That's the route that the Database Projects force you down. If you can't write the SQL for your database changes, how are you going to be able to review and appreciate a diff between how a table was 6 months ago, and how it currently is in your project?
I've been using VS2008 Database Projects for about 10 months now for our version control. Every now and then I do still use the table designer, it is a quick and easy tool. I believe the majority of your question centers around workflow as this is what I found to be the most challenging part about development in a version controlled environment. I would recommend continuing to design your objects in Management Studio or however you're comfortable and then do a create script and import that script into your Database project. There are some quirks when doing this, you'll need to always script the create statement even if you're performing an alter in your environment. As well you'll need to remove any USE statements for your database as the context in which you're importing your scripts will always be in the project you're importing to.
We have found that a successful workflow for us to facilitate code deployment is to have a production branch which is branched to a Main (development branch) and then to test. All new development is done in Main and merged by changeset to each other environment as required.
You can import your scripts from your development environment by right clicking in the solution and clicking import scripts. I recommend that you check all the options to overwrite objects that exist, import extended properties and import permissions.
After changing your DB schema using SSMS's GUI tool, you can use Database project's Schema Compare tool to update your project files (set the source to be your database and target to be your project). This way you can keep using GUI tool to manage the schema and the database project will manage the versioning.
There is no visual table designer in Visual Studio 2010 Database Project. But, concerning version control for databases, there is a workaround - you can use SQL Server Management Studio together with Red Gate's SQL Source Control. It costs some money but definitely is worth it.
I have a database in my sql management studio how can script the database schema to file so that I can put it in another device?
thanks
Open SQL Management -> Script Database As -> .... I think its the closest to what you mean.
Of course there are 3rd party tools for these kind of works. See RedGate.
Shutdown SQL Server, copy the MDF and LDF Files to a new server and attach them on that instance by right clicking on Databases and choosing Attach. Specify the location of the files.
Alternatively, you could also backup the database from the source and restore it in the destination.
The above two methods copy all data too. If you want only the schema, Right click on the database and choose Generate SQL Scripts and follow the instructions.
SQL Management Studio 2008 can make query to unload Schema and data from database, but older versions if Management studio can't do it. You can use another soft to do it like an EMS SQL Management studio
I just installed VS 2010 for the purposes of running someone else's DB project that was created using the 2010. In VS 2008 I was able to right click on a SQL file ans select "Run ON" to run the script on a given SQL Server. I don't see this option in 2010. Is it available and if so how do I get access to it?
The database project format that was included in VS 2005 and VS 2008 has been completely removed in 2010.
Rather than holding loose SQL files that could be run independently, it acts a bit more like a compiler. When the project is built, the SQL files are parsed and (for the most part) turned into an XML-description of the database schema.
If you're trying to create or update a database based on all of the scripts in the project, right click on the project name in Solution Explorer and select "Properties". Under the Deploy tab youchange "Deploy Action" to "Create a deployment script and deploy to the database". Specify the connection settings and database name.
When you select "Deploy" on the right-click context menu of the database project, Visual Studio will build the database deployment files and generate the database. It's generally intelligent enough to update existing databases as well, assuming the project was designed well.
If you're attempting a remote deployment to a production SQL Server, things get a bit trickier. There is no single set of SQL files you can run - part of the database schema is stored as XML.
Take a look at Link - it describes how to use the "vsdbcmd.exe" utility to deploy a database file.
If you just want to run a single SQL file or test part of one, open the file, right click, and select "Execute SQL"
DNRTv # 167 talks about VS 2010 Database Projects in detail.
As #ShadowChaser already mentioned, DB Project in VS 2008 simply had the scripts in it, and 2010 version is a lot more complex and has a lot more features.
By using VS TFS Database Edition 2008, how to create dbproject from an existing SQL SERVER database?
This as updated in VS 2010. There is now the option to "Import database objects and settings" from the project context menu.
In "Visual Studio" go to the "SQL Server Object Explorer" locate to database, right-click on the database you want and select "Create New Project ..."
There no direct, built-in support to do that, unfortunately.
You can get close by doing this:
in SQL Server Management Studio, go to the Object Explorer, right-click on the database you want, and pick Tasks > Generate Scripts
select all the database objects you want to script out
at the end, choose to generate the scripts into separate files for each db object
What you end up with are a number of .sql scripts in a folder of your choice, which basically represent your database.
Next:
create a Database Project in Visual Studio 2008
once you've done that, add the existing scripts to that project
It's a bit more involved that it should be - but that's the only way that I know of to achieve this right now. Don't know if VS2010 will support this in an easier way....