Differences between sight maps and synonyms in Oracle

Source: Internet
Author: User

Both views and synonyms are the object names in the database. They do not correspond to actual data storage and all depend on the existence of other objects.
View: A view can be viewed as a virtual table or storage query. Unless it is an index view, the data in the view will not be stored in the database as non-duplicate objects. Generally, a view is built based on one or more data tables that are queried by a data query statement. A view can be used in a data query statement.

Synonym: It is another name of an object within the framework. By using synonyms, client applications can reference a base object by using a name consisting of two, three, or four parts. It can be understood as a shortcut to an object in a database or an alias in a specific range; not limited to data tables, almost all database objects can be used to create synonyms.
1. A view can correspond to one or more tables. A synonym can only correspond to one table name.

2. Other constraints can be set for the view.

3. You can create a view on Synonyms:
For example, if a synonym named synonym_city and a table named table_citys already exist, you can CREATE a VIEW: create or replace noforce view view_city as select * FROM synonym_city, table_citys;


4. You can perform any DML operation on synonyms to insert, update, and delete table data. You can only update and delete views.

It is worth noting that both views and synonyms can block users from accessing tables owned by other users.
For example, there are two users: scott and sys. Log On As sys.
Create a synonym for a cross-User table:
Create or replace public synonym SYN_EMP for scott. emp;
Create a view for a table across users:
Create or replace view view_EMP as select * FROM scott. emp

Then perform the query operation:
SELECT * FROM SYN_EMP;
SELECT * FROM view_EMP;

The query results are the same.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.