• Declaring a cursor with all the sp names, and then execute sp_helptext for each one.

    DECLARE @sp AS SYSNAME

    DECLARE curSP CURSOR LOCAL FOR

    SELECT name

    FROM sysobjects

    WHERE xtype = 'P'

    ORDER BY NAME

    OPEN curSP

    FETCH NEXT FROM curSP INTO @sp

    WHILE (@@FETCH_STATUS = 0)

    BEGIN

    PRINT 'Scripting sp ' + @sp + '...'

    EXEC ('EXEC sp_helptext ' + @sp)

    FETCH NEXT FROM curSP INTO @sp

    END

    CLOSE CurSp

    DEALLOCATE curSP