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 2005 Forums
 Transact-SQL (2005)
 Copying view logic from one DB to another

Author  Topic 

im1dermike
Posting Yak Master

222 Posts

Posted - 2008-10-03 : 12:12:21
I'm writing an application which I want to allow me to update the logic for a view in one or multiple databases with the logic for a view in a source database. I assume this will require me to:

1. Script the view definition to a file
2. Execute the file/query on database(s)

Can someone define exactly how this is done?

Thanks in advance.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-03 : 12:17:39
what do you mean by update the logic?
Go to Top of Page

im1dermike
Posting Yak Master

222 Posts

Posted - 2008-10-03 : 12:22:29
Here is my situation. I have a "master" (MGSDB) database, a copy of which gets made each month ("MGSDB_AUGUST", etc). Let's say an issue (a logic error or otherwise) is discovered and a change needs to be made to the logic in a view of all or some of the databases. Rather than make the change in up to 13 different databases, I want to be able to make the change in MGSDB and then be able to copy the logic into whichever other databases I'd like.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-03 : 12:45:19
are you talking about db copy or view copy?
Go to Top of Page

im1dermike
Posting Yak Master

222 Posts

Posted - 2008-10-03 : 13:11:45
Copying the logic of a view.

For example... the logic of View_1 in all the databases is "SELECT * FROM Table_1 WHERE X=2". I want to change it to "SELECT * FROM Table_1 WHERE X=4" in specific databases. So I want to be able to make the change in MGSDB and then transfer that logic to multiple databases.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-03 : 13:18:25
quote:
Originally posted by im1dermike

Copying the logic of a view.

For example... the logic of View_1 in all the databases is "SELECT * FROM Table_1 WHERE X=2". I want to change it to "SELECT * FROM Table_1 WHERE X=4" in specific databases. So I want to be able to make the change in MGSDB and then transfer that logic to multiple databases.


sp_helptext viewname 


will give you view logic.you need to apply this to other dbs.
Go to Top of Page

im1dermike
Posting Yak Master

222 Posts

Posted - 2008-10-03 : 13:25:01
Perfect. I think this is all I need. Thanks man.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-03 : 13:33:45
quote:
Originally posted by im1dermike

Perfect. I think this is all I need. Thanks man.


welcome
Go to Top of Page
   

- Advertisement -