SqlServerKudos - Stories tagged with habits
1
kudos
spam Kudos Remove

Bad habits to kick : ORDER BY ordinal

published 287 days, 4 hours, 47 minutes ago posted by sasa 295 days, 12 minutes ago
Saturday, October 17, 2009 3:12:46 PM GMT Friday, October 09, 2009 7:47:47 PM GMT
A few weeks ago, I wrote a post about forming a new habit: always terminate statements with semi-colons.  Today I thought I would start a series on kicking bad habits that many of us have developed over time.  Today's topic: using ordinal numbers in our ORDER BY clauses.  At least once a week, I catch myself using ordinal position to define order.  For example, I might have this:  SELECT foo, bar FROM dbo.splunge ORDER BY 1, 2 DESC; This is lazy shorthand, and is bound to get screwed up at som... (more)
category: News | clicked: 0 | comment | | source: sqlblog.com
tags: Best Practices, future-proofing, habits, T-sql
1
kudos
spam Kudos Remove

Bad habits to kick : using loops to populate large tables

published 290 days, 4 hours, 57 minutes ago posted by sasa 295 days, 1 hour, 2 minutes ago
Wednesday, October 14, 2009 3:02:13 PM GMT Friday, October 09, 2009 6:57:04 PM GMT
Okay, I will admit, in most cases you are doing this for a demo or proof of concept, and so speed / performance is not all that important. But using a loop to populate a table with 1 million rows, one row at a time, is not fun at all, no matter how much thumb-twiddling you have to do. I often see people building up test cases like this: (more)
category: News | clicked: 1 | comment | | source: sqlblog.com
tags: Best Practices, CTEs, habits, loops, numbers table
1
kudos
spam Kudos Remove

Bad habits to kick : using old-style JOINs

published 290 days, 4 hours, 57 minutes ago posted by sasa 295 days, 2 hours ago
Wednesday, October 14, 2009 3:02:13 PM GMT Friday, October 09, 2009 5:59:18 PM GMT
In my last post in this series, I talked about using simple loops to populate large tables.  This time I'd like to focus on getting rid of old, ANSI-89 joins. I am sure most veterans know better than to use old ANSI-89 JOIN syntax, such as:SELECT o.OrderID, od.ProductID FROM dbo.Orders AS o, dbo.OrderDetails AS d WHERE o.OrderDate >= '20091001' AND o.OrderID = od.ProductID; One reason to avoid this syntax is that the query is often less readable than when you separate the joining criteria fr... (more)
category: News | clicked: 0 | comment | | source: sqlblog.com
tags: ANSI-89, ANSI-92, Best Practices, habits, old-style joins
1
kudos
spam Kudos Remove

Bad habits to kick : using table aliases like (a, b, c) or (t1, t2, t3)

published 290 days, 4 hours, 57 minutes ago posted by sasa 295 days, 2 hours, 11 minutes ago
Wednesday, October 14, 2009 3:02:13 PM GMT Friday, October 09, 2009 5:48:50 PM GMT
In my last post in this series, I talked about using old-style JOINs.  Today I'd like to touch on using aliases.  No, I don't mean fake passports and a life of crime, I mean using an alias as shorthand for referencing a table or view in a query. Some code I once had to clean up on an inherited system looked a lot like this:SELECT *   FROM Orders a   INNER JOIN OrderDetails b ON (more)
category: News | clicked: 3 | comment | | source: sqlblog.com
tags: Best Practices, habits, table aliases
1
kudos
spam Kudos Remove

Bad Habits to Kick: Not Using "AS"

published 290 days, 4 hours, 57 minutes ago posted by sasa 295 days, 4 hours, 16 minutes ago
Wednesday, October 14, 2009 3:02:13 PM GMT Friday, October 09, 2009 3:43:27 PM GMT
Aaron has recently been doing an absolutelyfantasticseries of posts detailing various "bad habits" that many of us pick up somewhere along the way. These coding anti-patterns aren't going to crash your server, but they will make your code more difficult to read and maintain. I'm enjoying Aaron's series so much that I've decided to join in the fun with one of my own. The "AS" keyword is optional both for table aliases and column name aliases. And although I'm pretty good about using it for columns, I've ... (more)
category: News | clicked: 2 | comment | | source: sqlblog.com
tags: as keyword, Best Practices, column names, derived tables, habits
1
kudos
spam Kudos Remove

Bad habits to kick : declaring VARCHAR without (length)

published 291 days, 4 hours, 58 minutes ago posted by sasa 295 days, 4 hours, 46 minutes ago
Tuesday, October 13, 2009 3:01:48 PM GMT Friday, October 09, 2009 3:13:25 PM GMT
In my last post in this series, I talked about using meaningless table aliases.  This time I'm going to talk about a pet peeve of mine: declaring varchar / nvarchar variables or parameters without specifying how many characters they should hold. Thankfully, I see this issue seldom in the code I've inherited in my own systems.  But I do see it quite a bit on blog entries, forum posts and newsgroup questions.  Because the length attribute is optional, people seem to make the assumption that defining a VAR... (more)
category: News | clicked: 1 | comment | | source: sqlblog.com
tags: Best Practices, declare, habits, Variables