Unfolding | Set Based Approach | Tally Table – Episode 5

In this video, we are going to understand Tally table which is very useful in writing set based SQL queries. You can download the script which can be used to create the Tally table from below the video.

--Creating database SetBasedApproach
CREATE DATABASE SetBasedApproach
GO

--Started using database SetBasedApproach
USE SetBasedApproach
GO

--Creating tally table
CREATE TABLE dbo.Tally
(
N INT NOT NULL PRIMARY KEY
)

--Adding records
INSERT INTO dbo.Tally(N)
SELECT TOP 100000 ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) AS N
FROM master.sys.all_columns Tbl1
CROSS JOIN master.sys.all_columns Tbl2
Rate This
[Total: 2 Average: 5]

Leave a Comment

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.

This site uses Akismet to reduce spam. Learn how your comment data is processed.