t-sql stored procedure create scripts

You can right-click on the database in the Object Explorer and do a Task > Generate Scripts.

alt text

That allows you to pick a whole bunch of objects to be scripted (e.g. tables, views, stored procs) and you can store those into a single big SQL file, or one SQL file per object. Works really quite well!

Update: if you want to do this in the SQL Server Management Studio app, you can use this SQL script to find the stored procs and their definitions - you cannot however have SQL Server Mgmt Studio write out the files to disk, that doesn't work - but you can copy the results into e.g. Excel.

SELECT 
    pr.name ,
    pr.type_desc ,
    pr.create_date ,
    mod.definition
FROM sys.procedures pr
INNER JOIN sys.sql_modules mod ON pr.object_id = mod.object_id
WHERE pr.Is_MS_Shipped = 0

To script out all ones matching a particular criteria you could use something like the below.

DECLARE @t VARCHAR(max) = '';
SELECT @t = @t +
 'If OBJECT_ID(''' + QUOTENAME(OBJECT_SCHEMA_NAME(object_id)) + '.' +  QUOTENAME(OBJECT_NAME(object_id)) + ''',''p'') IS NOT NULL
    DROP PROCEDURE ' + QUOTENAME(OBJECT_SCHEMA_NAME(object_id)) + '.' +  QUOTENAME(OBJECT_NAME(object_id)) + '
GO

SET ANSI_NULLS '
            + CASE
                WHEN uses_ansi_nulls = 1 THEN 'ON'
                ELSE 'OFF'
              END
            + '
GO

SET QUOTED_IDENTIFIER '
            + CASE
                WHEN uses_quoted_identifier = 1 THEN 'ON'
                ELSE 'OFF'
              END
            + '
GO

' + definition + ' 
GO

'
FROM   [sys].[sql_modules]
WHERE  OBJECTPROPERTY (object_id,'IsProcedure' )=1
       AND OBJECT_NAME(object_id) LIKE '%some_patttern%'


/*Stops the long text from getting truncated in SSMS*/
SELECT @t AS [processing-instruction(x)]
FOR XML PATH('')