﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Article Discussions / Article Discussions by Author / Discuss content posted by Divya  Agrawal  / Problem with scripting objects through query / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Wed, 22 May 2013 14:30:51 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Problem with scripting objects through query</title><link>http://www.sqlservercentral.com/Forums/Topic811370-1418-1.aspx</link><description>I have scripted the objects this way to script the triggers for a particular list of tables.</description><pubDate>Mon, 02 Nov 2009 06:00:19 GMT</pubDate><dc:creator>Divya Agrawal</dc:creator></item><item><title>RE: Problem with scripting objects through query</title><link>http://www.sqlservercentral.com/Forums/Topic811370-1418-1.aspx</link><description>[quote][b]Linson.Daniel (11/1/2009)[/b][hr]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?[/quote]For instance, when I want to see the definition of all objects that reference a particular linked server, or call a certain stored proc, or use OPENQUERY, or whatever else I'm interested in.  I usually use something like "SELECT definition FROM [?].sys.sql_modules WHERE definition LIKE '%xyz%' " as a parameter for sp_msforeachdb.</description><pubDate>Mon, 02 Nov 2009 05:36:03 GMT</pubDate><dc:creator>Scott Coleman</dc:creator></item><item><title>RE: Problem with scripting objects through query</title><link>http://www.sqlservercentral.com/Forums/Topic811370-1418-1.aspx</link><description>[quote]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?[/quote]Ohh hell ya!!! It does........From SQL 2K onwards it does have the option to script your entire database.....not sure about the earlier versions..</description><pubDate>Sun, 01 Nov 2009 21:25:43 GMT</pubDate><dc:creator>Linson.Daniel</dc:creator></item><item><title>RE: Problem with scripting objects through query</title><link>http://www.sqlservercentral.com/Forums/Topic811370-1418-1.aspx</link><description>[quote][b]Linson.Daniel (11/1/2009)[/b][hr]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? [/quote]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?</description><pubDate>Sun, 01 Nov 2009 19:52:38 GMT</pubDate><dc:creator>ankitwaitshere</dc:creator></item><item><title>RE: Problem with scripting objects through query</title><link>http://www.sqlservercentral.com/Forums/Topic811370-1418-1.aspx</link><description>Select datalength(object_definition(669622570))returns only 28700 - might be for this object with above ID.But when I display the value ofSelect object_definition(669622570)It just gives me the first few lines from the stored proc. Thoughts?</description><pubDate>Sun, 01 Nov 2009 19:50:34 GMT</pubDate><dc:creator>ankitwaitshere</dc:creator></item><item><title>RE: Problem with scripting objects through query</title><link>http://www.sqlservercentral.com/Forums/Topic811370-1418-1.aspx</link><description>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?</description><pubDate>Sun, 01 Nov 2009 18:56:38 GMT</pubDate><dc:creator>Linson.Daniel</dc:creator></item><item><title>RE: Problem with scripting objects through query</title><link>http://www.sqlservercentral.com/Forums/Topic811370-1418-1.aspx</link><description>[quote][b]ankitwaitshere (10/30/2009)[/b][hr].. 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??[/quote]According to BOL, OBJECT_DEFINITION returns nvarchar(max) in both SQL2005 and SQL2008 so it should be fine.</description><pubDate>Sat, 31 Oct 2009 01:01:31 GMT</pubDate><dc:creator>AUSteve</dc:creator></item><item><title>RE: Problem with scripting objects through query</title><link>http://www.sqlservercentral.com/Forums/Topic811370-1418-1.aspx</link><description>.. 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??</description><pubDate>Fri, 30 Oct 2009 20:57:43 GMT</pubDate><dc:creator>ankitwaitshere</dc:creator></item><item><title>RE: Problem with scripting objects through query</title><link>http://www.sqlservercentral.com/Forums/Topic811370-1418-1.aspx</link><description>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.[code]SELECT 'DROP PROCEDURE [' + SCHEMA_NAME([schema_id]) + '].[' + [name] + ']' + 'GO' + OBJECT_DEFINITION([object_id])+ '' + 'GO'FROM sys.objectsWHERE [name] = 'Test SP'[/code]</description><pubDate>Fri, 30 Oct 2009 07:59:37 GMT</pubDate><dc:creator>Scott Coleman</dc:creator></item><item><title>RE: Problem with scripting objects through query</title><link>http://www.sqlservercentral.com/Forums/Topic811370-1418-1.aspx</link><description>I typically just use a bunch of UNION ALL statements in my script building scripts</description><pubDate>Fri, 30 Oct 2009 07:51:05 GMT</pubDate><dc:creator>Chris Harshman</dc:creator></item><item><title>RE: Problem with scripting objects through query</title><link>http://www.sqlservercentral.com/Forums/Topic811370-1418-1.aspx</link><description>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.</description><pubDate>Fri, 30 Oct 2009 07:41:12 GMT</pubDate><dc:creator>Scott Coleman</dc:creator></item><item><title>RE: Problem with scripting objects through query</title><link>http://www.sqlservercentral.com/Forums/Topic811370-1418-1.aspx</link><description>I would change query a little[code="sql"]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'[/code]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</description><pubDate>Fri, 30 Oct 2009 02:55:23 GMT</pubDate><dc:creator>vitaly.maslevskiy</dc:creator></item><item><title>Problem with scripting objects through query</title><link>http://www.sqlservercentral.com/Forums/Topic811370-1418-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/articles/Incorrect+syntax+near+GO/68185/"&gt;Problem with scripting objects through query&lt;/A&gt;[/B]</description><pubDate>Fri, 30 Oct 2009 00:18:58 GMT</pubDate><dc:creator>Divya Agrawal</dc:creator></item></channel></rss>