Differences between views and synonyms in Oracle

Source: Internet
Author: User
Tags one table

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

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.