Solved

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

Posted on 2007-11-29
7
2,400 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to shrink a transaction log file down to a reasonable size.

867 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now