December 17, 2003 at 8:35 am
quote:
Dude should have normalized his database...
Probably bought the list from a spammer!
========================
He was not wholly unware of the potential lack of insignificance.
December 17, 2003 at 10:34 am
I agree with the second best practice but feel that the code example is still somewhat hard to read. I like to format select statements as follows:
select distinct
clo.clone_id,
clc.collection_name,
clo.source_clone_id,
clo.image_clone_id,
lib.library_name,
lib.vector_name,
lib.host_name,
loc.plate,
loc.plate_row,
loc.plate_column,
clo.catalog_number,
clo.acclist,
clo.vendor_id,
clc.value,
lib.species,
seq.cluster
from clone clo
inner join collection clc on clo.collection_id = clc.collection_id
inner join library lib on clo.library_id = lib.source_lib_id
inner join location loc on clo.clone_id = loc.clone_id
inner join sequence seq on clo.clone_id = seq.clone_id
where clc.short_collection_type='cDNA'
and clc.is_public = 1
and clo.active = 1
and clo.no_sale = 0
and seq.cluster in (select cluster from master_xref_new where
type='CLONE' and id='LD10094')
December 17, 2003 at 11:22 am
I have to admit that I tend to use single character, sometimes 2 char aliases, but they have some bearing to the tables. For example, I might use
select *
from products p
inner join orderline oi
on p.productid = oi.productid
inner join orders o
on oi.orderid = o.orderid
inner join customers c
on o.custtid = c.custid
As mentioned above, the same tables appear often, so you get used to p for products.
ANSI syntax, while strange at first, is 1000 times better than the old syntax.
I always use non proportional or fixed width fonts as well and spaces instead of tabs so that the code looks the same on my machine as yours. And vice versa, which is usually the more important one 😀
Steve Jones
http://www.sqlservercentral.com/columnists/sjones
The Best of SQL Server Central.com 2002 - http://www.sqlservercentral.com/bestof/
December 17, 2003 at 1:38 pm
When I wrote the article, I originally included some very brief remarks on formatting but the article was starting to get rather long, so I focussed on the two Best Practices that would make my life easier and I cut the references to formatting. If something shows up in front of me that looks ugly merely because the spacing and tabbing is poor, that's easy to fix if I feel it's necessary in the situation. Fixing up table aliases and separating join conditions from "this query" where restrictions is MUCH more time-consuming.
I believe an earlier reply had it right: develop a style but, as for imposing it on others, it's like arguing religion. Our local SQL Style Guide simply tells the individual programmers to develop some sort of style and stick with it. When I'm looking at something someone else wrote, I can usually get along OK as long as it has SOME sort of style.
My experience has been that most programmers seem to develop some sort of spacing/tabbing style of their own without being told to and that it's usually readable.
I also like fixed fonts for coding.
December 18, 2003 at 1:24 am
I tend to use short meaningful abbreviations, which is fine for databases with a few tables, but if you get an app with thousands of tables then your abbreviations cna only be local to the view, function or proc.
I remember looking at an SAP application, where there were tens of thousands of tables. The names of the tables themselves were pretty bloody meaningless in the first place.
========================
He was not wholly unware of the potential lack of insignificance.
December 23, 2003 at 7:12 am
It is also worth pointing out that in SQL Server 2000, in addition to making your code more readble, you also get a noticable speed improvement by using ANSI joins.
July 27, 2004 at 7:45 pm
As a soon to be senior citizen, I would like to put in my 2 cents worth on the suggested naming convention for aliases. Being an over 40 developer with less than perfect eye sight, I find it much easier to distinguish between alias like a, b, or c than it is Mnemonic aliases like clo and clc. The similarities between aliases like clo and clc are some times distracting and easy to confuse. Plus it adds addition characters to the statements, which adds to the statement's length. I suppose the idea of readable code would depend on the eyes of the beholder.
December 17, 2004 at 1:48 am
Ironic that in this issue of SQLServerCentral we have an article about formatting (with very easy to read SQL examples) and this article with code that was unreadable at a glance, so I gave up on it.
December 17, 2004 at 8:20 am
Really enjoyed the article. I think however, we all know the best way to name table aliases and variables: After ex girlfriends and cartoon characters. 😉
John Scarborough
MCDBA, MCSA
December 17, 2004 at 11:23 am
Kindest Regards,
Just say No to Facebook!Viewing 10 posts - 16 through 24 (of 24 total)
You must be logged in to reply to this topic. Login to reply