Posts

Showing posts from July, 2022

A book a day! Review of the book "SQL Server Query Tuning and Optimization" by Benjamin Nevarez.

Image
Hi Guys, Welcome back! I am very happy to review a new book, due out in August, about tuning and Optimization of SQL Server. It is published by the english publishing company Packt and wrote by the well known Benjamin Neverez , this book will be very useful to anyone who wants to enter in the word of the tuning and Optimization. You will find this book on sale from the 12 August .   The Review First of all, let's say who this book is for. This book is intended for anyone who wants to enter the world of SQL Server tuning and optimization. I'll be clear, this book contains almost all the aspects you need to know to do this job . Among the positive things I find the explanation of the concepts clearly stated and in this Nevarez knows how to do his job very well. In addition, everything is updated to the latest SQL Server 2022 version.   What this book covers? ...let's see it in preview! The book starts with an overview of the architecture of the SQL Server engine then mov...

SQL Server 2022 and windowing improvements. Learn SQL with me!

Image
Hi guys, In the last four posts we talked about the T-SQL news that SQL Server 2022 brought us. SQL Server 2022 and the DATE_BUCKET function. Work more easily with dates  SQL Server 2022 and the GREATEST / LEAST T-SQL commands   SQL Server 2022 and the STRING_SPLIT command .. string splitting made easy!  SQL Server 2022 and the GENERATE-SERIES command .. a T-SQL language enhancement  Today we will talk about another T-SQL extension.  We will talk about the Window clause in the window functions . As always, I will try to be as clear as possible! Enjoy this post!   The Window Clause With SQL Server 2022, Microsoft introduce in the window functions the concept of window . For the sake of truth this is not a feature invented by Microsoft because this concept is part of the ISO/IEC SQL standard. If you doesn't know what a window function is, you can read here: Learn SQL Server Window functions and Running Totals in five minutes  Looking at the example bel...

SQL Server 2022 and the DATE_BUCKET function. Work more easily with dates

Image
Hi guys, Welcome back to all for another short but useful post! This time I will tell you about another T-SQL TVF function introduced by the newest SQL Server 2022 ! This function will permit us to easily cope with the needs that arise when we have to work with dates. DATE_BUCKET The DATE_BUCKET function collapses a date/time to a fixed interval and let me say that this is a great idea! Now there is no more need to round datetime values, then extract date parts and perform conversions to and from other types like float. Example We can write: declare @dt datetime2 ; set @dt = '2022-03-21 19:45:01.123' Select date_bucket (MONTH, 1, @dt) Executing the command you will get:  All the dates will be rounded to a one month precision. Prior to SQL Server 2022 we should have written: declare @dt datetime2 ; set @dt = '2022-03-21 19:45:01.123' Select datefromparts ( YEAR (@dt), MONTH (@dt), 1) That's all for today! p.s. ... are you genuinely ...

SQL Server 2022 and the GREATEST / LEAST T-SQL commands

Image
Hi Guys, Welcome back to this little new midweek post. Today we will see two more simple but useful new T-SQL commmands added in SQL Server 2022.   I usually don't like commands that aren't ANSI standard as much, but now these commands are used by more than one database engine. For example, our new GREATEST and LEAST commands are supported by PostgreSQL, MySQL and Oracle. So if they are comfortable, they are welcome! Enjoy the reading! GREATEST / LEAST commands   These new two functions returns the maximum value and then mininum value from a list of one or more expressions .   As paramters they accept a list of comma-separated expressions of any comparable data type . Furthermore these functions requires at least one argument and supports no more than 254 arguments.    For example we can write: SELECT GREATEST   ( 'Brad Pitt' , N 'Angelina Jolie' , 'Tom Hanks' ) AS VALUE; or SELECT LEAST   ( 'Brad Pitt' , N 'Angelina Jo...

SQL Server 2022 and the STRING_SPLIT command .. string splitting made easy!

Image
Hi Guys and welcome back to this new post! Do you want to learn another useful T-SQL command with me? Well, today we will show how to split strings easily , so.....no more recursive left o copy statements usage!   The STRING_SPLIT function The String_Split function is a table-valued function that splits a string into rows of substrings. Obviously, you can choose the separator character to use . Well first I have to tell you that this function is part of SQL Server since version 13.00 (SQL 2016).but we are talking about it today because it has been significantly improved.   Using SQL Server 2022 we have a new parameter enable_ordinal:     If this parameter is set to 1 this function will return also a new column ordinal. For example i can write the following command:   SELECT value, ordinal FROM STRING_SPLIT ( 'My name is luke' , ' ' , 1) When i execute it i will get:       I get four rows,  a row for each word (the separat...