Can we use GIT as the source control for sql management studio?
-
Don't know about git, but we are using VisualSVN for source control SQL Server scripts. – juur Sep 26 '10 at 14:09
-
What did you end up doing? It seems straightforward to track .sql files, whether in SMSS or MSVS, but what about solution and project files? – tggagne Jan 10 '13 at 18:14
-
@tggagne currently what I did, is I track the sql scripts both the old and new one on a file system and track those files with GIT. I hope that are better way to do this on MS SQL management Studio. I am quite surprise that Microsoft do not provide this. I believe it will be easier for everybody, if they have the ability to track the changes of the stored proc and views or functions in MS Sql management studio it self. – Daniel Mahadi Oct 31 '13 at 18:56
-
1Anyone notice that using SSMS's default encoding of UTF-16 won't let you use git diffs? – NReilingh Oct 11 '14 at 21:53
-
We've been using a third party product by red-gate for years. It does integrate limited git into management studio. By limited, for example, you cannot commit sql changes along side other code changes easily. Also, it seems to slow down significantly on larger dbs. see: https://www.red-gate.com/products/sql-development/sql-source-control/ – Jens Frandsen Jun 24 '16 at 18:32
-
1In my opinion, this question absolutely *does not* violate Stack Overflow guidelines and should be opened. The OP is not seeking recommendations for books, tools, software libraries, etc, but asking about the capabilities of a well-established tool used by virtually every programmer. The question's high score indicates that the community sees it as a good, relevant question. – Michael Haddad May 18 '22 at 16:22
10 Answers
for Database source control within SSMS
Agent SVN - SCC Subversion Plug-in. http://www.zeusedit.com/agent/ssms/ms_ssms.html
or
http://www.red-gate.com/products/sql-development/sql-source-control/

- 4,272
- 4
- 30
- 34
I’ve found out that ApexSQL has a tool that natively supports Git as a source control system. It comes as a SSMS add-in, and offers a wizard you can use to map database objects with the source control systems. To do that:
- Download and install ApexSQL Source Control
- Start SSMS and in Object explorer select the database you want to be linked to a source control
- Right-click the database, and form the context menu, select the Link database to source control option, from the ApexSQL Source Control submenu
- Select the source control system (in your case it is Git) and choose from 2 database development models - shared or dedicated. Shared model is recommended when you link a database on which multiple developers will work at the same time
- Filter objects which you don’t want to track using source control: by schema, type or name by schema, type or name
- Provide appropriate login information and repository string. For Git it is:
<protocol>://<hostname>:<portnumber>/<Git server name>/<repository>
(see example below):
More detailed step-by-step instructions can be found in this article: http://knowledgebase.apexsql.com/link-database-source-control-system-2/

- 181
- 2
- 3
Try sql-source-control
, a free and open source CLI used to get SQL into source control systems like Git.

- 91
- 2
- 4
-
This is an impressive initiative but this package cannot be used cause of the bug when index has multiple attributes – bugwheels94 Jan 10 '19 at 00:20
Microsoft has released SQL Operations Studio. It's a free tool that runs on Windows, macOS, and Linux, for managing SQL Server, Azure SQL Database, and Azure SQL Data Warehouse; wherever they're running. It comes with native GIT support.

