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:

SQL INSERT – Inserting Rows into Database Table (3 methods) + Common mistakes

SQL Command INSERT is suitable for situations when we want to insert entries into the table. Insertion of rows can be done in multiple ways (further description below): You can insert the values that you choose (INSERT INTO … VALUES (value1, value2, …)) You can insert the values into the table using script (SELECT clause… Read More »

SQL Server Creating Email Notification using T-SQL – Database Mail (Part 2.)

In the previous two articles, I covered setting up database mail (gmail) and configuring Change Data Capture (CDC), which is the automatic tracking of changes to a table. So, it occurred to me, why not combine these topics and describe how to use automatic email to report changes to a specific table? This could come… Read More »

SQL Server Create Database CREATE DATABASE + Script

A database is a system of files and objects that are organized and linked within the database through keys. In SQL Server databases, you can find objects such as tables, views, functions, procedures, triggers, and more. Essentially, there are two ways to create a database. The first option is to create the database using the… Read More »

SQL Server DBCC (Database console commands) – Overview

DBCC stands for database console commands, which are commands executed on a specific database. The DBCC command set allows you to perform various administrative operations or queries on databases through scripting, instead of using the graphical interface of Management Studio. To execute these commands, you typically need a high-level role (such as sysadmin, serveradmin, db_owner,… Read More »

SQL IDENTITY (Auto increment) – Automatic value increase, description

IDENTITY is a property in SQL Server that allows for the automatic numbering of records inserted into a table. It creates an automatic increment with unique values without the need for manual insertion of numbers into the table. This function can be utilized with numeric data types, and its typical use is for identifiers and… Read More »

xp_cmdshell – How to Enable cmdshell in SQL Server?

xp_cmdshell is a very powerful procedure that allows you to execute commands via the command-line (cmd) in SQL Server. With cmdshell, you can perform various operations on a Windows server through the SQL platform, such as copying files, creating, deleting, running bcp for data import and export, and more. However, there are significant security risks… Read More »

SQL Server Agent for SQL Express + How to Guide, Task scheduler

SQL Server Agent is a tool integrated into SQL Server that is primarily used for automating and scheduling tasks. Through SQL Agent, you can create Jobs and schedule individual tasks within those Jobs, such as executing scripts, running SSIS packages, using PowerShell, and much more. However, SQL Server Agent is only available in the Standard… Read More »

SQL Automatic Index fragmentation fix in SQL Server + Script

In the previous article (see Index Fragmentation), I described how to detect index fragmentation using a script that utilizes system tables. According to Microsoft’s recommendations, we should reorganize (REORGANIZE) indexes with fragmentation between 5 – 30% and rebuild (REBUILD) indexes with fragmentation above 30%. We will use the script from the previous article and create… Read More »