Can I integrate SourceSafe / VSS with SQL Server 2005? - sql-server

How are the SQL objects managed with VSS?
Can I integrate SourceSafe / VSS with SQL Server 2005?
I want versioning in my SQL schemas.

Aside from VSS being a total train wreck, if you want to store your schema in source control, one possible approach is to store the object creation script for each database object as a separate file in source control. That way, you can update individual parts of the schema easily. So you have a script for each table, trigger, index, procedure etc. As part of your build process these can be pulled together into a single script for ease of application to the target database.

Utilize tools like SQL Compare from Red Gate which will allow you to create schema, object per file, and then maintain the state of the files with VSS. I am currently trying to push that in my organization.

We've just added Visual Source Safe support to SQL Source Control, providing source control integrated into SQL Server Management Studio. This is in early access at the moment so please sign up for the early access build and tell us what you think.
More detail is available here:
http://www.red-gate.com/MessageBoard/viewtopic.php?t=12265

Related

What are advantages of using SQL Server Database Project in VS 2013?

What are advantages of using SQL Server Database Project in VS 2013?
Currently I dont use this on my project, I am generate script from SQL Server Management.
Should I move to Database Project? How complicated is?
There are many advantage of sql project.
1.Easily deployable in any conditions.
2.You can view history of db objects
3.You can maitain all db objects under on roof.
Effectively, a database project converts all of the objects in your database (table designs, stored procedures) into text files -- text files that can be searched, modified and stored in source control just like your code files. A database project also includes designers for working with these files. Visual Studio cross-references those files to give you a higher level of IntelliSense support for working with stored procedures than you'll ever get in SQL Server Management Studio.
You also get a staging database where you can make your changes before updating your production or development database and a schema comparison tool for determining, after the fact, what changes you've made. Effectively, you get an isolated database environment for trying out database changes.

How to export database schema in Visual Studio 2012?

I am having a hard time figuring out how to export a database creation script in VS 2012. Is this possible?
It depends on what exactly you mean by your question. If you simply want to generate a create database / tables / views / and optionally include data, then you could use sql management studio (express, if need be) to generate scripts (via SMO) and then simply execute your script at runtime, alternatively i think you can generate scripts from the 'server explorer' tool window if you have a registered SQL server.
However, if you intend to version the database schema, and provide schema versioning/data versioning once a database is in place, they you'll want to look at SQL Server data tier applications, which is more of a toolset and libraries for database lifecycle management (buzzword overdrive enabled).
The tooling for VS data tier app projects is wrapped up in the SQL Server Data Tools, which basically adds a slimmed down version of SQL SMS object explorer to the project window when working with database projects, and adds some pretty awesome project configuration capabilities when compared to just executing a pre-generated SQL script at runtime.
If it's not giving you the update or generate script button, go into schema change options, under the general tab, uncheck "Block on possible data loss". Be sure to compare after changing this option.
Additionally, if you want to retrieve all comments from all tables in your database:
SELECT sys.Tables.Name,Value
FROM sys.Tables
INNER JOIN sys.extended_properties ON sys.extended_properties.major_id = sys.Tables.object_id

How to use VSS (or other system) for Database management and version control?

What is the best way to version database objects (Trigger, SPs, and other elements) in VSS in a similar fashion to the way that we store source code in VSS and access it in Microsoft Visual Studio?
We would like to check database elements in and out in VSS or a similar tool so that we can store database objects in a central location, and also so that we can have versioning of database elements, for example, version history of stored procedures.
We currently use SQL Server 2005 as our database engine.
If you are using VS, the easiest way to control your source objects is to create a Database project using the "Database" project template in Visual Studio.
The entire database project can be associated with source control (VSS in your case) and then all your DB object scripts are versioned.
A very important point to note is to make sure that Developers get out of their old habits of directly updating / changing objects in the DB because doing this will not stop them from doing so. An easy way out of that dilemma is to ensure that the DB project is built and deployed periodically(Continuous integration) just like your code is.
This will ensure that if changes are directly done to DB, they will be lost and hence automatically inculcate the behavioural change in developers.
Refer link for a step by step tutorial as to how to get started using a DB project.
Screen shots are for VS2010 but DB projects have been around since VS 2005 and more or less on the same lines. Very easy to use.
If you're willing to use Subversion or TFS, and are using SSMS to make your database changes, Red Gate's SQL Source Control maybe a tool that would work for you.
http://www.red-gate.com/products/SQL_Source_Control/
[Edit]
We've now added VSS and SourceGear Vault support. Try the early access build:
http://www.red-gate.com/MessageBoard/viewtopic.php?t=12265

