Views and synonyms are the names of objects in the database, each of which does not correspond to the actual data store , and is dependent on the existence of other objects.
Views: Views can be viewed as virtual tables or stored queries. Unless it is an indexed view, the view's data is not stored as a non-repeating object in the database. It is generally based on one or more data tables constructed from a data query statement; The view can be used again in a data query statement.
Synonym: is another name for an object within the scope of the schema. By using synonyms, a client application can reference a base object by using a partial name, rather than using a two-part, three-part, or four-part name. Can be understood as a shortcut to an object in a database or an alias within a particular range, and not limited to a data table , where almost all database objects can have synonyms.
1. Views can correspond to one or more tables, synonyms can only correspond to one table name
2. View can set additional constraints
3. You can create a view on synonyms:
For example, there already exists a synonym named Synonym_city and a table named Table_citys, which can create a view: Create OR REPLACE noforce View view_city as SELECT * from Synonym_ City,table_citys;
4. The table data can be inserted, updated, deleted, and only updated and deleted through the view by any DML operation on the synonym.
It is worth noting that both views and synonyms can block users from accessing tables owned by other users.
For example: There are now two users: Scott, sys, logged in with the SYS user
Create synonyms for cross-user tables:
CREATE OR REPLACE public synonym syn_emp for scott.emp;
To create a view of a table across users:
CREATE OR REPLACE VIEW view_emp as SELECT * from Scott.emp
Then proceed with the query operation:
SELECT * from Syn_emp;
SELECT * from View_emp;
The query results are the same.
Reprint: http://www.educity.cn/shujuku/1599690.html
Differences between views and synonyms in Oracle