|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Yesterday @ 4:59 AM
Points: 139,
Visits: 469
|
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Tuesday, July 13, 2010 11:38 PM
Points: 52,
Visits: 6
|
|
I would change query a little
select 'DROP PROCEDURE ['+ si.name + '].[' + so.name + ']'+ CHAR(13)+CHAR(10)+'GO'+CHAR(13)+CHAR(10)+ OBJECT_DEFINITION(object_id)+ CHAR(13)+CHAR(10)+'GO'+CHAR(13)+CHAR(10)
from sys.objects so inner join sys.schemas si ON so.schema_id = si.schema_id where so.type='P'
1. Add brackets to procedure name if proc name is "non standard" 2. Add join with sys.schemas for procedures not in dbo/current user schema
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: 2 days ago @ 11:38 AM
Points: 2,818,
Visits: 1,037
|
|
You don't need carriage return for a valid end-of-line sequence, only line feed. Drop the CHAR(13) and just use CHAR(10) and it works fine.
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Yesterday @ 7:19 AM
Points: 1,562,
Visits: 1,716
|
|
| I typically just use a bunch of UNION ALL statements in my script building scripts
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: 2 days ago @ 11:38 AM
Points: 2,818,
Visits: 1,037
|
|
The line breaks can be included in the literal strings, so you don't need to worry about which characters are used. You do have to put " ' + ' " in front of any GO however.
SELECT 'DROP PROCEDURE [' + SCHEMA_NAME([schema_id]) + '].[' + [name] + '] ' + 'GO ' + OBJECT_DEFINITION([object_id])+ ' ' + 'GO' FROM sys.objects WHERE [name] = 'Test SP'
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Thursday, August 26, 2010 4:50 PM
Points: 13,
Visits: 45
|
|
.. All fine... but Why do I need OBJECT_DEFINITION(1234567) there...?? Is this to create the stored proc back?
If so, it may not be possible as the function OBJECT_DEFINITION(1234567) returns only first few hundred chars I think...
Thoughts??
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Tuesday, March 12, 2013 12:34 AM
Points: 344,
Visits: 178
|
|
ankitwaitshere (10/30/2009) .. All fine... but Why do I need OBJECT_DEFINITION(1234567) there...?? Is this to create the stored proc back?
If so, it may not be possible as the function OBJECT_DEFINITION(1234567) returns only first few hundred chars I think...
Thoughts??
According to BOL, OBJECT_DEFINITION returns nvarchar(max) in both SQL2005 and SQL2008 so it should be fine.
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Saturday, March 02, 2013 8:26 PM
Points: 312,
Visits: 367
|
|
| Then again....would someone tell me why would I go about generating scripts like the way that was shown here when SQL server itself provides all the necessary options to script your db objects?
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Thursday, August 26, 2010 4:50 PM
Points: 13,
Visits: 45
|
|
Select datalength(object_definition(669622570))
returns only 28700 - might be for this object with above ID.
But when I display the value of Select object_definition(669622570)
It just gives me the first few lines from the stored proc. Thoughts?
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Thursday, August 26, 2010 4:50 PM
Points: 13,
Visits: 45
|
|
Linson.Daniel (11/1/2009) Then again....would someone tell me why would I go about generating scripts like the way that was shown when SQL server itself provides all the necessary options to create your db objects?
May be if someone wants scripts for many objects all in one shot... not sure if SQL-Server does that for many objects at a time. Does it?
|
|
|
|