- 2,615
- 3
- 26
- 30
-
2Currently called Azure Data Studio. It inherits its native GIT support from Visual Studio Code. Correct me if I am wrong but it doesn't version directly your selected (database) Stored Procedures, Functions, .. to git repo. It is using its git support for plain files. – Vaclav Elias Oct 08 '18 at 15:11
-
1Correct it uses plain files, it doesn't support native database versioning. – Derrick Bell Oct 08 '18 at 17:36
-
I gave it a try. It has a promising future, being FOSS in active development with free extensions, while SSMS add-ons are almost always pricey. Unfortunately, for source control, it is much worse than generating scripts in SSMS and using source control externally as I'm doing now with git-gui. In ADS, there is no way to export multiple objects at once to individual files where even the built-in source control can read them. Each object must be opened as script, then go to Explorer and right click the open editor to save as file, then add to source control. – Pilot_51 Sep 11 '19 at 15:12
-
They have made some more progress on it as of 2021, but have a huge backlog. Again, promising future, but nowhere near capabilities SSMS has. – spencer741 Feb 16 '21 at 05:23
-
-
@MC9000, Azure Data Studio works with lots of relational and NoSQL database, including SQL Server, Azure SQL, Oracle, MySQL, Postgres, MongoDB. There are free extensions for all sorts of stuff. – Bryan Williams May 26 '23 at 13:04
You could add Git Bash as an External Tool (Tools | External Tools...):
- Name: &Git (use
&
to specify a hot key) - Command:
C:\windows\SysWOW64\cmd.exe
(32-bit Command shell) - Arguments:
/c ""C:\path\to\Git\bin\sh.exe" --login -i"
Finding the path where Git is installed on a Windows system - Initial directory:
$(ItemDir)
-
-
15I assume this doesn't magically make Git able to track SQL objects as if they were files. Can you elaborate on what this actually does? – MarredCheese Apr 19 '17 at 19:56
Red Gate SQL Source Control has been updated to include Git and Mercurial support (as well as Perforce and TFS). Be forewarned that their DVCS integration is not 100% feature complete in relation to their SVN product, as basic features such as viewing history of an object are not supported from within SSMS. This may be a deal-breaker if other Red Gate tools like SQL Compare are part of your workflow.
Our workaround was to install TortoiseGit or GitExtensions and navigate to the repository on disk to drill into the specifics. It works but is a bit clunky.

- 46
- 3
Since SSMS is (more or less) a custom version of Visual Studio, you might be able to use a solution intended for VS:
Alternatively, manage your DB source code in Visual Studio from the beginning, not in SSMS. That way (at least in VS2010) you have database projects, integrated deployment and unit testing etc. Or continue using SSMS and check in your code from an external tool when you're ready (not so convenient, of course).
But it depends on exactly what you're doing: SSMS is a DBA tool, VS is a developer tool. Either way, you should be using some form of source control, but it's not clear from the question exactly what sort of files you need to version.
VersionSQL is an SSMS source control add-in I've designed to be lightweight and easy to use. In the Object Explorer panel, just right-click on a database or object and click Commit. VersionSQL will script it out to Git/SVN in a neatly organized folder structure.
Check it out at https://www.versionsql.com

- 645
- 6
- 14
-
I prefer this answer because it easy to use, built in ssms and relatively cheaper... – Zvi Redler Aug 07 '23 at 11:09
Not yet but if you go to http://redgate.uservoice.com/forums/39019-sql-source-control/suggestions/537681-add-git-support and vote for redgate to add support for git it might get added in the next version. Yes I know it's a commercial product but some products are just good enough to pay for!

- 6,179
- 4
- 40
- 64
There have been a number of answers around this question which you might want to look at but in a nutshell ....
The nature of version control is to store the original file and then the deltas, the difference between the original file committed and and subsequent changes (ok i have made that a bit simpler than it is perhaps) and then to manage the version number and give tools to extract any particular revision you need. This also then allows you to compare previous revisions and roll back (etc. etc.)
The RDBMS is made up of the schema and the and data these change and can change frequently in the case of the data so even if you did VCS what would you compare to do a restore and how would that help? Assuming you have a live system then reverting to an earlier revision would lose all the data stored in the interim and although i have never tried it i suspect could destroy the general integrity of the RDBMS.
The better solution is to use a backup application built for that RDBMS, MySQLdump say in the case of MySQL which makes a snapshot of the data and the structure of the data and store that in a safe place.
Dumps can be scheduled regularly and you can do things like master/slave databases (or other strategies) so you can backup live production databases on the fly without impacting on performance

- 6,652
- 7
- 36
- 42
-
2I believe the OP is asking about source control for DDL and scripts, not how to backup a complete database. – Pondlife Sep 26 '10 at 11:52
-
Yes looks like it my apologies, so he is asking how to source control an application? – PurplePilot Sep 26 '10 at 12:13
-
1it's also not true that the nature of version control, in general, is to store the original file and then the deltas. that's not how git works, for one. – asymmetric Jan 12 '11 at 10:33