Python & SQL Server: Manage Database Transactions

Intro In our last post we used SQLAlchemy to bulk load data into SQL Server. Now that we can bulk load data we want to perform other actions on our database. In todays post we want follow a common loading strategy and TRUNCATE the target table before loading it. Adding this functionality to our script leaves us with a choice to make in how we want to execute our SQL statements and manage database transactions. ...

January 14, 2024 · 2 min · Chris Albert

Python & SQL Server: Bulk Loading Data

Intro You have a bunch of data and need to load it into SQL Server using Python. With the abundance of options out there its difficult to know what the best tool is to use. Lets approach the problem with two requirements. The solution needs to be easy to implement and blazing fast. Tooling Initially bcpandas looked like a great solution for this task. While it does fit our two requirements, it becomes very difficult to work with for data that contains multiple separators or any odd strings. If the data you work with is like mine it is almost never perfect. I quickly pivoted away from this due to its inability to handle imperfect data. ...

November 19, 2023 · 3 min · Chris Albert

Log Shipping Restore With dbatools

Intro In some scenarios a vendor or other 3rd party will send you a copy of their log shipping backups so you can keep a reporting copy of their database. Today’s post will cover how we can use dbatools to automate the restore process. This post assumes you have already restored the initial full backup and are now at the point where you are ready to automate the transaction log backups you are receiving. ...

May 17, 2022 · 2 min · Chris Albert

How to Configure SQL Server Management Studio for Efficiency

Intro SQL Server Management Studio (SSMS) is a great product. Out of the box SSMS is an awesome tool that many of us have come to know and love. In my quest for efficiency I have found some very helpful settings that can be changed. If you spend most of your day in SSMS like I do, these changes can help you be more productive. Version First and foremost is the version you are running. If you aren’t running the latest version of SSMS go download it now. It’s free! SSMS has received a lot of love from Microsoft over the last couple years. Now updates come out regularly instead of with the SQL Server release cycle. If you are still running SSMS 2005 I’m begging you to go download the latest version and give it a try. ...

April 13, 2020 · 3 min · Chris Albert

Installing dbatools

I had some issues installing dbatools over the weekend and wanted to share my experience. If you have not heard of dbatools I encourage you to go check it out and see what it can do. The easiest method to install dbatools is to open PowerShell as administrator and run the following command: Install-Module dbatools Following the install instructions on the dbatools website and other relevant blog posts around the web the install should be as easy as that. In my case it was not. ...

April 7, 2020 · 1 min · Chris Albert

First 3 SQL Server Settings to Check

You are handed a SQL Server that someone else set up and has, or more likely has not, maintained over time. You are now responsible for this server, but have limited time to check it out because of your busy schedule. What are your first 3 SQL Server settings to check? 1. Backups This should always without a doubt be the first thing you check. If backups are failing or even are non existent, you need to know about it and make it your first priority to fix. Now that this server is your responsibility, the business is going to look at you when the server crashes and they need a restore. Not being able to recover any data is a great way to get fired! ...

July 20, 2018 · 4 min · Chris Albert

CTE: Make Your Data Easier to Query

Ever wish your data was a little different so it is easier to query? Don’t fret, we have all had those queries that are gigantic and become too cumbersome to read through or modify. A CTE, a.k.a. Common Table Expression, can be the savior you have been wishing for. They are great for separating different pieces of your query and performing some tasks before your query runs. To use a CTE: ...

July 9, 2018 · 3 min · Chris Albert

Reset SQL Server sa Password

Once upon a time a vendor set up a new SQL Server at the company I was working for. For whatever reason they decided it best to not work with the local DBA. A few weeks later a server admin emails me asking if I can help out with an issue they were having. He says the vendor has lost the sa password and cannot connect to the SQL Server instance. After having a good chuckle I agreed to help out and reset the SQL Server sa password. Here is how I did it: ...

September 26, 2017 · 3 min · Chris Albert