Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Just curious, what are your SQL pet peeves ?


Just curious, what are your SQL pet peeves ?

Author
Message
gbritton1
gbritton1
Old Hand
Old Hand (369 reputation)Old Hand (369 reputation)Old Hand (369 reputation)Old Hand (369 reputation)Old Hand (369 reputation)Old Hand (369 reputation)Old Hand (369 reputation)Old Hand (369 reputation)

Group: General Forum Members
Points: 369 Visits: 841
I've slowly grown to favor leading commas in queries for two reasons:

1. It's easy to comment out a column for debugging or to explicitly show that there is a column that you are NOT using
2. I find commas at the end of the line or (worse, much, much worse!) in the middle hard to track down. I've had to look at too many things like:


SELECT a,b,c,REPLACE(REPLACE(d,'a','b'),'e','f') g,e,
f,h



My pet peeve is the deep nesting (> 1 levels) of subqueries where CTEs could be used instead.
Koen Verbeeck
Koen Verbeeck
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16540 Visits: 13210
gbritton1 (6/4/2014)
I've slowly grown to favor leading commas in queries


+1

I always use leading commas. It looks cleaner in my opinion and it's easier to align everything.



How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at SQLKover.

MCSA SQL Server 2012 - MCSE Business Intelligence
SQL is delicious
SQL is delicious
SSC Rookie
SSC Rookie (49 reputation)SSC Rookie (49 reputation)SSC Rookie (49 reputation)SSC Rookie (49 reputation)SSC Rookie (49 reputation)SSC Rookie (49 reputation)SSC Rookie (49 reputation)SSC Rookie (49 reputation)

Group: General Forum Members
Points: 49 Visits: 174
Evil Kraig F (6/3/2014)
Sorry, ;WITH is ingrained into my head at this point. You're stuck with it if you chase me in my code.

I agree with a decent amount of what's been said here. I personally trail my commas.

Personal pet peeves not already stated:
not using AS when you define your field names/table aliases. Drives me NUTS because now I'm looking at forumulas not aliasing.

Indent your damned CASE trees/IF trees/whatevers intelligently and consistently. I expect to be able to page down a few times and see, clearly, where that cursor from hell you built ends. I don't expect to have to dig through 6 ENDs to figure out which one is the trailer for the thing when I'm prepping to gut it.

INDEX (0). Particularly without comment(s).

SSIS: Using Row Redirection on bad rows without creating an error trap table to deal with them.

SSIS: Not understanding what a configuration is. How to use it I can train, not knowing it's there is on you.

SSIS: Crappy naming methods for your data sources. You're connecting this thing to a database and you're going to push it through environments. It doesn't need to be named "Martha's stuff in a table". Name it after the database. And for the love of god if I see one more 'Textfile 1', 'Textfile 2' I may shoot someone. At the very LEAST: Inbound CSV from Client, Outbound Flatfile to GL. Or something.

SSIS: Trying to create some form of alternate error logging and delivery system other than what's built in. Because yes, everyone should learn YOUR bloody mess of a system instead of the two that's documented and already included (SSIS logging and step logging in the job).

SSIS: Scoping variables at very low levels, and then re-using the name elsewhere. I get scope. I get why it's used in PROGRAMMING. I don't expect to have to click on EVERY object on the screen to figure out where the hell you scoped something. Global them.



OMG YES YES YES to all of this.

*raises a glass*
SQL is delicious
SQL is delicious
SSC Rookie
SSC Rookie (49 reputation)SSC Rookie (49 reputation)SSC Rookie (49 reputation)SSC Rookie (49 reputation)SSC Rookie (49 reputation)SSC Rookie (49 reputation)SSC Rookie (49 reputation)SSC Rookie (49 reputation)

Group: General Forum Members
Points: 49 Visits: 174
Koen Verbeeck (6/4/2014)
gbritton1 (6/4/2014)
I've slowly grown to favor leading commas in queries


+1

I always use leading commas. It looks cleaner in my opinion and it's easier to align everything.


I'm "bi" when it comes to leading/trailing commas.

If I'm writing quick queries to grab data for someone or if I'm developing something and need to comment out columns, I use leading commas. Since most places I've ever worked either explicitly require trailing commas or have traditionally always used them (without written standards), I switch them to trailing once I'm settled on my design. Doesn't take long.

I don't have a strong preference either way, though I agree that leading commas are easier when you're developing code because they're easier to comment out. Smile
SQLRNNR
SQLRNNR
SSC-Insane
SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)

Group: General Forum Members
Points: 21137 Visits: 18259
Rudyx - the Doctor (6/3/2014)
What is wrong with table variables ?

hmmm ...

table variables are not capable of having indexes (however they support constraints and primary keys)

no indexes mean:
- no index statistics for the optimizer
- no indexes or index statistics which translates to mean a table scan for all access
- no indexes also mean that inserts with a constraint cause a table scan for every insert (the more rows the longer the scan)

