Create views for all the tables in a Database with Column Names not *

SELECT
‘IF EXISTS(SELECT 1 FROM sys.objects WHERE name = ”vw’ + t.name + ”’ AND type = ”V”) BEGIN DROP VIEW [v_’ + t.name + ‘] END CREATE VIEW [vw’ + t.name + N] AS SELECT ‘ +
STUFF(
(SELECT N’,[‘ + c.name+’]’
FROM
sys.columns AS c
WHERE
c.OBJECT_ID = t.OBJECT_ID
ORDER BY
column_id
FOR XML PATH(”), TYPE).value(‘.’,’nvarchar(max)’)
,1,1,”)
+ ‘ FROM [‘ + t.name + N’]’ + char(10) + char(13) + ‘GO’ + char(10) + char(13)
FROM
sys.tables AS t

Leave a Reply

Your email address will not be published. Required fields are marked *