SQL Art, Part 2: New Year Fireworks in SSMS (Yes, Really)
Last time we turned SQL Server into a Christmas card.
This time we’re doing something even less sensible: fireworks.
Not charts. Not dashboards. Not “data visualization”.
Actual fireworks, built from SQL Server geometry shapes and rendered in SSMS.
What you’ll get
-
Random firework bursts in the sky
-
Rings, cores, rays, and trails
-
“HAPPY NEW YEAR” stamped in spark pixels
-
One simple way to remix it without understanding all the math
If you want a reminder that SQL is just a programming language with a storage habit, this is it.
Run it
Paste this into SSMS, execute, then view the results in the spatial viewer.
How it works
Step 1: Pick the sky coordinates
We generate @Fireworks random centers in #centers using CHECKSUM(NEWID()). That gives us repeatable “random enough” values per row, which is better than RAND() when you want variety without weird loop behaviour.
Each center has:
-
xandyfor position -
rfor burst size
Step 2: Build each burst in layers
For each center:
-
Core: a small circle
STBuffer(r * 0.12) -
Ring: big circle minus slightly smaller circle using
STDifference -
Rays:
@Raysline segments shot out usingCOSandSINaround a full circle -
Trail: a vertical line down to the ground to fake a launch path
It’s basically procedural art, just written in SQL.
Step 3: Draw “HAPPY NEW YEAR” as spark pixels
This is my favourite part.
We define a 5x7 pixel font in a table variable @Font where each character is a set of (row, col) pixels. Then we loop through each letter and stamp little circles as “spark dots”.
It’s a tiny rendering engine, built from a table and two loops.
Remix it in 30 seconds
If you want readers to actually engage, give them these quick edits:
More chaos
Bigger sparks and thicker rays
Move the text
One improvement you should make before publishing
Right now you end with SELECT * FROM #scene; which works, but the viewer will show multiple shapes. For a cleaner “single picture” result, output one unioned geometry, like this:
That makes the result feel like a finished artwork, not a bag of parts.
Your next-level version
If you want this series to become something people follow, stop hard-coding glyphs inside every post. Make a reusable font table and a stored procedure like:
-
dbo.GlyphPixels(ch, r, c) -
dbo.StampText(@text, @x, @y, @scale, @dot)
That turns a holiday gag into a tiny SQL art toolkit.
Comments
Post a Comment