SQL Server Source Control for Beginners is a presentation about using source control for SQL Server databases. It discusses:
- Common source control systems like SVN, TFS, and Mercurial that can be used to track database changes.
- How RedGate SQL Source Control allows committing database objects and changes directly from SQL Server Management Studio.
- Key features like rolling back changes, maintaining referential integrity, and locking objects while working.
- Demonstrates setting up a database in source control and committing changes.
- Additional tools that can deploy databases directly from source control like SQL Compare and SQL Data Compare.
3. AGENDA
• Source Control Systems
• RedGate SQL Source Control
• Version Controls – SVN, TFS, MERCURIAL
• One or many?
• DEMO
• Video Games
4. Source Control Systems
a definition:
Revision control, also known as version control and source control (and
an aspect of software configuration management), is the management of
changes to documents, computer programs, large web sites, and other
collections of information.
Example history graph of a revision-controlled project; trunk is in green, branches in
yellow, and graph is not a tree due to presence of merges (the red arrows).
License: http://commons.wikimedia.org/wiki/File:Revision_controlled_project_visualization.svg
6. SOURCE
CONTROL
DB state vs upgrade scripts
Greenfields
Existing systems
Static data
Four key stages of the deployment
pipeline
7. Select CI tooling
Automate builds as first step
o Incremental
o Complete
Create build Artefacts
CONTINUOUS
INTEGRATION:
FUNDAMENTALS
Four key stages of the deployment pipeline
8. Write tests
Automate tests
Fast test cycles
Team disciplineCONTINUOUS
INTEGRATION:
ADVANCED
Four key stages of the deployment
pipeline
9. Testing
Automation
Safety
o Backups
o Rollback strategyAUTOMATED
DEPLOYMENT
Four key stages of the deployment
pipeline
10. Database Lifecycle Management Series
1. Database Source Control
with Redgate’s SQL Developer Suite
2. Database Continuous Integration (CI)
with Redgate’s DLM Automation Suite
• Automated builds and tests
3. Automated Database Deployment
with Redgate’s DLM Automation Suite
14. SQL SOURCE CONTROL WORKS WITH
or any source control system with a command line
RedGate SQL Source Control
15. Deploy your database straight from source control
• Avoid errors and stop those 4am deployments
• SQL Source Control gives you an alternative: deploy from a canonical version of
your database in source control. You’re working with a stable version, which
cuts the risk of deploying incomplete or incorrect changes.
• Deploy straight from your repository with SQL Compare Pro
• You can deploy directly from your repository with SQL Compare Pro. It writes a
deployment script for you in minutes, making your release safe and efficient. You
can use it to generate rollback scripts too.
RedGate SQL Source Control Deploy Features
16. Source control at your fingertips inside
SQL Server Management Studio
• It’s easy to record and share your
code changes, because SQL Source
Control runs inside SQL Server
Management Studio.
• You don’t have to stop what you’re
doing or pass round handwritten
change scripts.
1st of Six Source Control Key Features
Source control at your fingertips inside SQL Server Management Studio
17. Source control your schemas and
reference data
• Store and share any SQL Server
object and static data. Committing
and updating takes two clicks in the
Object Explorer.
• To see what’s new, you can check
changes down to the individual
lines of SQL, with highlighted
differences.
2nd of Six Source Control Key Features
Source control your schemas and reference data
18. Roll back any changes you don't want
• It’s simple to roll back and resolve
conflictsfrom the Object Explorer.
• This also gives you a risk-free
sandbox. If you want to experiment
on your database, go ahead. You
can undo any changes you don't
want to keep.
3rd of Six Source Control Key Features
It's simple to roll back and resolve conflicts from the Object Explorer.
19. Handles referential integrity for you
• When you commit or update, SQL
Source Control maintains the
referential integrity of your
database for you.
• It works out the right order for your
changesand even deals with keys
and constraints.
• It uses the same engine as SQL
Compare, the world’s most trusted
tool for syncing database changes
• .
4th of Six Source Control Key Features
When you commit or update, SQL Source Control maintains the referential integrity of your database
20. Work on a central database or your
own local copy
• You and your team can work on a
shared database or each use a local,
dedicated copy.
• SQL Source Control supports both
models for database development.
• Either way, it helps you share
code, avoid conflicts, and see who’s
doing what, so you can work
without treading on each other’s
toes.
5th of Six Source Control Key Features
You and your team can work on a shared database or each use a local, dedicated copy
21. Lock objects you're working on
• You can lock the object you're
working on in SQL Server
Management Studio with just one
click, so your changes are safe from
being overwritten.
• Your team can see what's locked, as
well as information on who locked
it.
6th of Six Source Control Key Features
Exclude objects with filters
22. • Source control for schemas and data
• Push and pull database changes in SSMS
• Check development history and access specific database versions
• Store and share scripts to handle complex changes, such as column splits
• Undo SQL Server changes
• Exclude objects from source control using custom filters.
• Supports SQL Server on Amazon RDS
• View SQL differences between objects in a database and source control
• Work with SQL Compare and SQL Data Compare to deploy databases directly from
source control
RedGate SQL Source Control
23. Reuirements
• SQL Server Management Studio
• 2005 (RTM, SP1, SP2, SP3, and SP4),
• 2008 (RTM, SP1, SP2, R2, R2 SP1, and R2 SP2),
• 2012, 2014 or 2016 (almost)
• Windows Server 2008 R2, Windows Server 2012, Windows 7, or Windows 8/8.1
• .NET Framework 3.5 or later
• MDAC 2.8+
• If you're using Team Foundation Server, you also need a compatible version of Team Explorer.
Supported SQL Server versions
• SQL Server 2005 (RTM, SP1, SP2, SP3 and SP4)
• SQL Server 2008 (RTM, SP1, SP2, R2, R2 SP1, and R2 SP2)
• SQL Server 2012 (RTM), SQL Server 2014 (RTM)
• SQL Source Control doesn't support SQL Server 2000, SQL Express, SQL Azure or SSMS Express.
RedGate SQL Source Control Requirements
24. RedGate SQL Source Control Permissions
The permissions required to use SQL Source Control depend on your version of SQL Server and the objects in your
database schema. If you have insufficient permissions, some objects may be missing from the change list. For
example, user defined types may not be listed if you don't have permissions for the schema they belong to.
• dbo permissions for the database you want to link to source control.
• sysadmin permissions to commit or retrieve encrypted stored procedures.
Additionally, if you're using SQL Server 2008 or later, we recommend:
• SELECT permission for the system viewsys.sql_expression_dependencies. You may experience poor
performance if you don't have this permission.
• VIEW SERVER STATE permissions to commit or retrieve some encrypted objects
25. • SubVersion - control source system
| LINK: https://subversion.apache.org/
• Free Repository
| LINK: http://bettercodes.org/
• Paid Repository
| LINK: http://cloudforge.com/
| LINK: https://www.assembla.com/subversion/
• Tortoise SVN - SVN client
| LINK: http://tortoisesvn.net/downloads.html
Version Control – with SVN
28. • Mercurial – control sources system
• | LINK: http://mercurial.selenic.com/
• TortoiseHg – client
• | LINK: http://tortoisehg.bitbucket.org/
Version Control – working with CMD
32. • Team Foundation Server – control sources system
• MS Team Explorer – VS client
• | LINK: http://msdn.microsoft.com/en-us/vstudio/ff637362.aspx
Version Control – working with TFS
34. Six steps:
• create database
• connect database to TFS/SVN/GIT {source control}
• commit objects
• get last version from TFS/SVN/GIT {source control}
• change code
• commit change to TFS/SVN/GIT {source control}
Version Control – always in six steps
39. Version Control – excluding
• Get latest
Updates the local working folder with latest version in source control.
• Commit
Commits all changes in the local working folder to source control.
• Add
Adds new files to the local working copy. Changes can then be committed to source control using the Commit command.
• Edit
Makes the local working copy of the files available for editing. Changes can then be committed to source control using the
Commit command.
• Delete
Deletes the files from the local working copy. Changes can then be committed to source control using the Commit
command.
• Revert
Undoes changes if an error occurs during a commit.
40. Version Control – historical data
We can:
• look into the logs
• capture changes in SSMS
You can't view history for databases linked to
• Git
• Mercurial
• Working Folders
43. We can exclude tables when we don’t use special type of table in our development.
Effect of this action – we don’t see those tables after operations:
• Commit Changes
• Get Latest
• Undo Changes.
Version Control – config files
46. • The key to avoiding database version control problems by Amy Burrows
• http://www.red-gate.com/blog/object-locking
• Locking objects in SQL Server by Amy Burows
• https://www.simple-talk.com/blogs/2015/09/03/locking-objects-in-sql-
server/?utm_source=twitter&utm_medium=social&utm_campaign=sqlsourcecontrol&utm_content=v4simpletalkreleaseblog_aburrows
• Public Git hosting sites
• https://git.wiki.kernel.org/index.php/GitHosting
• White Papers:
• http://www.red-gate.com/products/sql-development/sql-source-control/learn-more/white-papers
• Case Study video of SQL Source Control & Continuous integration:
• http://play.buto.tv/yhkvl
• Product Manager& Developer session on Top tops for Continuous Integration:
• http://play.buto.tv/TzmXD
To learn more, go here…
50. To learn more, go here.
Learn a new Database Lifecycle Management skill in one day
Want to take your next step in Database Lifecycle Management?
These one-day workshops will teach you everything you need to
get started with:
•Database Source Control
•Database Continuous Integration
•Automated Database Deployment
Each one’s available as a public workshop or on-site.
If you'd like to book something on-site, contact us.
http://www.red-gate.com/training/
51. Raffle for the end…
KoprowskiT@windowslive.com
I want SQL Developer Suite because…
53. SQL Saturday #434 Holland {Utrecht}
Pre-Conference Full-Day Seminars
PASS Nederland | Vianen, Nederland | Friday 25 september 2015 van 09:00 tot 17:00 (CEST)
• Tobiaz Koprowski - WASD-A Journey from Zero to be Hero - Level 200
• Dejan Sarka - Data Mining Algorithms in SQL Server, Excel, R and Azure ML - Level 300
• Hugo Kornelis - Understanding Execution Plans - Level 400
Free Full Day Conference
PASS Nederland | Vianen, Nederland | Saturday 26 september 2015 van 09:00 tot 17:00 (CEST)
54. Durf jij ook? Schrijf voor ons magazine of
spreek ook op een volgend SDN event!