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
VIEWS SQL Reviewed by Rupesh on 19:08 Rating: 5

No comments:

All Rights Reserved by Technology from Developers Eye © 2014 - 2015
Powered By Blogger, Designed by Aadics
Disclaimers:: The information provided within this blogsite is for general informational purposes only. While we try to keep the information up-to-date and correct, there are no representations or warranties, express or implied, about the completeness, accuracy, reliability, suitability or availability with respect to the information, products, services, or related graphics contained in this blogsite for any purpose.The author does not assume and hereby disclaims any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from accident, negligence, or any other cause.

Contact Form

Name

Email *

Message *

Powered by Blogger.