Solved

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

Posted on 2007-11-29
7
2,387 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

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.

Join & Write a Comment

Suggested Solutions

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
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/…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
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…

746 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

12 Experts available now in Live!

Get 1:1 Help Now