Solved

MS SQL Server 2000/2005 - Export view SQL to text file.

Posted on 2007-11-29
7
2,424 Views
Last Modified: 2012-05-05
Is there a way to export the actual SQL of all the views in a database?

I'd like to do this without purchasing software.

If there was a way to do this in ASP, even better!
0
Comment
Question by:xizwyck
[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
7 Comments
 
LVL 17

Expert Comment

by:Chris Mangus
ID: 20374593
From the database in question try:

select text from syscomments where text like 'Create View%'
0
 
LVL 18

Accepted Solution

by:
Sham Haque earned 500 total points
ID: 20375009
alternatively, use Enterprise Manager/Management Studio to do it for you (as CREATE VIEW scripts...):

right-click database > All Tasks > Generate SQL script
Click Show All
Tick All Views

Have a look at the Options tab
you can choose to create one long script or individual files per script
0
 
LVL 17

Expert Comment

by:Shanmuga Sundaram
ID: 20375027
This will display the list of views in your database.
select * from sysobjects where type ='V'
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 28

Expert Comment

by:sybe
ID: 20375744
Combining the code snippets below, you got it in ASP
Set oRS = Connection.OpenSchema(20)
Do While Not oRS.EOF
    If oRS("TABLE_TYPE").Value = "VIEW" Then 
        sViewName = oRS("TABLE_NAME").Value
    End If
oRS.MoveNext: Loop
oRS.Close
 
' ====
 
sViewName  = "vw_myview"
Set oRS = Connection.Execute("SELECT VIEW_DEFINITION FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME ='" & sViewName & "'")
sViewCode = oRS("VIEW_DEFINITION").Value

Open in new window

0
 
LVL 5

Expert Comment

by:ursangel
ID: 20380986
I think the easiest way to do this is the one cmangus:have suggested
Go to the Tasks -> Generate Scripts -> Select all views
and then generate the script.
0
 
LVL 17

Expert Comment

by:Chris Mangus
ID: 20381996
gbshahaq suggested that
0
 
LVL 3

Author Comment

by:xizwyck
ID: 20383502
Thanks gbshahaq! I set it to write to file, changed the extension to text and it worked great! I had tried something like that before but I was having write to a new tab.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
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…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

726 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