
What is a view?
"A view is a database object that allows you to create a customized slide of a table or a collection of tables. A view is just a SQL query that is stored in the database. The results of that query are returned in the form a table." [1] "A view can be created by selecting columns from a larger table, or a view can be written to restrict the number of rows or type of data returned from a select. You can define a view that joins several tables together." [2] A view extracts its data from one or more underlying actual tables. The underlying tables are known as base tables. Views can be based on tables or other views.
Any changes you make to the base tables of a view directly change the view. If you delete a table that a view is based on, then the view is invalid. The view is valid only if the base tables on which the view is built exist.
In order to create a view:
There are 2 ways to create a view: through SQL*Plus or the Navigator
SQL*Plus
An example of creating a view using SQL*Plus:
To create a join view, which is a view made up from more than one table:
select * from assign_view;
To drop a view:
The Navigator
An example of creating a view using the Navigator:
What is an index?
An index is built of columns in a table that are queried often. An index is used to speed up access to rows within a table. "Without an index, each time you wanted to retrieve information, Oracle would have to perform a full table scan of the data and look at each and every row in each table of interest. If you have a commonly used query that just retrieves two columns of a table containing a large volume of information, you can create an index on those two columns. Oracle will look in the index for the information you want instead of walking through every complete row in the table." [2]
To create a simple index:
create index bdate on player (begin_date);
The following command:
select name from player
where begin_date > ‘15-JAN-98’;
Would cause the system to search the index bdate to find players who started the team after January 15, 1998. In tables that consist of many columns and thousands of rows, using indexes will on average speed up access time.
To drop an index:
drop index index_name;
What is a synonym?
"Synonyms are often referred to as nicknames or shortcuts or alternatives for the syntax object_owner.object_name." Synonyms can be created for tables, views, procedures, packages, or sequences. [2]
Why are synonyms used?
Synonyms are most frequently used for security. By using synonyms, you can hide the location of the object and the object owner. For example, in the Soccer database, the table PLAYER is owned by the schema SAM. Each time you refer to the PLAYER table, you have to use the syntax SAM.PLAYER so it will be clear exactly which table you are referencing. But if you create a synonym for the PLAYER table, called PLAY, you can reference the table by the synonym name, without using the owner of the table (SAM).
Synonyms also can be used to simplify SQL statements. For example, if you have a table name that is very long, you can shorten it by using a synonym and reference the synonym in the SQL statement.
There are two types of synonyms: public and private.
Public Synonyms
Public synonyms are owned by the PUBLIC user. Therefore, public synonyms are accessible to all users within the database. You must have CREATE PUBLIC SYNONYM privilege to create a public synonym.
Private Synonyms
Private synonyms are "stored in the user’s schema who creates the private synonym." [3] You must have the CREATE SYNONYM privilege to create a private synonym. You must have the CREATE ANY SYNONYM privilege to create a private synonym in another user’s schema.
Example of creating a private synonym:
The Soccer database is created by user SAM. All tables are stored in the SAM schema. Suppose user SALLY needs access to the EQUIP table in the SAM schema.
SQL>select * from eq;
| EQUIPMENT_ID | EQIUPMENT_NAME | NO_IN_STOCK |
| 1001 | Ball | 25 |
| 1002 | Jersey | 20 |
| 1003 | ShinGuard | 25 |
| 1004 | Cone | 25 |
Suppose other users need access to the EQUIP table. You cannot expect each user to create his/her own synonym. This is when you, the DBA, could create a public synonym, which would make the EQUIP table accessible to everyone. However, each user would "still need to be granted access to the table for any data to be seen." [3] It is best for a dba user, such as SYSTEM, to create a public synonym.
Example of creating a public synonym:
| EQUIPMENT_ID | EQIUPMENT_NAME | NO_IN_STOCK |
| 1001 | Ball | 25 |
| 1002 | Jersey | 20 |
| 1003 | ShinGuard | 25 |
| 1004 | Cone | 25 |
Now TOM can see the data in the EQUIP table. By using synonyms, TOM does not know who owns the EQUIP table or where the table is stored in the database.
Dropping a private synonym
An example:
"Notice that you do not have to specify that this is a private synonym if you use DROP SYNONYM. Oracle automatically knows this is a private synonym." [3]
Dropping a public synonym
An example:
"Notice that the word PUBLIC is specified. If not, Oracle would try to drop a private synonym by the same name." [3]
Back to Top