Oh, and the initial fallacy that they are memory resident (HAH) - try:

select name
from tempdb..sysobjects
where name like '#%'

as for holding data in a roll-back scenarirollbackis wrong about using regular temp tables ?

anyone else ? did I miss something ?


They fixed some of the index issues with table variables in 2014. But table variables could always have an index. You just couldn't create indexes on the table variable after the fact.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

SQLRNNR
SQLRNNR
SSC-Insane
SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)

Group: General Forum Members
Points: 21137 Visits: 18259
GilaMonster (6/3/2014)
patrickmcginnis59 10839 (6/3/2014)
So whats the beef with "best practices"?


Over-priced 'consultants' who justify their non-standard settings and unconventional configuration options with 'It's best practice' with an undertone of 'and lesser individuals such as yourself wouldn't understand'

Any attempt to disagree, discuss or suggest alternatives get met with 'Our recommendations are according to best practices' or 'your recommendations are against best practices'


I would add software vendors to that statement. I have had them tell me their settings are BP numerous times with those same undertones.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

SQLRNNR
SQLRNNR
SSC-Insane
SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)

Group: General Forum Members
Points: 21137 Visits: 18259
Evil Kraig F (6/3/2014)

SSIS: Crappy naming methods for your data sources. You're connecting this thing to a database and you're going to push it through environments. It doesn't need to be named "Martha's stuff in a table". Name it after the database.


This made me think of another really bad pet peeve.

Naming the database as _Prod, _UAT, _QA, _Dev in order to match the different environments. Not only does it screw with code releases, it screws with SSIS packages (and yes configurations help a bit with that, but then do you leave the DS named after Dev where you built the package in the first place?).



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

Koen Verbeeck
Koen Verbeeck
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16540 Visits: 13210
SQLRNNR (6/4/2014)
Evil Kraig F (6/3/2014)

SSIS: Crappy naming methods for your data sources. You're connecting this thing to a database and you're going to push it through environments. It doesn't need to be named "Martha's stuff in a table". Name it after the database.


This made me think of another really bad pet peeve.

Naming the database as _Prod, _UAT, _QA, _Dev in order to match the different environments. Not only does it screw with code releases, it screws with SSIS packages (and yes configurations help a bit with that, but then do you leave the DS named after Dev where you built the package in the first place?).


It only makes sense if all those databases are on the same instances. (sounds like a lovely idea)
You could suffix the databases names if the databases are in source control and you need to branch.



How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at SQLKover.

MCSA SQL Server 2012 - MCSE Business Intelligence
Jeff Moden
Jeff Moden
SSC-Forever
SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)

Group: General Forum Members
Points: 45430 Visits: 39942
Koen Verbeeck (6/4/2014)
SQLRNNR (6/4/2014)
Evil Kraig F (6/3/2014)

SSIS: Crappy naming methods for your data sources. You're connecting this thing to a database and you're going to push it through environments. It doesn't need to be named "Martha's stuff in a table". Name it after the database.


This made me think of another really bad pet peeve.

Naming the database as _Prod, _UAT, _QA, _Dev in order to match the different environments. Not only does it screw with code releases, it screws with SSIS packages (and yes configurations help a bit with that, but then do you leave the DS named after Dev where you built the package in the first place?).


It only makes sense if all those databases are on the same instances. (sounds like a lovely idea)
You could suffix the databases names if the databases are in source control and you need to branch.


On the other hand, it has saved the lives of multiple DBAs that I know (myself included on one instance) because they thought they were in a dev envirionment when they were really in a prod environment. 99.9% of all code written can be setup to correctly use synonyms which also removes the need for 3 and 4 part naming requirements (which I never allow in code reviews).

As far as SSIS packages go, thanks... you've just given me yet another reason to avoid SSIS whenever possible. :-P

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is not.
Just because you can do something in PowerShell, doesnt mean you should. Wink

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Koen Verbeeck
Koen Verbeeck
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16540 Visits: 13210
Jeff Moden (6/4/2014)
Koen Verbeeck (6/4/2014)
SQLRNNR (6/4/2014)
Evil Kraig F (6/3/2014)

SSIS: Crappy naming methods for your data sources. You're connecting this thing to a database and you're going to push it through environments. It doesn't need to be named "Martha's stuff in a table". Name it after the database.


This made me think of another really bad pet peeve.

Naming the database as _Prod, _UAT, _QA, _Dev in order to match the different environments. Not only does it screw with code releases, it screws with SSIS packages (and yes configurations help a bit with that, but then do you leave the DS named after Dev where you built the package in the first place?).


It only makes sense if all those databases are on the same instances. (sounds like a lovely idea)
You could suffix the databases names if the databases are in source control and you need to branch.

...

As far as SSIS packages go, thanks... you've just given me yet another reason to avoid SSIS whenever possible. :-P


Where was SSIS mentioned to give you that conclusion?



How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at SQLKover.

MCSA SQL Server 2012 - MCSE Business Intelligence
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search