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