Search This Blog

Wednesday, July 10, 2019

View in sql

view is a virtual table based on the result-set of an SQL statement

CREATE VIEW

CREATE VIEW view_name AS
SELECT column1column2, ...
FROM table_name
WHERE condition;

 CREATE TABLE dbo.Employee
 (
        Id   INT IDENTITY NOT NULL,
        [Age]  INT NOT NULL ,
        Name VARCHAR (50)
 )
---------------Create View-------------------
 CREATE VIEW view_Employee
 as 
 select age,Name from Employee
----------------------------------------------
   UPDATE view_Employee   SET AGE = 35   WHERE name = 'Monu';
   insert into view_Employee values(13,'sou')

   delete from view_Employee where age=13
-----------------------------------------------


WITH CHECK OPTION

The purpose of the WITH CHECK OPTION is to ensure that all UPDATE and INSERTs satisfy the condition(s) in the view definition.




Updating a View

A view can be updated under certain conditions which are given below −
  • The SELECT clause may not contain the keyword DISTINCT.
  • The SELECT clause may not contain summary functions.
  • The SELECT clause may not contain set functions.
  • The SELECT clause may not contain set operators.
  • The SELECT clause may not contain an ORDER BY clause.
  • The FROM clause may not contain multiple tables.
  • The WHERE clause may not contain subqueries.
  • The query may not contain GROUP BY or HAVING.
  • Calculated columns may not be updated.
  • All NOT NULL columns from the base table must be included in the view in order for the INSERT query to function.

No comments :