Solved

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

Posted on 2007-11-29
7
2,410 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
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
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.
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…

810 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