Listing out the Column names in a view

Bandi
Posted by Bandi under Sql Server category on | Points: 40 | Views : 210
View Creation

CREATE VIEW viewEMP 
AS
SELECT EMPId, EMPname AS NAME FROM EMPLOYEE
GO


Two methods to get the column names of view

Method1:

SELECT v1.name FROM sys.columns v1 INNER JOIN sys.views v2 on V1.OBJECT_ID = V2.OBJECT_ID and V2.NAME = 'VIEWEMP'


OUTPUT:
name
-----
EMPId
NAME


Method2:
SELECT column_name AS ALIAS, data_type AS DataTYPE FROM information_schema.columns WHERE table_name = 'ViewEMP'
GO


OUTPUT:
ALIAS 	DataTYPE  
EMPId int
NAME varchar


--Clean up code
DROP VIEW ViewEMP

Comments or Responses

Login to post response