Visual Studio 2008 Database project Deployment Baseline - visual-studio

I have a question about creating a deployment script using a database project in Visual studio 2008.
In a more traditional project we would create a deployment script that would create the DB and the initial objects for the first deployment. This would become the baseline.
Any additional objects would be scripted as ALTER statements. Each statement would check for the existence of the object, giving a re runnable database deployment script.
I want to be able to do the same thing with the database project, but it currently analyses the database and creates a script to take it from its current state to where the project specifies it should be. This is fine for local deployment, but I cannot use this to deploy to production, as they require a re runnable script that will not loose any data in the live system.
My first idea was to have a copy of the database that matches live, and then point the project to it to generate the statements for the deployment, but it does not seem very maintainable.
Does anyone have any idea about how achieve this?
Thanks

This is done by the Schema Compare option of the Database Edition of Visual Studio.
I Think you could find useful this link:
How to: Compare Database Schemas

Related

How to save a SQL Server Maintenance Plan within a Visual Studio Database Project

Having created a SQL Server maintenance plan in a SQL Server 2008 R2 instance, how can I import the definitions into a Visual Studio 2013 SSDT database project?
I don't mind using pre- and post-deployment scripts if that helps but I want it to be in a database project and to be able to build the project in VS and then to be able to deploy either a new instance of the plan, or to be able to synchronize an existing plan instance with the definitions in the database project. Also, drop and re-create is entirely acceptable.
Does anyone else already know how to do that ?
First of all maintenance plans are not supported by SSDT.
You can export it manually as an xml template file and then try to write some sql/batch post deploy scripts to deploy it.
You can find general instruction here (read comments also): https://robertbigec.wordpress.com/2013/10/03/automating-deployment-of-sql-server-maintenance-plans/
One note: The exported xml template contains some specific values such as server name or path to backup/log file locations. You might want to write custom script to get these values from target machine and replace it in the xml file.

How can I manage SQL Server jobs using a Database project

Does Visual Studio 2010 support managing SQL Server jobs in the Database Project?
I am working with a database project in Visual Studio 2010. I would like to manage my database scheduler job in my database project. It seems that I could not create any server object in the database project.
What we do at my company is:
Script out your jobs to be re-runnable (either drop/create or skip if exists)
Place the scripts in your Post-Deployment folder (and include the reference in your Script.PostDeployment.sql file as necessary)
No, you won't be able to do that. If you want to use Visual Studio to manage database projects you can use the database and server projects (what used to be called Data Dude).
You might also want to take a look at Red Gate SQL Connect. It works with databases and source control through Visual Studio.

Customize deploy scripts for Visual Studio 2010 Database project

The deployment scripts generated by a visual Studio 2010 Database project won't work for me. I need to include them in an MSI that will be shipped to many different customers to both upgrade and create new databases.
Looking through the Microsoft.Data.Schema... namespaces I see many possibilities for customizing the generation of the deployment scripts, DeploymentScriptGenerator, ExtensionManager etc. etc. It really looks like it was designed to be extensible and to support any database.
What I can't find is any sort of "getting started" documentation or samples. Has anyone done something like this?
Visual Studio Data Projects use two phases of deployment.
The deployment files created by building the database project is really just a package of metadata that describes the desired final state of of the database, but with no knowledge of where is going to be deployed or whether it is a new database or existing database.
The second part is actually executing the deployment package against a specific database, either existing or new. To do that, Visual Studio has to run a diff against the database and the deployment package, and determine which changes need to be applied, and generate the script necessary to apply those changes.
So the problem you have is that if you include the first part in your MSI, you need something running on the end user's machine to apply those changes to an unknown number of unknown databases out in the field, and you can't really ship them Visual Studio.
Luckily MS includes a command line too (VSDBCMD.exe) which allows you to take that single deployment package and use it to apply changes to any database. This tool will do the same diff as Visual Studio and generate the SQL script necessary to create/upgrade that database (any actually run the script, if you so choose, based on command line parmaeters). See http://msdn.microsoft.com/en-us/library/dd193283.aspx for information about how to call it from the command line.
So I'd saw you ship that command line tool with your application (just make sure to double check the redistribution license to make sure this is OK) and have a custom action in your MSI (or some other utility) that executes it to apply the database changes. And also check the dependencies for the command line tool, I know it requires the SQL SMO objects, SQL Native Client, and probably a few other things. You'll want to make sure you MSI includes those as prerequisites.

Database in version control using Visual Studio 2010 Professional

I've added a SQL Server 2008 database project to my Visual Studio 2010 Professional Edition solution in the hope that it might allow me to include my database in version control.
I can commit the schema files for each database object into version control, however these schema files all script objects as create rather than alter, so are not good for colleges getting my changes and updating their databases.
Is this a good way to get my database into source control?
And what would the workflow be for actually using it to update databases to a given revision without losing all the data associated with dropping and re-creating all the tables?
Update: on Premium and Ultimate versions, there is a schema compare tool which makes this easy. This does not exist on Professional. Is there any straightforward manual workaround?
I'm not sure if you can do this in VS 2010 Professional, but in VS 2010 Premium, you can do a schema comparison (Data -> Schema Compare -> New Schema Comparison) between your project and database, and update changes in either direction.
When going from project to database, VS generates a script that copies existing data into a temporary table before dropping the existing one.
The database project has a deploy step (which is present in my Professional copy of VS2010) that will generate a sql script with your sql objects in it.
The key thing here is if you r-click the project, properties, goto deploy and change target database settings to a specific database, when you deploy it will generate a change script for that specific database so it matches the objects in the project (and in theory keep existing data etc).
You can get it to either generate a sql script, or directly update the database. Generating a script is probably a better idea :)

Database project deployment

I have database project in visual studio 2010. It has tables views stored procedures etc. I have created a full text index on view and in stored procedure I am using like this:
create proc myproc
as
select * from my view
where contains(tblperson.fname,'Steve')
end
When I deploy, I get error that I can't use contains as view is not full text indexed. I want to know if there is a sequence in which database project is deployed ? means first stored proc is deployed or views are deployed. Can I change this sequence.
Please suggest.
The Visual Studio Database projects are great! I have just migrated from Db_Deploy integrated with SVN to TFS Visual Studio Database projects. The database projects work by creating a self contained db schema file and when you use the VsDbCmd command for deployment, it will do a schema comparison between the project schema and the database schema to generate the delta script for you. The order in which the comparison takes place is Tables, Procs then Views, ...
I would suggest that you apply this script direct on to the database and then use the schema comparison from database to project to soak in the changes. This way the visual studio database project will create the script for you. Read more about the db comparison and walkthrough on msdn http://msdn.microsoft.com/en-us/library/aa833435.aspx.
PS - How are you managing deployments of your db project? I have automated the entire deployment suit, interested to know how others are doing it.
HTH.
Cheers, Tarun

Resources