[dba-SQLServer] Automating the creation of views

sdunlap at brownshoe.com sdunlap at brownshoe.com
Thu Apr 23 08:20:31 CDT 2009


Hi,

I'm new to SQL Server and I've been tasked with creating a lot of views 
(over 100).  I'm using SQL Server 2005.

The process of creating these views will be repetitive, and I'm wondering 
if there is some way to automate the creation of the views.

More details on the task at hand...I have a whole bunch of views in a 
database, View1, View2, View3 ....... ViewN.  For the purposes of this 
example, this database would be called 'OriginalDatabase'.

In another database, the views I need to create will be:    SELECT  * FROM 
 OriginalDatabase.dbo.ViewX

In the SQL above, ViewX represents the view 1, 2, 3 or N.  I would want to 
be able to generate the list of Views (1, 2, 3 ... N) by programmatically 
reading the available views in the OriginalDatabase views folder and 
selecting only the views I need based on a naming convention - 
specifically, the first three characters of the view name = 'nnn'.

I have a book on SQL Server 2005, but I haven't been successful using the 
index to find help on this, mainly because I'm not sure what topic this 
would fall under. 

Does anyone know if it is possible to automate the creation of the views?

Any insight is appreciated.

Thanks,
Stu


More information about the dba-SQLServer mailing list