How to debug SQL Databases
Tags: sql, database, tutorial, architecture
Published: 2019-04-06 12:29:33

---
title: How to debug SQL Databases
published: true
description: #sql #database #legacy #architecture
tags: #sql #database #tutorial #architecture
---

This post was part of a series talking about How to create a good architecture for SQL Databases:

|[How to versioning SQL databases architecture using GitHub and Visual Studio](https://dev.to/lleonardogr/how-to-create-a-scalable-architecture-when-the-businessdomain-logic-is-in-the-database-2bko)|
|---|
|[How to organize SQL legacy Databases](https://dev.to/lleonardogr/how-to-create-an-evolutive-architecure-from-legacy-databases-pt-2-2df9)|
|**How to debug SQL Databases**|
|[How to migrate SQL databases to a new version](https://dev.to/lleonardogr/how-to-migrate-sql-databases-to-a-new-version-server-58mc)|

First, we set up an environment for database version control, then we work on creating a new framework to organize the code we created on the server, now let's talk about another feature that we can use in our databases to us Help, **debugging**.

### Debugging in Database

That part was weird to me because I've never seen anyone debug in a database for the obvious reason: **The debug mode is much less performative**. But, debug is a tool that most programmers do not live without now, and I think I could not solve 90% of problems with programming if I had not debug. A Microsoft [article](https://docs.microsoft.com/pt-br/sql/ssms/scripting/run-the-transact-sql-debugger?view=SQL-server-2017) explains very well the walkthrough to have this feature on your SQL servers. 

So, how to bring such an important resource to databases without compromising performance?

### Strategy: Prepare multiple environments
<img class="WP-image-233 aligncenter" src="https://encaixandoblocoshome.files.wordpress.com/2019/04/0_ubwa5aqwxqqp17gf.png" alt="0_uBWA5AQwxqqp17Gf" width="455" height="219" /> 

Separate development environments when we talk about systems, companies already adopt the idea of having development, homologation and production environments. These environments allow us to make a transition from new functionalities in a less problematic way, even though the deliveries are somewhat bureaucratizing. With the development environment, we can work freely in the debug of apology currencies and jobs quietly, only this will already help a lot the work of scheduling new features and doing maintenance on possible bugs. An article in
[Medium](https://medium.com/venture-garden-group-technology-blog/effective-development-environments-development-test-staging-pre-production-and-production-environmen-a3a85cd349b2") explains this process very well.

#### Synchronize production data with the development 

It Is important to remember that we need the data updated with the development environment if we always want to have the best real proof of new functionality or the errors our base may be experiencing. This synchronization can be instantaneous or scheduled but if possible have it prepared.

#### Adding another database to my infrastructure can be very expensive

Nowadays, robust databases do not have a few bytes of information, on the contrary, the largest technology companies are playing with PETA bytes of data, making transfers and analyses in real-time and massively. With our current scenario, having disk space in a robust infrastructure to develop software, it can be very expensive, even more, if we want to have environments as close to production as possible. But the local infrastructure to work with the database is becoming something much cheaper as it spends the years. Open-source infrastructure, storage, and data processing Solutions are increasingly appearing in the world. Database-specific cloud computing Solutions then dropping to the public's liking so enabling you to work with more resources. So spend some time analyzing how to align the cost of your infrastructure so you have multiple environments.

These suggestions, plus the other parts of this article, you will have a much more robust and prepared environment for the organization routine, less prone to failure and more organized.