In 2012 SQL Server introduced the SEQUENCE object.  Looking at the syntax it is very similar to how Oracle has implemented SEQUENCEs for many years.  I believe that the SEQUENCE was introduced to aid in the transition of Oracle developers to SQL Server. First off what is a SEQUENCE???… A user-defined object that generates a sequence of numeric values. To …

SQL Server SEQUENCE Read more »

Take the following sample code.    Four similar tables with an INT IDENTITY, BIGINT IDENTITY, and two with UNIQUEIDENTIFIERS, one using newid() and the other with newsequentialid(). Once the tables are created and we insert 100,000 rows into each, they are very similar, but they take up very different amounts of disk space. Using the Database Health Reports application, we …

Should I Use A Unique Identifier As A Primary Key? Read more »

Have you ever needed to generate a list of dates for the last 30 days.  There are lots of different ways to do this with TSQL, but one way is with a recursive CTE. You can then left join against it with another query to generate a list of all  dates in a result set, along with the dates for …

Recursive CTE to Calculate Dates for the Last 30 Days Read more »

TSQL Pivot Table TSQL Pivot Table?  What’s that? Here is a quick sample of how to implement a pivot table in TSQL for SQL Server. The example below creates a database called pivot, you probably already have your own database to work in. Then it… Read more… Excited to Release Training Videos Just this week the team at Stedman Solutions …

August Blog Post Wrap-up Read more »

Just this week the team at Stedman Solutions finished the SQL Server JOIN Types paid training course. I am very excited to complete this and to make it available to the SQL Community. Whether you have been writing SQL Queries for 10 years, or you are on connecting your first 2 tables in a query, there is something that you …

Excited to Release Training Videos Read more »

Recently I have been on the LEAN improvement quest to make a 2 second improvement in my process every day. Part of that improvement is to avoid switching to the mouse when you don’t have to.  Here are some shortcut keys that I find very useful in SQL Server Management Studio, some of which I just discovered recently. Window + …

What’s your favorite SSMS time saving hotkey? Read more »

The OUTPUT clause is often times underappreciated by the TSQL programmer.  There are many really interesting things that you can do with the OUTPUT clause, from inserting to two tables with one statement or to replace the SCOPE_IDENTITY option.  For this posting I am looking into using the OUTPUT clause for auditing. By auditing in this example, I specifically mean …

Using the OUTPUT Clause in TSQL for Auditing Read more »

After the last post on Cumulative Distribution Function (CDF) or as it is known in TSQL CUME_DIST(), I realized that although I showed how to use it, I didn’t really explain what it means, or when to use it.  That is where this example comes in. First lets take an example that generates simulated dice rolls.  What are the odds …

Cumulative Distribution Function (CDF) – Analyzing the Roll of Dice with TSQL Read more »