SlideShare a Scribd company logo
Sql server  ___________session_16(views)
 A view is an "VirtualTable".
 It can have multiple columns and rows from the
one or more table.
 Normally view cannot store the data
permanently in the table.
 Views display only those data which are
mentioned in the query.
 A view consists of a SELECT statement
Sql server  ___________session_16(views)
 Views are used as Security Mechanism of Database.
 A view can be useful when there are multiple users with different levels
of access, who all need to see portions of the data in the database.
 Views can do the following:
 Restrict access to specific rows in a table
 Restrict access to specific columns in a table
 Join columns from multiple tables and present them as though they
are part of a single table
 Present aggregate information (such as the results of the COUNT
function).
‘EmpInfo’Table:
General syntax for creating a view:
CREATEVIEW [View_Name]
AS
[SELECT Statement]
As for example :
CREATEVIEW SampleView
As
SELECT EmpID, EmpName FROM
EmpInfo
 This is as similar as select statement of a
table.
SELECT * FROM SampleView
 General syntax:
DROPVIEW viewname;
 Example:
DROPVIEW SampleView;
 When a view is dropped, it has no effect on the underlying
tables.
 Dropping a view removes its definition and all the
permissions assigned to it.

 However, dropping a table that references a view does not
drop the view automatically.
 You must drop it explicitly.
 General syntax:
ALTERVIEW viewname
AS
SELECT…;
 Example:
ALTERVIEW SampleView
AS
SELECT * FROM EmpInfo;
The value for the column is provided
automatically if:
 The column has an IDENTITY property.
 The column has a default value specified.
 The column has a timestamp data type.
 The column takes null values.
 The column is a computed column.
 The value of a column with an IDENTITY
property cannot be updated.
 Records cannot be updated if the base table
contains aTIMESTAMP column.
 While updating a row, if a constraint or rule is
violated, the statement is terminated, an error is
returned, and no records are updated.
 When there is a self-join with the same view or
base table, the UPDATE statement does not
work.
 There are 3 methods to see the view definition:
 Method 1:
Sp_helptext viewname;
 Method 2:
select definition from sys.sql_modules
where object_id=object_id(‘viewname');
 Method 3:
select object_definition(object_id('vv'));
 The sys.sql_modules is a system view. It is
used to display view definition.
 Object_definition() is built-in function that
returns the view definition.
 Object_id() is a system function that returns
the ID of view.
Sql server  ___________session_16(views)
 There are two types of views in the sql server
2005.
 Normal or Standard view
 Partitioned view
 This view is most frequently used by the
developers.
 When we create the view the schema will be
stored as object in the database.
 When we retrieve the content from this virtual
table, it will execute the schema and the stored
data from the parent table.
 These include focusing on specific data and
simplifying data manipulation.
 CREATEVIEW vw_empinfo
AS
SELECT * FROM EmpInfo;
 SELECT * FROM vw_empinfo;
 INSERT INTO vw_empinfo
VALUES(4,’abcd’,’.NET’,565652);
 DELETE FROM vw_empinfo WHERE EmpID = 1;
Here you can do the DML operations in the view when you
have only one table.
 The partitioned view and its execution is like
normal view.
 It will work across the database and across
the server.
 There are two types of Partitioned views.
 Local PartitionedView
 Global PartitionedView
 The local partitioned view can be created
within same server but different database.
 The view schema definition will be stored in
the executed database.
 USE Database1
CREATETABLE EmployeeList
(
iEmployeeID INT IDENTITY(1,1),
vFirstNameVARCHAR(25) NOT NULL,
vLastNameVARCHAR(25) NOT NULL,
iDeptID INT
)
 USE Database2
CREATETABLE Department
(
iDeptID INT IDENTITY(1,1) PRIMARY KEY,
vDeptNameVARCHAR(50),
)
CREATEVIEW vw_LocalPartion_View
AS
SELECT E.iEmployeeID, D.vDeptName
FROM EmployeeList E
INNER JOIN
Database2.dbo.Department D ON D.iDeptID = E.iDeptID ;
 The global Partitioned view will work across the server.
 The view can be created to join the table across the server.
 The accessing format will be like this.
[Server Name]. Database Name.Table Name
 When we execute the view if it is not linked with the current
server then it will ask us to link the external server.
 The following system stored procedure will be used
to link the server.
sp_addlinkedserver 'Server name'
 The following system catalog table is used to see
the list of linked servers.
SELECT * FROM SYS.SERVERS
 There are two different option for creating a
view.
 Schema Binding Option
 Encryption
 If we Creates a view with the SCHEMABINDING option it will
locks the tables being referred by the view and restrict any
kinds of changes that may change the table schema ( No
Alter Command) .
 While creating schema binding view, we can't mention
"Select * from tablename" with the query.
 We have to mention all the column name for reference
CREATEVIEW DemoSampleView
With SCHEMABINDING
As
SELECT EmpID, EmpName, FROM DBO.EmpInfo;
 While specifying the Database name we have
use Dbo.[DbName] .
 This will prevent any of the underlying tables
from being altered without the view being
dropped.
Sql server  ___________session_16(views)
 This option encrypts the definition.
 This option encrypts the definition of the view.
 Users will not be able to see the definition of
theView after it is created.
 This is the main adavatages of view where we
can make it secure.
 Note: Once view is encrypted, there is no way
to decrypt it again.
CREATEVIEW DemoView
With ENCRYPTION
Select ename,edesig from dbo.EmpInfo

More Related Content

What's hot (14)

PDF
Sql ch 13 - sql-views
Mukesh Tekwani
 
PPTX
Sql basic things
Nishil Jain
 
ODP
Prabu's sql quries
Prabu Cse
 
PPTX
Oracle: Procedures
DataminingTools Inc
 
ODP
My sql Syntax
Reka
 
PDF
SQL Functions - Oracle SQL Fundamentals
MuhammadWaheed44
 
ODP
Sql commands
Balakumaran Arunachalam
 
PPTX
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
LGS, GBHS&IC, University Of South-Asia, TARA-Technologies
 
DOC
Pl sql using_xml
Nayana Arewar
 
PPTX
View
Pooja Dixit
 
PPTX
Commands of DML in SQL
Ashish Gaurkhede
 
PPTX
Rapid postgresql learning, part 3
Ali MasudianPour
 
PPTX
Database Management - Lecture 2 - SQL select, insert, update and delete
Al-Mamun Sarkar
 
Sql ch 13 - sql-views
Mukesh Tekwani
 
Sql basic things
Nishil Jain
 
Prabu's sql quries
Prabu Cse
 
Oracle: Procedures
DataminingTools Inc
 
My sql Syntax
Reka
 
SQL Functions - Oracle SQL Fundamentals
MuhammadWaheed44
 
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
LGS, GBHS&IC, University Of South-Asia, TARA-Technologies
 
Pl sql using_xml
Nayana Arewar
 
Commands of DML in SQL
Ashish Gaurkhede
 
Rapid postgresql learning, part 3
Ali MasudianPour
 
Database Management - Lecture 2 - SQL select, insert, update and delete
Al-Mamun Sarkar
 

Viewers also liked (7)

PDF
Creative Play UK- The Outdoor Play Experts
Paul Gambino
 
PPT
Manuel de survie de l'Innovateur
Simon Guimezanes
 
PPTX
Release Planning Days - The story of a ritual @ Meetic
Marika Prince, PMP
 
PDF
PeopleLink Corporate Brochure-2016
PeopleLink Unified Communications Pvt. Ltd.
 
PDF
Problem Interview exercice for OCTO meetup
Franck Debane
 
PDF
The Outlook For Telehealth And CSP Early Movers
Sherrie Xiaoyu HUANG
 
PDF
мультимедіа1
Slovyansk School
 
Creative Play UK- The Outdoor Play Experts
Paul Gambino
 
Manuel de survie de l'Innovateur
Simon Guimezanes
 
Release Planning Days - The story of a ritual @ Meetic
Marika Prince, PMP
 
PeopleLink Corporate Brochure-2016
PeopleLink Unified Communications Pvt. Ltd.
 
Problem Interview exercice for OCTO meetup
Franck Debane
 
The Outlook For Telehealth And CSP Early Movers
Sherrie Xiaoyu HUANG
 
мультимедіа1
Slovyansk School
 
Ad

Similar to Sql server ___________session_16(views) (20)

PPTX
Designing and Creating Views, Inline Functions, and Synonyms
Tayba Farooqui
 
PPTX
SQL lab number 10 in database system ppt
MUHAMMADANSAR76
 
PDF
RDBMS Lecture Notes Unit4 chapter12 VIEW
Murugan Solaiyappan
 
PPT
Views
Rahul Gupta
 
PDF
Implementing views
sqlschoolgr
 
PPT
Module05
Sridhar P
 
PPT
Oracle training institute in hyderabad
appaji intelhunt
 
PPT
Oracle view
Madhavendra Dutt
 
PPT
chap 9 dbms.ppt
arjun431527
 
PPT
SQL WORKSHOP::Lecture 12
Umair Amjad
 
PDF
Sql viwes
Huda Alameen
 
PPTX
V28 view
Dhirendra Chauhan
 
PPTX
Oracle Database View
Eryk Budi Pratama
 
PPT
Creating other schema objects
Syed Zaid Irshad
 
PPT
Les12
arnold 7490
 
PPT
Les10
Sudharsan S
 
PPTX
Oracle views
Balqees Al.Mubarak
 
PPTX
View
LakshmiSamivel
 
Designing and Creating Views, Inline Functions, and Synonyms
Tayba Farooqui
 
SQL lab number 10 in database system ppt
MUHAMMADANSAR76
 
RDBMS Lecture Notes Unit4 chapter12 VIEW
Murugan Solaiyappan
 
Implementing views
sqlschoolgr
 
Module05
Sridhar P
 
Oracle training institute in hyderabad
appaji intelhunt
 
Oracle view
Madhavendra Dutt
 
chap 9 dbms.ppt
arjun431527
 
SQL WORKSHOP::Lecture 12
Umair Amjad
 
Sql viwes
Huda Alameen
 
Oracle Database View
Eryk Budi Pratama
 
Creating other schema objects
Syed Zaid Irshad
 
Oracle views
Balqees Al.Mubarak
 
Ad

More from Ehtisham Ali (17)

PPT
Android tutorial
Ehtisham Ali
 
PPTX
Sql server ___________session_20(ddl triggers)
Ehtisham Ali
 
PPTX
Sql server ___________session3-normailzation
Ehtisham Ali
 
PPTX
Sql server ___________session2-data_modeling
Ehtisham Ali
 
PPTX
Sql server ___________session_19(triggers)
Ehtisham Ali
 
PPTX
Sql server ___________session_18(stored procedures)
Ehtisham Ali
 
PPTX
Sql server ___________session_17(indexes)
Ehtisham Ali
 
PPTX
Sql server ___________session_15(data integrity)
Ehtisham Ali
 
PPTX
Sql server ___________session_11-12(joins)
Ehtisham Ali
 
PPTX
Sql server ___________session_10(group by clause)
Ehtisham Ali
 
PPT
Sql server ___________session_1-intro
Ehtisham Ali
 
PPT
Sql server ___________session 3(sql 2008)
Ehtisham Ali
 
PPT
Sql server ___________session 2(sql 2008)
Ehtisham Ali
 
PPT
Sql server ___________session 1(sql 2008)
Ehtisham Ali
 
PPTX
Sql server ___________data type of sql server
Ehtisham Ali
 
PPTX
Sql server ___________data control language
Ehtisham Ali
 
PPTX
Sql server ___________ (advance sql)
Ehtisham Ali
 
Android tutorial
Ehtisham Ali
 
Sql server ___________session_20(ddl triggers)
Ehtisham Ali
 
Sql server ___________session3-normailzation
Ehtisham Ali
 
Sql server ___________session2-data_modeling
Ehtisham Ali
 
Sql server ___________session_19(triggers)
Ehtisham Ali
 
Sql server ___________session_18(stored procedures)
Ehtisham Ali
 
Sql server ___________session_17(indexes)
Ehtisham Ali
 
Sql server ___________session_15(data integrity)
Ehtisham Ali
 
Sql server ___________session_11-12(joins)
Ehtisham Ali
 
Sql server ___________session_10(group by clause)
Ehtisham Ali
 
Sql server ___________session_1-intro
Ehtisham Ali
 
Sql server ___________session 3(sql 2008)
Ehtisham Ali
 
Sql server ___________session 2(sql 2008)
Ehtisham Ali
 
Sql server ___________session 1(sql 2008)
Ehtisham Ali
 
Sql server ___________data type of sql server
Ehtisham Ali
 
Sql server ___________data control language
Ehtisham Ali
 
Sql server ___________ (advance sql)
Ehtisham Ali
 

Recently uploaded (20)

PPTX
Latest Features in Odoo 18 - Odoo slides
Celine George
 
PPTX
classroom based quiz bee.pptx...................
ferdinandsanbuenaven
 
PPTX
How to Define Translation to Custom Module And Add a new language in Odoo 18
Celine George
 
PPTX
GENERAL METHODS OF ISOLATION AND PURIFICATION OF MARINE__MPHARM.pptx
SHAHEEN SHABBIR
 
PDF
Comprehensive Guide to Writing Effective Literature Reviews for Academic Publ...
AJAYI SAMUEL
 
PPTX
CLEFT LIP AND PALATE: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
PPTX
Maternal and Child Tracking system & RCH portal
Ms Usha Vadhel
 
PPTX
LEGAL ASPECTS OF PSYCHIATRUC NURSING.pptx
PoojaSen20
 
PPTX
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
PPSX
Health Planning in india - Unit 03 - CHN 2 - GNM 3RD YEAR.ppsx
Priyanshu Anand
 
PPTX
Mrs Mhondiwa Introduction to Algebra class
sabinaschimanga
 
PDF
Living Systems Unveiled: Simplified Life Processes for Exam Success
omaiyairshad
 
PPT
digestive system for Pharm d I year HAP
rekhapositivity
 
PPTX
IDEAS AND EARLY STATES Social science pptx
NIRANJANASSURESH
 
PPTX
ENGLISH LEARNING ACTIVITY SHE W5Q1.pptxY
CHERIEANNAPRILSULIT1
 
PPTX
Folding Off Hours in Gantt View in Odoo 18.2
Celine George
 
PPTX
ABDOMINAL WALL DEFECTS:GASTROSCHISIS, OMPHALOCELE.pptx
PRADEEP ABOTHU
 
PDF
FULL DOCUMENT: Read the full Deloitte and Touche audit report on the National...
Kweku Zurek
 
PPTX
Various Psychological tests: challenges and contemporary trends in psychologi...
santoshmohalik1
 
PPTX
nutriquiz grade 4.pptx...............................................
ferdinandsanbuenaven
 
Latest Features in Odoo 18 - Odoo slides
Celine George
 
classroom based quiz bee.pptx...................
ferdinandsanbuenaven
 
How to Define Translation to Custom Module And Add a new language in Odoo 18
Celine George
 
GENERAL METHODS OF ISOLATION AND PURIFICATION OF MARINE__MPHARM.pptx
SHAHEEN SHABBIR
 
Comprehensive Guide to Writing Effective Literature Reviews for Academic Publ...
AJAYI SAMUEL
 
CLEFT LIP AND PALATE: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
Maternal and Child Tracking system & RCH portal
Ms Usha Vadhel
 
LEGAL ASPECTS OF PSYCHIATRUC NURSING.pptx
PoojaSen20
 
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
Health Planning in india - Unit 03 - CHN 2 - GNM 3RD YEAR.ppsx
Priyanshu Anand
 
Mrs Mhondiwa Introduction to Algebra class
sabinaschimanga
 
Living Systems Unveiled: Simplified Life Processes for Exam Success
omaiyairshad
 
digestive system for Pharm d I year HAP
rekhapositivity
 
IDEAS AND EARLY STATES Social science pptx
NIRANJANASSURESH
 
ENGLISH LEARNING ACTIVITY SHE W5Q1.pptxY
CHERIEANNAPRILSULIT1
 
Folding Off Hours in Gantt View in Odoo 18.2
Celine George
 
ABDOMINAL WALL DEFECTS:GASTROSCHISIS, OMPHALOCELE.pptx
PRADEEP ABOTHU
 
FULL DOCUMENT: Read the full Deloitte and Touche audit report on the National...
Kweku Zurek
 
Various Psychological tests: challenges and contemporary trends in psychologi...
santoshmohalik1
 
nutriquiz grade 4.pptx...............................................
ferdinandsanbuenaven
 

Sql server ___________session_16(views)

  • 2.  A view is an "VirtualTable".  It can have multiple columns and rows from the one or more table.  Normally view cannot store the data permanently in the table.  Views display only those data which are mentioned in the query.  A view consists of a SELECT statement
  • 4.  Views are used as Security Mechanism of Database.  A view can be useful when there are multiple users with different levels of access, who all need to see portions of the data in the database.  Views can do the following:  Restrict access to specific rows in a table  Restrict access to specific columns in a table  Join columns from multiple tables and present them as though they are part of a single table  Present aggregate information (such as the results of the COUNT function).
  • 6. General syntax for creating a view: CREATEVIEW [View_Name] AS [SELECT Statement] As for example : CREATEVIEW SampleView As SELECT EmpID, EmpName FROM EmpInfo
  • 7.  This is as similar as select statement of a table. SELECT * FROM SampleView
  • 8.  General syntax: DROPVIEW viewname;  Example: DROPVIEW SampleView;
  • 9.  When a view is dropped, it has no effect on the underlying tables.  Dropping a view removes its definition and all the permissions assigned to it.   However, dropping a table that references a view does not drop the view automatically.  You must drop it explicitly.
  • 10.  General syntax: ALTERVIEW viewname AS SELECT…;  Example: ALTERVIEW SampleView AS SELECT * FROM EmpInfo;
  • 11. The value for the column is provided automatically if:  The column has an IDENTITY property.  The column has a default value specified.  The column has a timestamp data type.  The column takes null values.  The column is a computed column.
  • 12.  The value of a column with an IDENTITY property cannot be updated.  Records cannot be updated if the base table contains aTIMESTAMP column.  While updating a row, if a constraint or rule is violated, the statement is terminated, an error is returned, and no records are updated.  When there is a self-join with the same view or base table, the UPDATE statement does not work.
  • 13.  There are 3 methods to see the view definition:  Method 1: Sp_helptext viewname;  Method 2: select definition from sys.sql_modules where object_id=object_id(‘viewname');  Method 3: select object_definition(object_id('vv'));
  • 14.  The sys.sql_modules is a system view. It is used to display view definition.  Object_definition() is built-in function that returns the view definition.  Object_id() is a system function that returns the ID of view.
  • 16.  There are two types of views in the sql server 2005.  Normal or Standard view  Partitioned view
  • 17.  This view is most frequently used by the developers.  When we create the view the schema will be stored as object in the database.  When we retrieve the content from this virtual table, it will execute the schema and the stored data from the parent table.  These include focusing on specific data and simplifying data manipulation.
  • 18.  CREATEVIEW vw_empinfo AS SELECT * FROM EmpInfo;  SELECT * FROM vw_empinfo;  INSERT INTO vw_empinfo VALUES(4,’abcd’,’.NET’,565652);  DELETE FROM vw_empinfo WHERE EmpID = 1; Here you can do the DML operations in the view when you have only one table.
  • 19.  The partitioned view and its execution is like normal view.  It will work across the database and across the server.  There are two types of Partitioned views.  Local PartitionedView  Global PartitionedView
  • 20.  The local partitioned view can be created within same server but different database.  The view schema definition will be stored in the executed database.
  • 21.  USE Database1 CREATETABLE EmployeeList ( iEmployeeID INT IDENTITY(1,1), vFirstNameVARCHAR(25) NOT NULL, vLastNameVARCHAR(25) NOT NULL, iDeptID INT )  USE Database2 CREATETABLE Department ( iDeptID INT IDENTITY(1,1) PRIMARY KEY, vDeptNameVARCHAR(50), )
  • 22. CREATEVIEW vw_LocalPartion_View AS SELECT E.iEmployeeID, D.vDeptName FROM EmployeeList E INNER JOIN Database2.dbo.Department D ON D.iDeptID = E.iDeptID ;
  • 23.  The global Partitioned view will work across the server.  The view can be created to join the table across the server.  The accessing format will be like this. [Server Name]. Database Name.Table Name  When we execute the view if it is not linked with the current server then it will ask us to link the external server.
  • 24.  The following system stored procedure will be used to link the server. sp_addlinkedserver 'Server name'  The following system catalog table is used to see the list of linked servers. SELECT * FROM SYS.SERVERS
  • 25.  There are two different option for creating a view.  Schema Binding Option  Encryption
  • 26.  If we Creates a view with the SCHEMABINDING option it will locks the tables being referred by the view and restrict any kinds of changes that may change the table schema ( No Alter Command) .  While creating schema binding view, we can't mention "Select * from tablename" with the query.  We have to mention all the column name for reference
  • 27. CREATEVIEW DemoSampleView With SCHEMABINDING As SELECT EmpID, EmpName, FROM DBO.EmpInfo;  While specifying the Database name we have use Dbo.[DbName] .  This will prevent any of the underlying tables from being altered without the view being dropped.
  • 29.  This option encrypts the definition.  This option encrypts the definition of the view.  Users will not be able to see the definition of theView after it is created.  This is the main adavatages of view where we can make it secure.  Note: Once view is encrypted, there is no way to decrypt it again. CREATEVIEW DemoView With ENCRYPTION Select ename,edesig from dbo.EmpInfo