forked from SeemaSP/shoppingjquerycart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3 - Introduction to Views.sql
59 lines (41 loc) · 1.41 KB
/
3 - Introduction to Views.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
-- Demonstration 3 - Introduction to views
-- Step 1 - Open a new query window to the AdventureWorks database
USE AdventureWorks;
GO
-- Step 2 - Create a new view
CREATE VIEW Person.IndividualsWithEmail1
AS
SELECT p.BusinessEntityID, Title, FirstName, MiddleName, LastName, E.EmailAddress
FROM Person.Person AS p
JOIN Person.EmailAddress as e
on p.BusinessEntityID=e.BusinessEntityID;
GO
-- Step 3 - Query the view
SELECT * FROM Person.IndividualsWithEmail1;
GO
-- Step 4 - Again query the view and order the results
SELECT *
FROM Person.IndividualsWithEmail
ORDER BY LastName desc;
GO
-- Step 5 - Query the view definition via OBJECT_DEFINITION
SELECT OBJECT_DEFINITION(OBJECT_ID(N'Person.IndividualsWithEmail1',N'V'));
GO
--V = View object type
-- Step 6 - Alter the view to use WITH ENCRYPTION
ALTER VIEW Person.IndividualsWithEmail1
WITH ENCRYPTION
AS
SELECT p.BusinessEntityID, Title, FirstName, MiddleName, LastName
FROM Person.Person AS p
JOIN Person.EmailAddress as e
on p.BusinessEntityID=e.BusinessEntityID;
-- Step 7 - Requery the view definition via OBJECT_DEFINITION
SELECT OBJECT_DEFINITION(OBJECT_ID(N'Person.IndividualsWithEmail',N'V'));
GO
--output:NULL
-- Step 8 - Drop the view
DROP VIEW Person.IndividualsWithEmail;
GO
-- Step 9 - Script the existing HumanResources.vEmployee view
-- to a new query window and review its definition.