Codechef4u is a community for computer professionals,by computer professionals,just like you; who loves sharing and helping each others,Join them
Share your post

SQL Views

View is a virtual table based on the result-set of an SQL statement and that is Stored in the database with some name.

Syntax:

CREATE VIEW SomeViewName AS
SELECT Some_columnName(s)
FROM tableName
WHERE condition


Example:

Create View:

CREATE VIEW StudentProducts AS
 
SELECT  * FROM Products WHERE CategoryId in (Select CategoryID from Categories where CategoryName='Books')
 
GO  

Update View:

MS-SQL supported

ALTER VIEW StudentProducts AS
 
SELECT  * FROM Products WHERE CategoryId in (Select CategoryID from Categories where CategoryName in ('Books','Mobile'))
 
GO

 

Oracle supported:

CREATE OR REPLACE VIEW StudentProducts AS
 
SELECT  * FROM Products WHERE CategoryId in (Select CategoryID from Categories where CategoryName in ('Books','Mobile'))
 
GO


DROP view:

DROP View StudentProducts 

Invalid entry,please enter valid data.

Loading