Tuesday, August 18, 2009

SQL View Statement

In SQL, a VIEW is a virtual table based on the result-set of a SELECT statement.
A view contains rows and columns, just like a real table.
The fields in a view are fields from one or more real tables in the database.
You can add SQL functions, WHERE, and JOIN statements to a view and present the data as if the data were coming from a single table.
Note: The database design and structure will NOT be affected by the functions, where, or join statements in a view.
Syntax
CREATE VIEW view_name AS SELECT column_name(s) FROM table_name WHERE condition
Note: The database does not store the view data! The database engine recreates the data, using the view's SELECT statement, every time a user queries a view.
CREATE VIEW tbl3View AS SELECT sno,m1,m2 FROM tbl3 WHERE m1>10;/*Error Incorrect syntax near ';' i don't know why?*/
CREATE VIEW tbl3View AS SELECT sno,m1,m2 FROM tbl3 WHERE m1>10
select * from tbl3View;
drop view tbl3View;

No comments:

Post a Comment