Oracle: difference between a view and a synonym
What a view and a synonym are in Oracle, and when to use each.
A view and a synonym both give access to Oracle data under a name other than the original table, but they serve different purposes.
View
A view is a virtual table.
- It can be created on a table or on another view.
- It acts as a window through which the base table data can be read, and sometimes changed.
- It holds no data of its own: the data always comes from the base table.
- It is stored as a query in the data dictionary; each time the view is queried, that query runs against the base table.
Main advantages of views:
- restrict access to a predetermined set of rows and columns of a table;
- hide the complexity of a query;
- hide the complexity of a calculation.
Synonym
A synonym is an alternate name given to a table, view, sequence or program unit.
- It is used to mask the real name and owner of the object.
- Public synonyms can be created to give public access to tables.