![Pdf Pdf](/uploads/1/2/4/3/124369816/736795816.png)
Guest postThis is a guest post from Sjors Takes. A Senior SQL Server DBA at Albelli in the Netherlands, Sjors Takes is an advocate of database continuous integration.
An expert in SQL Server administration and performance tuning, he builds database deployment pipelines to make the database delivery process as simple and smooth as possible.A member of PASS, Sjors blogs about continuous integration and deploying databases at, is a regular attendee at SQL Server events, and has also been a speaker at SQL in the City. Guest postThis is a guest post from Sjors Takes. A Senior SQL Server DBA at Albelli in the Netherlands, Sjors Takes is an advocate of database continuous integration. An expert in SQL Server administration and performance tuning, he builds database deployment pipelines to make the database delivery process as simple and smooth as possible.A member of PASS, Sjors blogs about continuous integration and deploying databases at, is a regular attendee at SQL Server events, and has also been a speaker at SQL in the City.Are you interested in version controlling your SQL Server database in GitHub? This article explains some simple steps to create a GitHub database repository and get your database code in there, using.I assume you’re a SQL Server professional and don’t need a deep dive into how source control systems work, nor an in-depth look at version control commands, but you do have a database that is not yet in version control, and you’d like to get started quickly.Is a database repository different than other repositories?No. A database repository is just like any other repository; it’s a folder in which to organize all the files and assets required to build a working project, in this case a database.
At a minimum, this will include the CREATE scripts that define each table in the database, as well as any schema-scoped objects such as views and stored procedures, and so on, plus scripts to insert any necessary static data. Step 1: Create a GitHub accountIf you don’t already have a GitHub account, simply visit the and sign up. GiHub supports 2-factor authentication, so to take advantage of that you’ll need to provide both the usual sign-in details plus a mobile device to receive authentication codes.You’ll be given the option to read the guide to GitHub.
It explains the basic purpose of GitHub, how to create a repository, how to create a new branch, make and commit changes, create a pull request, and then merge changes made on the new branch back to the master branch. It’s well worth ten minutes of your time, though we won’t progress to branching and merging in this article; we use only the master branch. Step 2: Create a database repository in GitHubThe first step is to create the database repository in GitHub, as described in the Hello World guide.
We’re going to put into source control a Customers database, so we’ll call the repo Customers. It will be a public repo, unless you have a paid subscription, in which case you can opt to make it private. Choose the Initialize this repository with a README option, and optionally a file and a license, and hit Create Repository.What we’ve done here is create a ‘remote’ database repository on the GitHub server. We can manage and administer this repository using the GitHub browser, but in the basic mode of working for team-based development, each developer will clone the repo locally, commit changes to the working repo, traditionally from a local working folder, then push changes to the repo on GitHub so that the rest of the team can access them, as well as pull down the changes of others. Figure 1 Step 3: Clone your database repository to your local machineThe next step is to clone the ‘remote’ database repository that we just created to your local machine. For this task, we’re going to use, so you’ll need to download it and install it on your machine.
SQL was a go-to tool when you needed to get a quick-and-dirty look at some data, and draw preliminary conclusions that might, eventually, lead to a report or an application being written. SQL (Structured Query Language) is a language for retrieving information out of relational databases such as Oracle, Informix, SQL Server, Access and MySQL. Planet Source Code has: 374 lines of SQL code. Click here to see: Latest news All SQL categories of code Newest SQL code SQL contest winners.
There are other tools that can perform this task, such as SourceTree, so feel free to use an alternative tool, but I’m not going to discuss them here.Open GitHub Desktop. Clone your Customers repository by clicking on the + sign in the upper left corner and then selecting the clone tab. Select the Customers repository and click Clone Customers. Alternatively, if you’re in the GitHub browser, you can click into the Customers database repository, and then select Clone.Choose the directory to which you wish to clone Customers and you’re done.
Figure 2 Step 4: Install SQL Source ControlGo to the Redgate website and download the trial version of the. There are more tools in the toolbelt, but for this tutorial you only need SQL Source Control.
It’s simply a plug-in for SSMS that allows the developer to commit changes made to a local database directly to a version control repository (in this case, GitHub), as well as update the database with the committed changes of others. Step 5: Create a database and link it to GithubOpen SSMS, and on your local SQL Server instance, create a new database named Customers.Select the database in the Object Explorer and open the SQL Source Control tab (or right-click the database and select Link database to source control). If the SQL Source Control tab isn’t open in SSMS yet, you can open it via Tools SQL Source Control.Select Link to my source control system, Select Git, and then enter or navigate to the folder location for the local Customers repository. Click Link, and your database is linked to your database repository!The database is empty, currently, but nevertheless if you go to the Commit tab, you will see a message that there is a commit in your local repository that can be pushed to the remote repository. That’s because you just linked your database to the repository and SQL Source Control placed a file there ( RedGate.ssc).Enter a meaningful commit message, like ‘ Init‘ and click Push.
You’ll be asked to enter your GitHub credentials and after filling those in, SQL Source Control will push the RedGate.ssc file from your local repository to your GitHub repository.Note that if you enabled 2-stage authentication, you’ll need instead to set up a personal access token in order to authorize communication between SQL Source Control and GitHub. Go to the GitHub browser and in Settings (under your user profile), find Developer Settings and choose Personal access tokens. Step 6: Create database object scripts in the GitHub repositoryWe’ll create a number of tables in the Customer database. The script to do this is available to.Having created the tables, we want to commit the CREATE scripts for each table to the local Customers database repository. Go to the SQL Source Control tab again and on the Commit page click on refresh.
You now see that SQL Source Control detected the changes you just made. Figure 3Enter a meaningful commit message again (for example Create Initial Customers tables) and hit Commit.