Two Best Practices!

  • Comments posted to this topic are about the content posted at http://www.sqlservercentral.com/columnists/dhatheway/twobestpractices.asp

  • As a DBA I expect all submitted code to be commented.

    The comments should detail up front which tables are going to be used, what variables if any are declared and what they are supposed to be etc.

    ========================

    He was not wholly unware of the potential lack of insignificance.

  • quote:


    As a DBA I expect all submitted code to be commented.

    The comments should detail up front which tables are going to be used, what variables if any are declared and what they are supposed to be etc.

    ========================

    He was not wholly unware of the potential lack of insignificance.


    Does it work?

    Frank

    http://www.insidesql.de

    http://www.familienzirkus.de

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • In my environment yes because

    • I have a suitable carrot (the keys to the bosses drinks cabinet and the ability to sign expense forms).
    • I have a suitable stick (I contribute to their appraisals).
    • I practice what I preach.
    • Our projects come back to haunt us and when they haunt the person performing the exorcism may not necessarily be the person who originally wrote the code.

    I stress that the projects that come back to haunt do so, not because of poor quality, but because we deal with government projects and tend to get repeat business requiring reworking due to fundamental changes in requirements.

    ========================

    He was not wholly unware of the potential lack of insignificance.

  • Ah yes, ask the user what he wants and he starts thinking (maybe the first time) on what he's doing the whole day

    In another forum I found an interesting definition of USER

    quote:


    "USER, n.: The word computer professionals use when they mean 'idiot.'" Dave Barry


    When you deal with government, do you get your payment in time?

    Frank

    http://www.insidesql.de

    http://www.familienzirkus.de

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • I used to work on an HP3000 mini-computer where the console had ultimate control followed by administrators followed by users.

    We had a utility that let us impersonate differing levels of access.

    To impersonate the console we typed GOD.

    To return to administrive roles we typed MORTAL.

    To impersonate a user we typed TIT.

    Enough said

    ========================

    He was not wholly unware of the potential lack of insignificance.

  • TIT ????

    TIT Taste in Television (Married with Children)

    TIT Teacher in Training

    TIT Technician Induced Trouble

    TIT Tenchi In Tokyo (anime)

    TIT Tennessee Institute of Technology

    TIT Ternary Digit

    TIT The Internet Times

    TIT This Is Terrible

    TIT This Is Thailand (Bangkok Post)

    TIT This Is True

    TIT Time in Transit

    TIT Titus

    TIT Tokyo Institute of Technology

    TIT Torpedo Impulse Tank

    TIT Trotters Independent Trading

    TIT Trotter's International Trading

    TIT Tugaya Institute of Technology

    TIT Turbine Inlet Temperature

    The results from http://www.acronymfinder.com/af-query.asp?String=exact&Acronym=tit

    Frank

    http://www.insidesql.de

    http://www.familienzirkus.de

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • Sorry, forgot the language barrier.

    They say that eskimos have thousands of names for snow, the British have millions that can be used as insults.

    Bodily parts can be used as insults and tit is one of the milder ones. Given the nature of the bodily part its can even be regarded as an affectionate insult.

    British insults range from "affectionate greeting" to genuine full-blooded "I'd like to do unto you what God did unto the Sodomites"!

    People's names can also be used in a derogatory sense. For example the phrase "doing a Mandy" refers to a scam in the property trade that was carried out by one of our politicians (Peter Mandleson) where you sell a £300,000 house for £250,000 (thereby falling into a lower tax threshold) but charge £50,000 for fixtures and fittings.

    In fact the British have turned insulting people into such an art form that the mere sending of a Christmas card can be deemed to be a gross insult (according to one of our more useless politicians).

    If you have ever read "The Hitchhikers Guide to the Galaxy" there is a character in it who had immortality thrust upon him. Unable to cope with the shock of finding himself imortal he decided to devote his time to insulting each an every being in the universe personally. I'd like to think of him as British.

    ========================

    He was not wholly unware of the potential lack of insignificance.

  • You mean the Douglas Adams' book?

    If so, wasn't this character the robot?

    Me thinks the British have served the art of insulting very well in having black puddding and serving warm beer

    Frank

    http://www.insidesql.de

    http://www.familienzirkus.de

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • Yep, Douglas Adams.

    The robot was Marvin the paranoid android but I'm thinking of a character in a later book in the series but can't think of his name.

    There is a message for all computer programmers in this book when the computer, "Deep Thought" finally gives his answer to life the universe and everything but says that the programmers should have specified the ultimate question first! If that doesn't sum up user requirements then I don't know what does.

    I particularly liked God's last message to his creation "We apologise for the inconvenience".

    In addition to your warm beer and black-pudding I think you should add haggis and bagpipes (I know we didn't invent bagpipes but we do persist in playing them).

    ========================

    He was not wholly unware of the potential lack of insignificance.

  • For the second best practice, i would like to add

    Give proper alignments or Indent while writing the joins to make the query more readable.

    Linto

  • I liked the article...I am amazed that people still use pre ansi-92 syntax...it has been over 10 yrs already.

    In addition to using ansi join syntax, I like to move the where clause restrictions to the join level where applicable...that way all of my join information is in the same spot.

  • quote:


    For the second best practice, i would like to add

    Give proper alignments or Indent while writing the joins to make the query more readable.


    Nice in theory, but it relies on everyone's Query Analyser being set to use the same font and font size.

    I've got both Enterprise Manager and Query Analyser using the same font and size but they still show indents at different positions.

    I've found that leaving blank lines between key blocks of SQL aids readability For example

    FROM dbo.Customers AS cust

     INNER JOIN dbo.Orders AS Ord

      ON cust.Id = Ord.CustomerId

     INNER JOIN dbo.OrderDetails as Det

      ON Ord.Id = Det.OrderId

    ========================

    He was not wholly unware of the potential lack of insignificance.

  • I second the recommendation on using ANSI joins. It's much clearer.

    However, it's important to remember that for outer joins the results may not be the same between ANSI and non-ANSI syntax. For ANSI syntax, the join logic is applied before the filter logic. For non-ANSI joins, the filter logic is applied before the join logic.

    Many articles have been published describing this.

    Because of this, I am always suspicious of the creators intent and/or skill when viewing non-ANSI joins.

    Larry Ansley

    Atlanta, GA


    Larry Ansley
    Atlanta, GA

  • I'd like to add to all the above threads.

    I tend to use two characters for table aliases; this generally works, because some tables pop up in almost every query, and you get quite familiar with them. For subqueries and other complex abstractions, I tend to use short words or phrases to make it clear what the subquery's doing.

    The specifics are vague and abstract, but there are certain forms or conditions where a (left?) outer join cannot be properly performed using pre-ANSI-92 [ANSI 89, right?] syntax. Exclusively using ANSI-92 avoids ever even having to think about this. (This issue is documented somewhere in BOL.)

    For spacing, I always use non-proportional fonts (for any coding job) and spaces for indentation, and that you can cut and paste most anywhere with impunity. I've developed a complex and rigorous code layout convention... but, when it comes right down to it, everyone has their own systems and standards, and getting anyone to agree on anything is about as productive as arguing religeon. Devise something that works for you, get others to use it if you can, adapt those parts of their conventions that make sense, and be prepared to be flexible. (I will say that I'd never add blank lines within a single T_SQL statement, no matter how long. I use blank lines to tell when one (long) statement has ended and the next one has begun.)

    Rather than "tit", would "git" be at all appropriate? (From and American who watched loads of Monty Python at a young and impressionable age...)

    And you missed "rouding out" the Hitchhiker's Guide / Database analogy. The immortal who'd set about insulting everyone (third book?) showed up early on and insulted Arthur Dent... and then showed up at the end of the book and did it again, only to realize "Wait a minute, didn't I already do you?" implying that his list was corrupt and he'd probably have to start all over again. Dude should have normalized his database...

    Philip

Viewing 15 posts - 1 through 15 (of 24 total)

You must be logged in to reply to this topic. Login to reply