TSQL Analytic Functions LEAD and LAG
SQL Server 2012 introduces 8 new analytic functions. This post will cover 2 of them LEAD and LAG, which can be used to reference a value in the row before or the row after the current row. If you have...
View ArticleUsing the OUTPUT Clause in TSQL for Auditing
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...
View ArticleCumulative Distribution Function (CDF) – Analyzing the Roll of Dice with TSQL
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...
View ArticleTSQL Pivot Table
TSQL Pivot Table? Whats 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...
View ArticleSEQUENCE Sample Code from SQL Saturday in Olympia WA
The sample code below is a quick run down of the new sequence object introduced in SQL Server 2012. USE [tsql2012]; -- SEQUENCE -- using default where does this one start? --DROP SEQUENCE...
View ArticleSQL Server 2012 IIF Statement
SQL Server 2012 introduces the IIF statement. It is very similar to the IIF statement in MS Access. I have extracted the IIF part of my presentation on Whats new in SQL Server 2012, and turned it into...
View ArticleT-SQL 2012 Procedure sp_describe_first_result_set
SQL Server 2012 adds a new stored procedure called sp_describe_first_result_set. This new procedure returns metadata for the result set returned from a query. The metadata is information about what...
View ArticleRows and Range, Preceding and Following
SQL Server 2012 adds many new features to Transact SQL (T-SQL). One of my favorites is the Rows/Range enhancements to the over clause. These enhancements are often times referred to as the windowing...
View ArticleDBCC CheckAlloc
Being day one of DBBC Command month at SteveStedman.com, today’s featured DBCC Command is DBCC CHECKALLOC. Description: DBCC CheckAlloc checks and can repair disk space allocation structures for a...
View ArticleDBCC CheckFilegroup
Being day five of the DBCC Command month at SteveStedman.com, today’s featured DBCC Command is DBCC CHECKFILEGROUP. Description: DBCC CHECKFILEGROUP is used for a specific filegroup to check the disk...
View ArticleCommon Table Expressions – Terminating the Previous Statement
Day 4 of Common Table Expression Month (June) at SteveStedman.com, today I will cover the topic of terminating the previous T-SQL statement. These queries will be using that database that was set up in...
View ArticleCTE Scope
Day 5 of Common Table Expression Month (June) at SteveStedman.com, today I will cover concepts around the scope of a CTE. The queries in the video will be using that database that was set up in a...
View ArticleEnabling Transparent Data Encryption on SQL Server 2014
To start with for Transparent Data Encyrption (TDE) we will need to be using Enterprise (or Developer) edition of SQL Server 2014. I am using SQL Server 2014 Enterprise Edition CTP1, which is the early...
View ArticleIntroducing the DataBase Corruption Challenge (DBCC) – Week 1 Challenge
Welcome to the DataBase Corruption Challenge, this is an about weekly blog challenge where I will post a corrupt SQL Server database with some details on what happened to it. If at this point you are...
View ArticleHow To Move TempDB Files
I was asked recently how to move TempDB on SQL Server. The question specifically was how to move the TempDB files to different drives. At that point I realized that I don’t have that posted to my blog,...
View ArticleWeek 7 Database Corruption Challenge Results
The seventh week of ten in the Database Corruption Challenge went well. There were a few new participants, and many of those who have competed week over week. The first to submit a correct answer this...
View ArticleWeird Join Delete
This confused me for a few minutes today and I wanted to share to help avoid further confusion. The specific code was this: DELETE t2 FROM [dbo].[Table1] t1 INNER JOIN [dbo].[Table2] t2 on...
View ArticleTSQL To Start A SQL Agent Job
Most of us are familiar with the quick and easy right clicking on an agent job an select “Start job at Step…”, but what if you need to run a job on many servers how can you kick it off manually. But...
View ArticleCumulative Distribution Function (CDF) – Analyzing the Roll of Dice with TSQL
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...
View ArticleUsing the OUTPUT Clause in TSQL for Auditing
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...
View Article