With the Docker environment finally running, it was time to move from "configuring" to "doing."
I went to the Microsoft SSMS source and pulled two classic sample files: instnwnd.sql (Northwind) and instpub.sql (Pubs). My plan was simple: install them, run some queries, and sharpen my SQL skills.
As is tradition in development, it wasn't that easy.
The Ghost in the Container
When I ran instnwnd.sql against my Docker-hosted SQL Express, the database simply didn't appear in the SSMS Object Explorer. I’m still not entirely sure why—it’s a task for another day. Instead of getting bogged down in another configuration rabbit hole, I pivoted to instpub.sql.
It worked. I finally had data to play with.
The Practice Run: 5 Challenges
I set out to solve five challenges ranging from basic filtering to aggregations. Here’s a look at the "Lessons Learned" from the session.
1. The "SELECT *" Trap
I started out by using SELECT * for almost everything. It’s a common beginner habit, but I quickly realized the cost. Using the wildcard pulls every column, wasting memory and processing power. In a small sample database, it doesn't matter; on a large production database, it’s a performance killer.
Lesson: Be specific. Only ask for what you need.
2. Efficiency with IN vs. OR
I was tasked with finding authors in California (CA) or Utah (UT). My first instinct was a long OR statement:
WHERE state = 'CA' OR state = 'UT'
I realized I could make this much cleaner using the IN operator:
WHERE state IN ('CA', 'UT')
3. The Power of the Wildcard (%)
I had a slight mix-up with the % wildcard. I initially tried to find last names starting with 'S' by using LIKE '%s', which actually looks for names ending in 'S'.
The fix: LIKE 'S%'.
4. Reading the Requirements (Slow Down)
In one challenge, I was asked for the Average Price and Total Sales. In my rush, I wrote a query for Average Sales.
-
My mistake:
AVG(ytd_sales) -
The requirement:
AVG(price), SUM(ytd_sales)
Progress Over Perfection
I’m a beginner, and this log is proof of that. I’m learning that SQL isn't just about getting the data—it's about getting the right data efficiently. I misread questions, I used inefficient methods, and I struggled with installations.
But the queries are running, the logic is sticking, and Log 02 is in the books. Next time, I’ll be diving into more advanced methods.
Top comments (0)