Create Oracle synonyms and their functions

Source: Internet
Author: User

The Oracle synonym (synonyms) is literally an alias. Similar to the attempted function, it is a ing relationship. This topic describes how to create a synonym statement, delete a synonym, and view a synonym statement.
Summary of oracle Synonyms:
The meaning of an alias is literally the same as that of an attempt. Is a ing relationship.
1. Create a synonym statement:

Create public synonym table_name for user. table_name;

The first user_table and the second user_table can be different.
In addition, to create a synonym for a table on a remote Database, you must first create a Database Link (Database connection) to expand the access, and then create a Database synonym using the following statement: create synonym table_name for table_name @ DB_Link;
Of course, you may need to authorize the current user (user2) in the user: grant select/delete/update on user2
2. Delete Synonyms:

Drop public synonym table_name;

3. view all synonyms:

Select * from dba_synonyms

Synonyms have the following benefits: they save a lot of database space and have little difference in operating the same table for different users; they extend the scope of use of databases, allows seamless interaction between different database users. synonyms can be created on different database servers and connected over the network.
Oracle Database provides the synonym management function. Oracle synonyms are aliases of database solution objects. They are often used to simplify object access and improve object access security.

In Oracle, users are managed by permissions. That is to say, if we want to use a database, we must have permissions, but if someone else grants us the permissions, we can also perform operations on the database, but we must enter the name of the table owner before the name of the authorized table, so this is troublesome, what should we do? Create an Oracle synonym! In this way, you can directly Use synonyms to use tables.
1. Definition of synonyms
Oracle Database provides the synonym management function. Synonyms are aliases of database solution objects. They are often used to simplify object access and improve object access security. When a synonym is used, the Oracle database translates it into the name of the corresponding solution object. Similar to a view, synonyms do not occupy the actual storage space. Only the definition of synonyms is saved in the data dictionary. Most database objects in Oracle databases, such as tables, views, synonyms, sequences, stored procedures, packages, etc. Database administrators can define synonyms for them based on actual conditions.
2. Oracle synonym Classification
There are two types of Oracle Synonyms: Public Oracle synonyms and private Oracle synonyms.
1) Public Oracle synonym: it is owned by a special user group Public. As the name suggests, all users in the database can use public synonyms. Common synonyms are often used to mark common database objects, which must be referenced by everyone.
2) Private Oracle synonym: it corresponds to a public synonym, which is owned by the user who created it. Of course, the creator of this synonym can control whether other Users have the right to use their own private synonyms through authorization.
3. Create and delete Oracle Synonyms
Syntax for creating public Oracle Synonyms: Create [public] synonym name for [username.] objectName;
Drop [public] synonym name
4. Role of Oracle Synonyms
1) in multi-user collaborative development, the object name and its owner can be blocked. If no synonym exists, the user name must be used to operate tables of other users. the object name format uses Oracle synonyms to hide the user name. Of course, note that the public synonym only defines a public alias for the database object, whether other users can access this database object through this alias depends on whether the user has been authorized.
2) Simplify SQL statements for users. The preceding statement is a simplified SQL statement. If the name of a self-created table is long, you can create an Oracle synonym for the table to simplify SQL development.
3) provides location transparency for remote objects in distributed databases.
5. Role of Oracle synonyms in the database chain
A database chain is a named object that describes the path from a database to another database, through which communication between different databases can be achieved.
Create database link database chain name connect to user name identified by password using 'oracle connection string'; the access object must use the object name @ database chain name. The role of synonyms in the database chain is to provide location transparency.

Author "snowdymy"

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: 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.