[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Ability to export the sql behind a SP / view / query to an ascii file ?

Posted on 2004-03-23
5
Medium Priority
?
571 Views
Last Modified: 2012-05-04
Is there a way that I can export the SQL behind a stored procedure or view, into a text file, or preferably into a recordset string field.

My absolute ideal would to have a stored procedure that returns a recordset with the database object name and the SQL in the object, be it a stored procedure or a view, that I can use to get ascii copies of all my db objects, such that I can see their progress over time in CVS.

Any ideas ?

Regards
Marts
0
Comment
Question by:mj_cole
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 34

Assisted Solution

by:arbert
arbert earned 1000 total points
ID: 10663811
sure, if you want it in a recordset, just execute the sp_helptext stored proc with the stored procedure you want the text of:

rs=conn.execute("sp_helptext mystoredproc")


You can also right click on your database (in enterprise manager) and generate SQL Scripts for your entire database or certain objects.

Brett
0
 
LVL 34

Expert Comment

by:arbert
ID: 10663818
You can also write queries against the information.schema_views (located in the master database) to retrieve information....

Brett
0
 

Author Comment

by:mj_cole
ID: 10664298
sp_helptext  seems to do the job :)

is there a master SP to return all the stored procedures and views, such that I can then write my own SP to get the list and then call sp_helptext on that list ?

Regards
Marts

0
 
LVL 34

Accepted Solution

by:
arbert earned 1000 total points
ID: 10664412
Nope, but that's where the information_schema.views come in.....

You can run this from your database and it will list the procs and views for you:

select 'proc', routine_name from information_schema.routines
union
select 'View',view_name from information_schema.view_table_usage

However, using the information schema views, you can also return the text of the views and procs and you don't have to use sp_helptext.

Brett
0
 
LVL 70

Expert Comment

by:Scott Pletcher
ID: 10669100
Actually I think the information_schema views only return the first 4K of object text, so it's not a safe way to get the source.  You really need to use sp_helptext.
0

Featured Post

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question