Category Archives: Useful SQL Scripts

Here you can find articles containing some useful technique or script. For example, automatic optimalization of indexes in the database (rebuild or reorganize), database email settings, various checking scripts, etc.

Don’t miss out from category:

Bulk Copy Program (BCP) Utility – Fast Bulk Import and Export in SQL Server

BCP is a utility that is installed by default with SQL Server editions and is used for bulk import or export of a large volume of data in user-defined formats. This utility is optimized for large data transfers either between SQL Server instances or between a SQL instance and a text file. The utility is… Read More »

SSRS | How to Create an Amortization Calculator in SQL Server – Including a Report with Parameters

Lately, I’ve been dedicating a lot of time to financial mathematics in Excel. I’ll try to leverage that and shift the focus from Excel to SQL Server. Perhaps someone is considering creating an application for amortization calculator schedule where you can input parameters, and it will generate results for you in a table. The result… Read More »

SQLCMD (Server command line) – Run SQL query via cmd

In this short article I will introduce the possibility to run a sql script outside of SQL management studio using SQL server command line utility (sqlcmd for short). This utility allows you to work with SQL server using the command line. The use are obvious and include working with SQL from different applications. How to… Read More »

SQL Duplicates in a Table with an Example – How to Retrieve a List of Duplicate Values?

In some situations, we need to get an overview of the data present in a table. Or perhaps we want to check if there are any duplicate values in the table that we do not want. How can we retrieve a list of such duplicate records using SQL script? How to Identify Duplicate Rows in… Read More »

Basic SQL Queries – Overview For Beginners With Examples

What I have here today is a article for beginners. It will be full of sql query examples. We will start from the most basic ones and continue up. SQL queries will be organized chronologically according to their difficulty. I will add more later on. SQL knowledge is a must for any IT department nowadays.… 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 OFFSET (Window) Functions – LAG, LEAD, FIRST_VALUE, LAST_VALUE

OFFSET functions are relatively new to MS SQL Server. They are available since SQL Server 2012 version. These functions enable a user to “list” through rows of a table. To be precise, it makes you able to put hand on previous or next row while still at the current one. These functions belong to a… 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 »