• bvs23bkv33 (unregistered)

    select top 1 comment from comments; --all of comments!!

  • guest (unregistered) in reply to bvs23bkv33


  • (nodebb)

    What language is this with "SELECT TOP 10"? I'm used to seeing "SELECT .... LIMIT 10".

  • Flips (unregistered)

    10 orders ought to be enough for everybody

  • Web Design Chicago (unregistered)

    I just want to say, you explained this topic very well. Website is must now for every business and writer to express the information so we are here to help you Chicago web Design. thank for the post and all the best.

  • Dude (unregistered) in reply to Rosuav

    T-SQL (for MSSQL) uses the syntax of "SELECT TOP [number] [fieldList]..."

  • Raj (unregistered) in reply to Rosuav

    Count your blessings. With limit 10 (postgresql, MySQL) or top 10 (SQL server) the limit is not part of the query and the database will figure things out.

    With our friend Oracle, you have to add a where clause on the fake column rownum, which interestingly is applied before the order by, leading to all kinds of interesting side effects.

  • Scott (unregistered)
    • for certain values of "all".
  • Brian Boorman (google)

    Was this query called from anywhere else? Perhaps it was a stub that was never completed. In that case, the WTF is not pruning unused code.

  • Chris L (unregistered)

    Someone leaving in some debugging code counts as a WTF?

  • PSql (unregistered)

    Please do not ever require all your queries to be backed by stored procedures, why would you even do that to yourself ><

  • Yazeran (unregistered) in reply to PSql


    I can understand that all inserts or updates have to go through SP's, but selects???, that's what views are for...


    Plan: To go to Mars one day with a hammer

  • Ali Razeghi (google) in reply to Rosuav

    LIMIT 10 at the end would be MySQL but T-SQL used by MS SQL does a SELECT TOP X (column list or *)

  • Ali Razeghi (google) in reply to Yazeran

    I'd say any query that is to be ran automatically as part of an app would benefit a lot from being a stored procedure unless you have an excellent reason to use an 'anti-pattern'. Maybe it's a query that's to be ran during a upgrade which only happens once. A Stored Procedure also lets you avoid having to recompile your application and instead just change the proc in the background, submitting the latest version to Git.

    A problem and a benefit with a stored proc is a plan reuse. If the table changes heavily and statistics aren't kept up to date reusing a plan could cause a out of date bad plan to be executed which could take longer than just recreating a new execution plan. In most cases though stats are kept up to date and the query plans work out very well saving the app and more importantly the DB CPU a lot of time.

  • I Am A Robot (unregistered)

    WTF is guessing what ANYTHING does just by the name? Book <> Cover.

  • FormalWare (unregistered)

    Vestigial organs make it to Production all the time - both in cyberspace and meatspace.

  • I Am A Robot (unregistered)

    Actually the name is GetA11Orders and it was working correctly.

  • Sole Purpose of Visit (unregistered) in reply to I Am A Robot

    That obvious point appears to have escaped both Remy and every other commentor so far.

    There's probably an actual WTF behind this, in which they feed every single customer order into an Excel spreadsheet and then do ... something ... to it.

    But, as presented, it's just an "oh well. Too bad the name doesn't feature the number 10. Who really cares?" sort of thing.

  • Jeremy Hannon (google) in reply to Ali Razeghi

    "A problem and a benefit with a stored proc is a plan reuse"

    Plan Reuse is not really an issue with Microsoft SQL since SQL 2005 due to auto-parametarization of queries. If you are writing proper code and using a data layer (ORM or otherwise), or at least using parameterized queries it is not a problem anyway because those get sent to the server parameterized and get into the query plan cache just like stored procedures. If you are doing string-concatenation inside of a stored proc, all of the claimed security and performance benefits of stored procedures go out the window.

    To be honest, the added complexity, lookups, and maintenance etc of stored procedures in combination with developer code can make stored procedures to be more work for no gain at all. Usually I recommend a proper ORM setup for most things and stored procedures sparingly. There are times where stored procedures can be significantly faster - especially when working with temp tables and avoiding round trips. For most work, though, it is just extra overhead.

  • Deez (unregistered)

    Yasmin, being a smart prograammer

    Is that Dutch?

  • Down under (unregistered) in reply to Raj

    Unless, of course, you use Oracle's FETCH FIRST n ROWS ONLY clause, which behaves pretty much like the others.

  • Greg (unregistered) in reply to Deez

    No, that would be "programmeur".

  • AP (unregistered) in reply to Deez

    No, it's in Typo.

  • (nodebb) in reply to Down under

    Not specifically Oracle's FETCH FIRST. It is ANSI SQL:2008 standard, unlike all the other dialects like TOP and LIMIT.

  • Barf4Eva (unregistered) in reply to Jeremy Hannon

    Funny, I feel that way about people who DON'T use sprocs across the board... They simply not handling the complexity in a helpful way... Whereas procedures encapsulate a level of complexity and give a layer of separation that helps me to research more DB-centric scenarios. Making it easier to navigate the complexity.

    Muddied-up DALs and hiding complexity behind Linq-to-SQL will make research and review on very large teams problematic, in my opinion/experience. Especially when multiple applications perhaps must interface w/ this DB.

  • Barf4Eva (unregistered)

    To each their own tho. I'm no hater. Sprocs work great as a tool for me, however.

  • Donald Knuth (unregistered) in reply to Ali Razeghi

    1998 calling - they want their data access style back!

  • Definitely not John (unregistered)

    It's always about context. If you have widget, where you need to display 10 orders, you might write query getAllOrders() so you get all orders you need to display.

Leave a comment on “All the Things!”

Log In or post as a guest

Replying to comment #:

« Return to Article