ExecuteNonQuery

  • Comments posted to this topic are about the item ExecuteNonQuery

  • This was removed by the editor as SPAM

  • Stewart "Arturius" Campbell (12/9/2015)


    Nice one, thanks Steve.

    Reminiscent of the C# method of the same name....

    and C++

  • Thanks for the question. Had to do some research.

  • Always thought this is a rather badly named function--ExecuteNonResults would be better, IMHO. ExecuteNonQuery implies it's not actually going to run the query, to my mind.

  • Thanks for the question.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • paul.knibbs (12/10/2015)


    Always thought this is a rather badly named function--ExecuteNonResults would be better, IMHO. ExecuteNonQuery implies it's not actually going to run the query, to my mind.

    Well, a query is a question, which implies an answer.

    That's why statement is a better general term to use for a unit of SQL code.

    You wouldn't expect an INSERT or UPDATE statement to return results (unless you use an OUTPUT clause). They would be non-query SQL statements; hence ExecuteNonQuery.

  • sknox (12/10/2015)

    Well, a query is a question, which implies an answer.

    So "NonQuery" implies you never asked the question in the first place, which is exactly the point I was making. ExecuteNonQuery is actually the equivalent of asking a rhetorical question--you ask the question expecting no answer--but ExecuteRhetorically would probably be just as confusing. 🙂

  • paul.knibbs (12/10/2015)


    sknox (12/10/2015)

    Well, a query is a question, which implies an answer.

    So "NonQuery" implies you never asked the question in the first place, which is exactly the point I was making. ExecuteNonQuery is actually the equivalent of asking a rhetorical question--you ask the question expecting no answer--but ExecuteRhetorically would probably be just as confusing. 🙂

    No, as the rest of my comment explained, ExecuteNonQuery means Execute a non-query SQL statement, such as an INSERT or UPDATE. There's nothing rhetorical about that. It's just differentiating statements from queries.

    I don't know for sure, but I'd guess the developers figured queries would be the majority of client-side activity (even actions such as inserting, updating, and deleting records are usually paired with a query to identify the records affected) so that was the assumption in Execute.

  • thanks for the question steve. brought some old memories back. 🙂

  • Nice question, but the tag is wrong; this isn't just powershell, it's a .NET framework method in several classes, available not only in powershell but also in C++, C#, VBS, F#, JavaScript, VB, .....

    Some people claim it's badly named: we have ExecuteWithResults for batches where at least one result set is to be returned to the caller, so maybe the case where no result sets are to be returned should be ExecuteWithoutResults? But when I execute batch I expect that execution to have some results (eg a table is created or a row is deleted or inserted or a procedure is dropped) whether or not it returns me any result sets so ExecuteWithoutResults would be a terrible name, and ExecuteWithResults is also a bad name - why isn't it ExecuteWithResultSets?.

    It's a pity that the result value -1 is used for three different things: (i) errors (ii) no rows were affected and (iii) no rowcounts were returned (ROWCOUNT ws off when any command affecting rows were executed). Maybe it can't reasonably be expected to distinguish (ii) from (iii) but it certainly ought to be able to tell whether there's been an error or not.

    Tom

  • TomThomson (12/11/2015)

    It's a pity that the result value -1 is used for three different things: (i) errors (ii) no rows were affected and (iii) no rowcounts were returned (ROWCOUNT ws off when any command affecting rows were executed). Maybe it can't reasonably be expected to distinguish (ii) from (iii) but it certainly ought to be able to tell whether there's been an error or not.

    I think that's down to the .NET philosophy that you should throw an exception rather than return an error value. In this case it ought to throw a SqlException when this happens, but the documentation says this only happens when "An exception occurred while executing the command against a locked row" or "a timeout occurred during a streaming operation", which seems a bit pointless really.

  • I don't even use PowerShell and got it without doing research.

  • Thanks for this nice question.

    I have been able to answer it only because , as I am more a C# programmer , I have used it as a method of the classes SqlConnection and ServerConnection ( SMO is my favorite part ).

Viewing 14 posts - 1 through 13 (of 13 total)

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