Category Archives: SQL Tutorials

Datový skladT-SQL is a language used for working with databases on the MS SQL Server platform. You will find a lot of articles and tutorials about T-SQL in this section. If you want to learn SQL or just remind yourself how to work with SQL function, check out the SQL tutorial. I want every article to contain an example of usage and a code example too. List of Articles in category »

SQL ROLLUP, CUBE, GROUPING SETS – Totals and Subtotals

What about upgrading GROUP BY clause by use of useful commands? GROUP BY is used in a clause with aggregate operations. When it is used, aggregation happens throughout all columns. Using this simple “grouping” does not enable us to do totals and subtotals. But there is plenty of operators which can easily query for totals.… 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 »

How to Execute SQL Procedure in Excel incl. Parameters with Example

I must say right from the beginning that even though this process is possible, I do not recommend it (but I will show it to you anyway) :). Launching SQL queries in Excel is not optimal in general, but sometimes there is no other option. This guide is aimed on advanced Excel users with SQL… Read More »

SQL 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 – Unification 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 Syntax SELECT Column FROM dbo.Table WHERE Condition   UNION ALL SELECT Column… 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 in final unification of records. Syntax SELECT Column FROM dbo.Table WHERE Condition      UNION SELECT Column FROM dbo.Table WHERE Condition; Syntax is same as in all Set operators. Result… Read More »

SQL SUBSTRING Function – Get Part of String With Example

SUBSTRING function is used in sql to select part of text string in text. This function belongs to the group of text functions – string functions. I created a big summary of T-SQL text functions – you can find it here. Syntax SELECT SUBSTRING(text, <start position of the text character>, <the number of characters to… Read More »

SQL BETWEEN Operator – Defining Range in a Condition with Examples

This operator is used in SQL whenever it is needed to prove if certain value belongs to some range. This operator is used together with “AND” command which defines given range. Operator can be used in most of the clauses but is most common in WHERE for defining limiting requirement. Syntax SELECT [Date] FROM [dbo].[Table]… Read More »

SQL Handling Transaction COMMIT ROLLBACK – Prevent Troubles

What we call a transaction in SQL is logical set or sequence of operations which belong to this transaction. SQL Transactions can be used if we perform some changes in a databases. Advantage of transactions managing is that performed changes are reversible and we always need to use command COMMIT for confirmation or use ROLLBACK… Read More »

SQL CTE (Common Table Expressions) With Examples – More Organized Queries and Procedures

SQL CTE or so called Common table expression is simply put a temporary table (or better said it is a result set) in form of an expression. We can refer to it in SELECT, INSERT, DELETE or UPDATE script after its declaration using clause WITH. We can make recursive queries using CTE (it is even… Read More »

SQL DELETE TABLE Statement, Difference DELETE and TRUNCATE, Deleting Large Amounts Of Data

We distinguish two types of commands with data deleting purpose – SQL commands DELETE and TRUNCATE. Each is suitable for different situations. It is good to know them both and be able to choose the right one in a specific situation. DELETE Syntax (First Command is Optional): DELETE FROM dbo.Table WHERE <Condition>; or DELETE dbo.Table WHERE… Read More »