dbTalk Databases Forums  

CREATE VIEW - script to automate column names?

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss CREATE VIEW - script to automate column names? in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
clir
 
Posts: n/a

Default CREATE VIEW - script to automate column names? - 03-12-2007 , 05:44 AM






Hi,

I'm trying to create views on all my existing tables and for that I'd
like to create a script or so.
I don't want to specify the '*' for the columns in the create view
statement. I prefer to specify the column names.
I have the column names int sys.columns table but Do not know how to
handle them to have a statement like that:

CREATE VIEW myVIEW
WITH SCHEMABINDING
AS
SELECT col1name, col2name, col3name, etc...
from sys.columns
....?????.....


Anyone can help?

thx,

Chris


Reply With Quote
  #2  
Old   
Tom van Stiphout
 
Posts: n/a

Default Re: CREATE VIEW - script to automate column names? - 03-13-2007 , 08:43 PM






On 12 Mar 2007 04:44:56 -0700, "clir" <christophe.leroquais (AT) gmail (DOT) com>
wrote:

Use a cursor to loop over the column names, all the while
concatenating a string variable. In the end, execute that string
(sp_executesql) and your view will be created.

-Tom.



Quote:
Hi,

I'm trying to create views on all my existing tables and for that I'd
like to create a script or so.
I don't want to specify the '*' for the columns in the create view
statement. I prefer to specify the column names.
I have the column names int sys.columns table but Do not know how to
handle them to have a statement like that:

CREATE VIEW myVIEW
WITH SCHEMABINDING
AS
SELECT col1name, col2name, col3name, etc...
from sys.columns
....?????.....


Anyone can help?

thx,

Chris


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.