What is the usual methodology for using Git when developing in SQL Server (stored procedures, triggers, etc.)?
-
Thanks for your answer. The question refers to using git (the versioning system) to version control and collaborate on SQL development. Since SQL files don't have an effect until they are compiled as DB objects, it's not straightforward to me as to how to employ git. What is the customary methodology to use git? How are variations in table structure managed, as well?
-
Answer:
You need to think beyond version controlling individual files to how you are going to version control and manage your database schema in production, development or staging environments. You could consider your stored procedures as schema elements, or related to the schema. So the issues are around managing change control of your schema elements as you need to update them for new software releases, data changes and bug fixes. Consider your database schema as having a version level. So you have deployed schema v1 and you are developing v1.1 which is going to have some updates to tables, views, stored procedures etc. Schema v1.1 is going to be some sort of 'change set ' applied on top of v1. You can manage this with some tools like Liquibase (http://www.liquibase.org) or Flyway (http://flywaydb.org). The Liquibase tool allows you to manage the change sets as XML configuration for example, referencing stored procedure definitions as SQL files. So these would be the files you would be committing to Git or any other source control system in a specific directory structure you need to define for the database release change sets. These tools typically have a way of tracking which changes have been applied to the database and only updating what is required, using tables they create in the database to track this. They can also output the updates as plain SQL for a DBA to review prior to deployment. Once you have this in place you can look at running tests in a CI tool such as Jenkins to automatically deploy the schema updates into a Dev or Staging database environment and run tests to smoke out any issues arising during development. We used Liqiuibase on a project I worked on and it made deployment of schema updates much more predictable replacing an ad hoc manual process that was prone to error. We also ran unit tests against all our stored procedures using Groovy, Gradle and JUnit.
Bill Dennis at Quora Visit the source
Other answers
In addition to using Visual Studio Database Projects, you could also look to a third party product like Red Gate SQL Source Control. That works with git to assist you with managing your database code in source control. Basically, you make the changes to the object in source control, then the scripts are moved into the git repository by SQL Source Control.
Grant Fritchey
I'm not sure what you mean by methodology in this context. If you're referring to a way of organizing your programmable objects in a file structure than I'd have to say that they best way is probably the layout of a Visual Studio database project (http://candordeveloper.com/2013/01/08/creating-a-sql-server-database-project-in-visual-studio-2012/). Even if you don't use VS their file layout makes a lot of sense and is worth mimicking. VS studio can reverse engineer a database through a schema comparison. Else, you can use a small script to pull out all the objects with SMO - http://msdn.microsoft.com/en-us/library/ms162557.aspx
Mordechai Danielov
I think ApexSQL and Redgate are very good and mature... but they are quite expensive when you want to collaborate in a multi developer environment. i.e. 10 users. I have just launched gitSQL. - http://www.gitsql.net gitSQL is a *free front end GUI for scripting out SQL objects into Flat File for use with Source Control such as GIT. *free version limited to 4 objects per type. Types are stored procedures, tables, functions and views. The licensed version is cheaper than ApexSQL and RedGate. * Redgate = $399 * ApexSQL = $299 * gitSQL = $40 What you get for $40 is unlimited objects Export/Import between SQL Server and Flat file (Source Control). Here is an article which describes how to source control SQL Server. http://gitsql.net/documentation-04_SQL_Server_and_GIT
Anup Saund
Related Q & A:
- Can I create a second filestream container on an existing SQL Server 2008 database without going offline?Best solution by Database Administrators
- How to connect Sql Server Database from android app?Best solution by Stack Overflow
- How to upgrade sql server express 2005 to 2008R2?Best solution by Server Fault
- What is the best practice for free space for a SQL server database drive?Best solution by Database Administrators
- How do I connect to SQL Server using C#?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.