View in SQL

--We will be using View to help us encapsulate our queries to form either temporary tables or 
permanent tables from pre-existing tables
CREATE VIEW derieved_table
AS
SELECT EName
 ,Eid
FROM Employee;

--this will create a new table named derieved_table from pre-existing table employee with 
just columns Ename and Eid 
--or somthing more complicated 
CREATE VIEW muj_view
AS
SELECT r.regiondescription
 ,t.territorydescription
 ,e.Lastname
 ,e.firstname
 ,e.hiredate
 ,e.reportsto
FROM region r
INNER JOIN territories t ON r.regionid = t.regionid
INNER JOIN Employeeterritories et ON t.territoryid = et.territoryid
INNER JOIN employees e ON et.employeeid = e.employeeid

--after all work is done you should drop view by 
DROP VIEW my_view;

Comments

Popular Posts