VIEWS SQL
---VIEWS--
---Database objects which are used to represent an SQL Query that can be used to fetch data from a single or multiple tables.
----Views are also known as virtual tables and always depend upon the base tables for their working.
---Views are used for 2 reasons.
---1)Simplify the querying process. Views represent the SQL Query and we don't have to write the query again and again.views do not have space allocated to them.
--2)Views also implement data security.
--example:-There may be a table with no select permissions on any of the columns.But a View can be created to allow the user to view selective data from a particular set of columns.
----Types of Views--
---1)Simple Views.
---2)Partitioned Views.
---3)Indexed Views.
--select * from salesdetails
create view vw as select * from salesdetails where sno=100
select * from vw
select * from salesdetails
insert vw values(656,800,'ffg')
alter view vw as select * from salesdetails where sno=100 with
check option
sp_helptext vw
drop view vw
---Partition Views
--They can be created on tables from same server or different server .
create view vws as
select sno,salary from salesdetails
union all
select * from salesunion
select * from vws
--Read only views
--We can only view the data.Insert,delete,update cannot be executed on these views.
--examples:-
--Aggregate function queries, distinct operator , union.
create view vwd as select count(*) as "count" from salesdetails
select * from vwd
--Error
insert vwd values(67)
delete from vwd where count=6
create view vwf as select distinct(salary) from salesdetails
delete from vwf
sp_helptext vwf
---Database objects which are used to represent an SQL Query that can be used to fetch data from a single or multiple tables.
----Views are also known as virtual tables and always depend upon the base tables for their working.
---Views are used for 2 reasons.
---1)Simplify the querying process. Views represent the SQL Query and we don't have to write the query again and again.views do not have space allocated to them.
--2)Views also implement data security.
--example:-There may be a table with no select permissions on any of the columns.But a View can be created to allow the user to view selective data from a particular set of columns.
----Types of Views--
---1)Simple Views.
---2)Partitioned Views.
---3)Indexed Views.
--select * from salesdetails
create view vw as select * from salesdetails where sno=100
select * from vw
select * from salesdetails
insert vw values(656,800,'ffg')
alter view vw as select * from salesdetails where sno=100 with
check option
sp_helptext vw
drop view vw
---Partition Views
--They can be created on tables from same server or different server .
create view vws as
select sno,salary from salesdetails
union all
select * from salesunion
select * from vws
--Read only views
--We can only view the data.Insert,delete,update cannot be executed on these views.
--examples:-
--Aggregate function queries, distinct operator , union.
create view vwd as select count(*) as "count" from salesdetails
select * from vwd
--Error
insert vwd values(67)
delete from vwd where count=6
create view vwf as select distinct(salary) from salesdetails
delete from vwf
sp_helptext vwf
VIEWS SQL
Reviewed by Rupesh
on
19:08
Rating:
No comments: