home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
sql
/
view.shr
< prev
Wrap
Text File
|
1988-03-05
|
3KB
|
121 lines
CREATE A VIEW
A view is an alternate view of the data. It allows you to
create a temporary table based on a select statement. It is a
good method of saving a complex select statement that will be
used again.
SYNTAX
create view file_name as
select_statement
EXAMPLE:
create view prodmanu as
select prod.code, desc, mst, defects
from prod, manu
where prod.code = manu.code;
select *
from prodmanu;
code desc mst defects
---- -------------- --- -------
AB Megawamp WA 3
AB Megawamp ID 5
AC Gigasnarf AZ 0
DZ Electrowidgit AZ
EA Nanomouse AZ 12
EC RGBMouse ID 2
6 rows selected
This table does not exist on the disk as a permanent file. It
is just a composition of two files on the disk. Every time you
query the database using prodmanu, the data is taken from the
prod table and the manu table. Because of this, views are
always up-to-date.
RULES FOR USING VIEWS
1. Can only be used in a select statement, NOT an insert,
update, or delete statement.
2. Cannot be used in a subquery.
3. Can contain any select statement except one that has
the following statements: into, order, and group.
However, the above can be added when you query the view as
in:
select *
from prodmanu
where defects > 3
order by mst;
VIEW-1
The advantage of views is that you can do all the queries that
you find in the section on the select statement without the
problem that comes from data that is not normalized. For a
discussion on the advantages of data normalization, refer to the
full documentation. Basically, an actual table with the
contents of what we get from the view would create some major
insert, update, and delete problems.
Since the table has to be created every time a view is accessed,
using views tends to slow processing significantly.
VIEW-2