August 13, 2015 at 9:01 am
Wayne West (8/13/2015)
Luis Cazares (8/13/2015)
We need a T-shirt campaign to help drum up attention for MS Connect requests. Somebody like RedGate can put their logo on the back distribute them at events.
Something like this?
Wear that T-shirt in public, and you'll be explaining a hundred times over to friends, family, and total strangers. 🙂
Well, someone has to learn about tally tables 😀
Today, sir, you win the internet! Or at least SSC.
I'd buy that for a dollar! :hehe:
Luis, that looks like a winner. Put me down for one, please.
August 13, 2015 at 9:56 am
It's great that you love them, though I'd like to see you promote specific examples, not just sing the praises.
It's helpful for people that don't understand tally tables to see others in the world actually applying them in specific situations. In fact, more "example" articles would be welcome.
August 13, 2015 at 10:30 am
Luis Cazares (8/13/2015)
Ed Wagner (8/13/2015)
Eric M Russell (8/13/2015)
But where do you get your tally? There are examples out there; Jeff's is popular. However, it would be nice if SQL Server would provide an internal tally table just for the purpose, so we would always have it available in any environment, and it would perhaps have some optimization advantage over a physical table.Erland Somerskog opened an MS Connect item for this back in 2007, but it hasn't been implemented. https://connect.microsoft.com/SQLServer/feedback/details/258733/add-a-built-in-table-of-numbers
Maybe the people in Microsoft should learn how and why to use a Tally Table as they don't seem to understand the concept. Or maybe they just don't care about it anymore.
It's not viewed as critical or essential. Many businesses have no idea what it is or how it would help so they put resources where it matters to businesses. Don't expect a Tally table to be implemented anytime soon, but be pleasantly surprised if it is.
Part of the reason could be that it is so easy for people to create their own table.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
August 13, 2015 at 2:04 pm
When I'm involved in interviews I ask if they know about the tally/number table. I'm always surprised how many people have never heard about it. If they have I do follow up with how they would use it.
It is certainly a valuable tool.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
August 13, 2015 at 2:52 pm
Long overdue praise for the lowly tally table. I declare August 33rd as the official Tally Table Appreciation Day.
"Do not seek to follow in the footsteps of the wise. Instead, seek what they sought." - Matsuo Basho
August 13, 2015 at 8:23 pm
Knut Boehnert (8/13/2015)
Knowing how and what to use a tally table for is not a core skill.Working in sets of data instead of RBAR of data is a core skill.
The use of a tally table just shows that the person writing SQL (in whichever flavor) understands this core skill.
THAT is exactly correct! The Tally/Numbers table and its cousin, the Itzik Ben-Gan style cascading CTE (cCTE) are just one manifestation of the core skill of working in sets.
--Jeff Moden
Change is inevitable... Change for the better is not.
August 13, 2015 at 8:27 pm
Eric M Russell (8/13/2015)
Long overdue praise for the lowly tally table. I declare August 33rd as the official Tally Table Appreciation Day.
Ugh! That would mean that I'd have to change the Calendar table I told them we didn't need.
--Jeff Moden
Change is inevitable... Change for the better is not.
August 14, 2015 at 8:47 am
This is a skill that I do not have in my toolbox. I've heard of it, but haven't really investigated it much. You've got me curious Steve, thanks! I Binged it (hey, it's a decent search engine) and found a link to a blog post titled Tally Tables in T-SQL[/url]. Even that had something I'm not sure what the author is doing. They have the following code which they said will run on a SQL 2000 instance:
SELECT TOP 1000000 N=IDENTITY(INT, 1, 1)
INTO dbo.Numbers
FROM master.dbo.syscolumns a CROSS JOIN master.dbo.syscolumns b;
ALTER TABLE dbo.Numbers ADD CONSTRAINT NBR_pk PRIMARY KEY(N);
SELECT TOP 5 N FROM dbo.Numbers;
What's the purpose of doing a cross join between the master.dbo.syscolumns table, and then not using it? Sorry, inquiring minds want to know.
Kindest Regards, Rod Connect with me on LinkedIn.
August 14, 2015 at 8:51 am
I just wish it wasn't called a "Tally" table. I don't tally things, I count them. fwiw I usually call my "tally" table "N" to reflect it's relation ship to the set of natural numbers, usually represented by a double-struck N (now let's not argue if it should contain 0 (CS) or not (mathematics)).
Gerald Britton, Pluralsight courses
August 14, 2015 at 8:52 am
What's the purpose of doing a cross join between the master.dbo.syscolumns table, and then not using it? Sorry, inquiring minds want to know.
to get enough numbers to handle large applications
Gerald Britton, Pluralsight courses
August 14, 2015 at 8:58 am
Rod at work (8/14/2015)
What's the purpose of doing a cross join between the master.dbo.syscolumns table, and then not using it? Sorry, inquiring minds want to know.
Well, the point is that you are actually using it. You're not using the columns, but you're using the rows. You need to generate the rows somehow and using large tables is easier than creating the rows on the fly like this:
SELECT N=IDENTITY(INT, 1, 1)
INTO dbo.Numbers
FROM (SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL
SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1) a(n)
CROSS JOIN (SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL
SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1) b(n)
CROSS JOIN (SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL
SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1) c(n)
CROSS JOIN (SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL
SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1) d(n)
CROSS JOIN (SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL
SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1) e(n)
CROSS JOIN (SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL
SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1) f(n);
In the end, you care about the rows, because you generate new values for a single column. How you get the rows is not that big deal.
August 14, 2015 at 8:59 am
g.britton (8/14/2015)
What's the purpose of doing a cross join between the master.dbo.syscolumns table, and then not using it? Sorry, inquiring minds want to know.
to get enough numbers to handle large applications
Shouldn't use dbo.syscolumns. That system table is one of those deprecated and may be removed from a future version of SQL Server. Should use sys.columns or sys.all_columns instead. Or you could use this in SQL Server 2008 and newer:
with e1(n) as (select 1 from (values (1),(1),(1),(1),(1),(1),(1),(1),(1),(1))dt(n)), -- 10 rows
e2(n) as (select 1 from e1 a cross join e1 b), -- 100 rows
e4(n) as (select 1 from e2 a cross join e2 b), -- 10,000 rows
eTally(n1) as (select row_number() over (order by (select null)) from e4 a cross join e2 b) -- 1,000,000 rows
select n from eTally;
August 14, 2015 at 9:02 am
Lynn Pettis (8/14/2015)
g.britton (8/14/2015)
What's the purpose of doing a cross join between the master.dbo.syscolumns table, and then not using it? Sorry, inquiring minds want to know.
to get enough numbers to handle large applications
Shouldn't use dbo.syscolumns. That system table is one of those deprecated and may be removed from a future version of SQL Server. Should use sys.columns or sys.all_columns instead. Or you could use this in SQL Server 2008 and newer:
with e1(n) as (select 1 from (values (1),(1),(1),(1),(1),(1),(1),(1),(1),(1))dt(n)), -- 10 rows
e2(n) as (select 1 from e1 a cross join e1 b), -- 100 rows
e4(n) as (select 1 from e2 a cross join e2 b), -- 10,000 rows
eTally(n1) as (select row_number() over (order by (select null)) from e4 a cross join e2 b) -- 1,000,000 rows
select n from eTally;
dbo.syscolumns is used because the code is intended for a 2000 instance.
August 14, 2015 at 9:04 am
Oh OK Luis, I get it now. I got hung up on trying to read what's in syscolumn. That's not the point at all, is it. The original poster is just using that table as a way of casing an iteration to occur. Ah, now I understand. Thanks! (You know, I would not have thought of that. Thanks!!)
Kindest Regards, Rod Connect with me on LinkedIn.
August 14, 2015 at 9:04 am
g.britton (8/14/2015)
I just wish it wasn't called a "Tally" table. I don't tally things, I count them. fwiw I usually call my "tally" table "N" to reflect it's relation ship to the set of natural numbers, usually represented by a double-struck N (now let's not argue if it should contain 0 (CS) or not (mathematics)).
It's funny, because tally is a synonym of count.
Viewing 15 posts - 16 through 30 (of 87 total)
You must be logged in to reply to this topic. Login to reply