Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««56789»»»

Just curious, what are your SQL pet peeves ? Expand / Collapse
Author
Message
Posted Wednesday, June 4, 2014 6:37 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Today @ 1:31 PM
Points: 280, Visits: 615
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.
Post #1577296
Posted Wednesday, June 4, 2014 6:49 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 1:19 PM
Points: 13,312, Visits: 10,177
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 LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1577302
Posted Wednesday, June 4, 2014 8:04 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, July 22, 2014 7:29 PM
Points: 48, Visits: 155
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*
Post #1577344
Posted Wednesday, June 4, 2014 8:08 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, July 22, 2014 7:29 PM
Points: 48, Visits: 155
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. :)
Post #1577347
Posted Wednesday, June 4, 2014 8:16 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 3:16 PM
Points: 21,251, Visits: 14,958
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


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #1577351
Posted Wednesday, June 4, 2014 8:19 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 3:16 PM
Points: 21,251, Visits: 14,958
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


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #1577361
Posted Wednesday, June 4, 2014 8:26 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 3:16 PM
Points: 21,251, Visits: 14,958
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


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #1577365
Posted Wednesday, June 4, 2014 2:24 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 1:19 PM
Points: 13,312, Visits: 10,177
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 LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1577535
Posted Wednesday, June 4, 2014 3:37 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 8:22 AM
Points: 36,767, Visits: 31,223
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.


--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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1577592
Posted Wednesday, June 4, 2014 3:44 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 1:19 PM
Points: 13,312, Visits: 10,177
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.


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 LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1577594
« Prev Topic | Next Topic »

Add to briefcase «««56789»»»

Permissions Expand / Collapse