• Jeff Moden (3/14/2013)


    Alan.B (3/7/2013)


    Cursors, loops and dSQL fall under the last choice column but this is one of those cases...

    For tables you would do this:

    EXEC sp_MSforeachtable'SELECT TOP 1 * FROM ?'

    BWAA-HAAA!!!! Oh, be careful now, Alan. You've just stated perhaps one of the greatest oxymorons of them all. Have you ever looked under the hood of sp_MSForEachTable? It's a monstorous LOOP! 😉

    Actually Jeff he said that cursors and loops fall under the last category but that this IS one time it is acceptable.

    I would of course recommend that anybody who wants to use any of the sp_MSForEach procs to crack them open and look at what they are doing.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/