Category Archives: SQL Tutorials

T-SQL is a language used for working with databases on the
MS SQL Server platform. You can find a lot of articles and tutorials about T-SQL in this section. If you want to learn SQL or just read how to work with SQL function you don’t know yet, check out the SQL tutorials. I want every article to contain an example of usage and a code example too

For Beginners – How to Gradually Learn T-SQL

Below, you will find a basic chronological outline that I would recommend following to learn SQL step by step. Use other resources as well to complement and expand your knowledge. If you thoroughly cover these topics, whether here on the website or elsewhere, it will give you a solid foundation for effective work with databases, automation, BI, reporting, applications, and more. You can lay the foundation for:

Before studying, I recommend installing the necessary tools (in this order) so that you can immediately practice the newly acquired knowledge:

1) Introduction to T-SQL – Introduction, Basic Orientation

After studying these articles, you will get acquainted with the basic syntax of the T-SQL language and build simple SQL queries:

2) Basic SQL Clauses (SQL Clauses Category) – Basic Structural Elements of SQL Queries

After studying these articles, you will be able to independently write simple query scripts for one table:

3) Joining Tables (FROM) – Joining

In a relational database, we typically don’t join just one table but several (in the FROM clause). There are several types of table joins. After studying these articles, you will understand the differences between different types of joins and be able to write more complex scripts by joining multiple tables. In practice, understanding and correctly choosing joins in various situations is probably the biggest challenge when learning the SQL language (moving from a complete beginner to moderately advanced):

4) Introduction to SQL Functions (SQL Functions Category)

After understanding the basic structure of the language, you can see how we can work with data (similar to Excel) through functions. These functions are most commonly used in the SELECT clause. Below are a few examples of the most commonly used functions; you can find more in the relevant category on the website:

5) DDL (Creating, Deleting, Cleaning Tables) and DML (Changing Records in Tables)

Until now, we’ve dealt with what’s called DQL (Data Query Language) – querying. After understanding how to query tables, we can move on to creating tables and commands that either modify or delete records in the table:

6) Connecting Data to Excel or Reporting Platforms

If we can prepare data in the database and efficiently query it, we can then pull the query results into tools like Excel or Power BI:

How to Execute SQL Server Procedure in Excel with Parameters

Right from the beginning let’s be clear. Even though this process is possible, don’t use it as your standard process. Instead use How to Execute SQL Query in Excel – Tutorial with Examples. But I will show you anyway. Processing SQL queries through procedures in Excel is not optimal in general, but sometimes there is… Read More »

SQL Server | Performance optimizing of SQL Queries – 10 Tips with Examples

Performance optimizing SQL queries is an ongoing battle that begins right from the design of the database architecture and server resource scaling. With the right architectural design, many performance issues in the future can be avoided. Additionally, script performance can be influenced by the structure of SQL queries and properly configured indexes. This article is… Read More »

SQL Error – Conversion failed when converting the varchar value to data type int

The error message “Conversion failed when converting the varchar value to data type int” occurs in SQL Server client (for example Management Studio) when attempting to convert a value stored as the varchar (text) data type to an integer data type. This might not be an issue if the varchar contains numeric values, but problems… Read More »

SQL THROW Exception – Alternative to RAISERROR and Differences

Some time ago, I published an article on the RAISERROR command, which raises an exception and allows us to influence whether the script will or will not continue based on severity. The THROW command is an alternative command introduced with SQL Server 2012. THROW Syntax in SQL Server The syntax is simpler compared to RAISERROR.… Read More »

SQL RAISERROR – How to Call an Error and Abort the Script

In certain situations, it’s necessary to call an error within an SQL script and interrupt its execution. Typical scenarios include failing a data quality check or the need to invoke an error within a BEGIN /END TRY BEGIN/END CATCH construct. In such cases, you can use the RAISERROR command or the newer THROW command. In… Read More »

SQL Server TRY CATCH and Error Handling with Examples

SQL TRY CATCH command is designed to control code flow in case that error situation occurs (error handling). This construction consists of  blocks. It is also possible to use transaction (more in article on Transactions). If an error occurs in the first block – TRY..END like that is activated code in CATCH..END block. TRY CATCH… Read More »

SQL UNION ALL – Merge of Queries with Example

Operator UNION ALL in SQL makes it possible to unify 2 query results and does not remove duplicities in queries. Operator returns records of both queries with no regard for existing duplicities. UNION ALL belongs to group called SET operators together with UNION, EXCEPT, INTERSECT SQL UNION ALL Syntax SELECT Column FROM dbo.Table WHERE Condition   UNION… Read More »

SQL UNION Operator – Unification of Sets with Example

UNION operator makes it possible to connect 2 results of query and remove all existing duplicities in them. In other words, operator actually performs DISTINCT (like SELECT DISTINCT) in final unification of records. SQL UNION Syntax SELECT Column FROM dbo.Table WHERE Condition      UNION SELECT Column FROM dbo.Table WHERE Condition; Syntax is same as… Read More »