DB Designer in Visual Studio 2010

I need to create an entirely new Sql Server 2008 database and want to use a Database Project in Visual Studio 2010 (Ultimate). I've created the project and added a table under the dbo schema.
The table .sql is shown only as plain text, though with colors. It has no designer, no Add Column, and no autocomplete. Existing column's properties are grayed out.
Usually, I use DB Project for nothing more than storing .sql files for source control purposes, but I'm assuming it can help me with designing the DB. Currently, it offers no such help and I think it's because I'm doing something wrong. Perhaps I need to deploy the DB to server first, or something of the such. I've looked for a Getting Started guide, but all guides I found start from importing an existing database.
Please help my understand what a DB Project can do for me and how.
Thanks,
Asaf
The whole idea of the VSTS DB is to get you set on the right path, ie. store database object definitions as .sql files, not as some fancy diagram. Any modification you do to the objects you do it by modifying the SQL definition. This way you get to do any modification to the objects, as permitted by the DDL syntax, as opposed to whatever the visual-designer-du-jour thinks you can and can't do. Not to mention the plethora of SQL code generation bugs associated with all designers out there.
The closes to a visual view is the Schema View, which shows tables, columns, indexes etc in a tree view and you can see the properties from there.
By focusing the development process and the Visual Studio project on the .sql source files, teams can cooperate on the database design using tried and tested source control methods (check-out/check-in, lock file, conflict detection and merge integration, branching etc).
the deliverable of a VSTS DB project is a the .dbschema file, which can be deployed on any server via the vsdbcmd tool. This is an intelligent deployment that does a a schema synchronization (merge of new object, modifies existing ones) and can detect and prevent data loss during deployment. By contrast, the 'classical' way of doing it (from VS Server eExplorer, or from SSMS) the deliverable was the MDF file itself, the database. This poses huge problems at deployment. The deployment of v1 is really smooth (just copy the MDF, done), but as soon as you want to release v1.1 you're stuck: you have a new MDF, but the production is running on its own MDF and does not want to replace it with yours, since it means data loss. Now you turn around and wish you have some sort of database schema version deployment story, and this is what VSTS DB does for you from day 0.
You might be better off downloading the SQL Server Management Studio for SQL Server 2008 Express - http://www.microsoft.com/downloads/details.aspx?FamilyId=C243A5AE-4BD1-4E3D-94B8-5A0F62BF7796
Using this tool you can create your database using the visual tools provided by that software. You can run your .sql script to build up the database and then visually adjust columns settings, table relationships, etc.
Once you have your database designed open up Visual Studio and open a connection to this database using the Server Explorer.
Visual Studio is ok for simple tweaks and changes to an existing database structure but for anything serious like making the database from scratch I would recommend using the Management Studio. It's free and built for that exact purpose :)

Scripting individual database objects

I have a database I have inherited, and my best practice is to create the scripts to create the objects (tables, stored procedures and views) and then version control these.
It would like to have all the objects in this database scripted out, and put into source control; but on SQL Server 2005 (SQL Server Management Studio) it appears - at least to me - that the option to create one file per object that was available on Enterprise Manager has not made it through to SQL Server Management Studio.
Am I just not seeing the wood for the trees, or has the option that was there in Enterprise Manager not made it through ?
Does anyone have an effective way to create one script file, named as per the object ready for adding to source / version control ?
In SQL Server 2005 SP2, this is supported. If you select the option, it will give you files named after the objects, but also including the type of the object in the file name.
http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=124774
EDIT
Added link confirming that the change was in SP2.
Here is a link to a CodeProject vbscript that you can use to scripting all the objects of an SQL database on separate files. I have downloaded, modified slightly for my naming purpouses and it works great.
http://www.codeproject.com/KB/vbscript/0g_SqlExtract.aspx

Resources