Solved

Copy View Between SQL Server Databases

Posted on 2007-04-11
3
2,521 Views
Last Modified: 2008-03-12
I am trying to find the SQL that will allow me to programmatically copy a view from one database to another.
0
Comment
Question by:hbash
  • 2
3 Comments
 
LVL 13

Expert Comment

by:Wizilling
Comment Utility
right click the view and select modify in Query Analyser (sql 2000)  or SQL Management Studio (sql 2005)
after the view is opened in a query window, change the word ALTER at the top few lines to the word CREATE.
change your connection to the other server / database.
press F5 or play button to execute the create view statement.
0
 
LVL 1

Author Comment

by:hbash
Comment Utility
Let me reiterate,  I want to "programmatically" copy a view.  What you are suggesting is using SQL Server tools.  The question is not how to format a Create View command or Alter View.

Thanks.
0
 
LVL 1

Accepted Solution

by:
hbash earned 0 total points
Comment Utility
Also,  the following snippet would retrieve the View's DDL as most likely the only way to achieve the view copy :

 sSQL = "select text From syscomments WHERE id = (SELECT id FROM sysobjects WHERE name = '" & sViewName & "')"


0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

13 Experts available now in Live!

Get 1:1 Help Now