Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Copying views

Author  Topic 

MarkyBoy666
Starting Member

14 Posts

Posted - 2004-12-21 : 05:19:56
Hi,

I've just created a stored procedure to create an archive version of an existing database by reconstructing tables, but now need to do the same to the views. Does anyone know of a quick way of copying a view from another db, using t-sql?

Thanks for any suggestions.

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2004-12-21 : 09:18:51
script out the CREATE VIEW statements using enterprise manager.

the result is just a text file, containing a T-SQL script you can run in query analyzer on any other database to re-generate all the views.

- Jeff
Go to Top of Page

heze
Posting Yak Master

192 Posts

Posted - 2007-06-05 : 13:10:02
hi, how can I copy programatically the script of the view from one db to another,
something like
delcare @myVar as varchar(8000)
set @myVar=(select viewScript from somewhere)
use [myTargetDb]
exec(@myVar)

thank you
Go to Top of Page

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2007-06-05 : 23:17:01
Or just run the script in different db.
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-06-06 : 03:23:00
"(select viewScript from somewhere)"

The "somewhere" thingie you are looking for is probably:

sp_HelpText 'MyView'

Kristen
Go to Top of Page

mahesh_bote
Constraint Violating Yak Guru

298 Posts

Posted - 2007-06-06 : 03:40:03
quote:
Originally posted by MarkyBoy666

Hi,

I've just created a stored procedure to create an archive version of an existing database by reconstructing tables, but now need to do the same to the views. Does anyone know of a quick way of copying a view from another db, using t-sql?

Thanks for any suggestions.



Why don't u use the DTS wizard to do such task?

Mahesh
Go to Top of Page

heze
Posting Yak Master

192 Posts

Posted - 2007-06-06 : 06:51:28
thank you so much K, thats exactly what I was looking for.
MB, Im allways a little bit hesitant to use DTS for small tasks, why would I use dts if I can code it and put it in a stored procedure?

Go to Top of Page
   

- Advertisement -