Solved

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

Posted on 2007-11-29
7
2,432 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
Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

 
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
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.

691 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