Copy View Between SQL Server Databases

I am trying to find the SQL that will allow me to programmatically copy a view from one database to another.
Howard BashSenior Software EngineerAsked:
Who is Participating?
Howard BashConnect With a Mentor Senior Software EngineerAuthor Commented:
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 & "')"

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.
Howard BashSenior Software EngineerAuthor Commented:
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.