SQL Art: I Made a Christmas Card in tempdb
Most people use SQL Server to count things.
I used it to draw a Christmas tree. In a database. On purpose.
If you’ve ever stared at SSMS and thought “this could use more festive chaos”, this is for you.
What we’re doing
We’re going to:
-
Create a temp table in
tempdb -
Insert a bunch of
geometrypolygons that form a tree, trunk, and star -
Stamp “MERRY CHRISTMAS” on top using more polygons
-
Render “AND A HAPPY / NEW YEAR” using a tiny pixel font built from squares
-
Add random baubles because discipline is overrated
-
Union it all so SSMS shows one clean shape
Then SSMS becomes your art gallery.
The only requirement
You need SQL Server with the geometry type available (so basically modern SQL Server). SSMS helps because it can render spatial results visually.
Run this
Paste the whole thing into SSMS and execute it. Then click the Spatial results tab (or the spatial viewer) and enjoy your database becoming a greeting card.
How it works (in plain English)
1) The tree is just polygons
The main outline is one polygon that zigzags upward like layered branches. The trunk is a small rectangle. The star and side ornaments are separate polygons too.
This is the part most people miss: you do not “draw” in SQL, you describe shapes as coordinates.
2) “MERRY CHRISTMAS” is hard-coded geometry
Those letter shapes are prebuilt polygons. Brutal, yes. Reliable, also yes.
3) The bottom text is generated
This is the fun bit.
You define a tiny 5x7-ish pixel font inside a table variable, where each character is a set of (row, col) pixels. Then the script loops through the string and stamps squares into the right places.
That means you can write anything as long as you define the letters.
4) Baubles are circles made from points
geometry::Point(...).STBuffer(0.3) creates a little circle. Random coordinates make them look like decorations.
One warning: RAND() inside loops is not truly random the way people assume. You’ll still get variation, but don’t pretend it’s cryptographically festive.
Three quick upgrades you should do before posting
If you skip these, you’re leaving impact on the table.
-
Make the baubles deterministic
Right now, reruns change the look. That’s funny once, annoying after. Use a seeded approach withCHECKSUM(NEWID())to generate repeatable pseudo randomness per row. -
Let readers customise the message easily
Expose@LineAand@LineBat the top with a comment like “Edit these to change the card.” People love changing the text and reposting. -
Add a second colour layer
SSMS won’t colour it, but you can separate layers (tree, star, baubles, text) into separate result sets so people can screenshot and stack them, or at least understand the composition.
Remix ideas
-
Change the strings to your team name or your product launch
-
Add a snowman using circles and polygons
-
Write a tiny font generator and stop hard-coding letters forever
-
Make it animate by outputting multiple frames (one per SELECT) and flipping through them
What this is really teaching
Spatial types aren’t just for GIS. They’re a geometric playground hiding in plain sight.
And yes, this is absolutely a misuse of tempdb. That’s the point.
Comments
Post a Comment