Skip to main content

Importance of Synonym in Oracle Database #Diksha Oracle Training Centre

Importance of Synonym in Oracle Database. 


Hello Everyone,

Today I will discuss about Synonym in Oracle as Synonym play important role in database to hide information of object. Before Starting this blog please go through my previous blogs of SQL in my archive folder. Let’s Discuss about Synonym. Synonym in database is an object which is basically used as alternative name for objects such as tables, views, sequences, stored procedures, and other database objects. We generally use synonyms for granting access to an object from another schema and you don't want the users from which Schema it’s own the object.

In Another word we can say synonym is an alias for any table, view, snapshot, sequence, procedure, function, or package. Because a synonym is simply an alias, it requires no storage other than its definition in the data dictionary.

Synonyms are basically used for security purpose and convenience.

For example, Synonym can do the following:

·        Hide  the name and owner of an object.

·        Provide location transparency for remote objects of a distributed database.

·        Simple use of SQL statements for database users.

There are two types of Synonym:

·        Public Synonym

·        Private Synonym

 We can create both public and private synonyms.

Note : We need CREATE PUBLIC SYNONYMPermission to create public synonyms

Syntax for creating Synonym :

CREATE [OR REPLACE] [PUBLIC] SYNONYM [schema .] synonym_name

  FOR [schema .] object_name [@ dblink];

Public synonym is global and owned by the special user group named PUBLIC and every user in a database can access it whereas a private synonym is in the schema of a specific user who has control over its availability to others by using Grant and Revoke.

 Syntax and example for Creating Public and Private Synonym:

 Public Synonym :

CREATE PUBLIC SYNONYM emp1

FOR dotc.employee;

This first CREATE SYNONYM example demonstrates how to create a synonym called emp. Now, users of other schemas can reference the table called employee without having to prefix the table name with the schema named dotc. Below is the example:

SELECT *

FROM emp1;

If we need to make any changes in Synonym as per requirement for the same name we can use Replace keyword.

CREATE OR REPLACE PUBLIC SYNONYM emp1

FOR dotc.employee;

Note : Once we define a synonym for an object, you can reference it in the SQL statements such as the SELECT, INSERT, UPDATE, and DELETE statement.

Below is the output of synonym emp1



 

 Private Synonym:

 

In Private we just omit the Public keyword, A private Synonym must be unique on its schema.

Syntax :

CREATE  SYNONYM emp

FOR dotc.employee;

Private Synonym has limitation to its own schema only, but we can give grant access to other user if required like select etc.

Synonyms are very useful in both distributed and non distributed database environments because they hide the identity of the objects, including its location in a distributed system. This is advantageous because if the underlying object must be renamed or moved, then only the synonym needs to be redefined. Applications based on the synonym continue to work without any modification. Synonym also simplify SQL statement for user in a distributed database system.

 One Basic Example:

A table employee is in the schema owned by the user DOTC. The SELECT privilege for the employee table is granted to PUBLIC. At this point, you have to query the table employee with a SQL statement  similar to the below query:

SELECT * FROM dotc.employee;

Here we must include both the schema that contains the table along with the table name to perform the query.

Suppose that the database administrator (DBA) creates a public synonym with the following SQL statement:

CREATE PUBLIC SYNONYM emp FOR dotc.employee;

After the public synonym is created, you can query the table employee with a simple SQL statement:

SELECT * FROM emp;

Note : Here  the public synonym emp hides the name of the table employee and the name of the schema that is dotc which contains the table employee.

So we are now able to understand the usage of Synonym in Database and  it’s importance . Synonymy used to hide table name as well as schema and we can simply query the synonym for data also it’s used for security purpose as it’s hide the information from the user.

Please go through this blog carefully  as Interviewer can ask frequent questions on Synonym to check it’s advantages in database. Please let me know if you have any doubts.

Thanks

Comments

Post a Comment

Popular posts from this blog

SQL and Classification of SQL in Oracle Database #Diksha Oracle Training Centre

  SQL and Classification of SQL in Oracle Database.   SQL is Structured Query Language , which is used for storing, manipulating and retrieving data stored in a relational database .SQL is the standard language for RDBMS. All the Relational Database Management Systems (RDMS) like Oracle, MySQL, Sybase, Informix, IBM DB2 and Microsoft SQL Server use SQL as their standard database language. Oracle is one of the more secured database as compared to other databases. Importance of   SQL : SQL and PL/SQL is a backend process where all data is stored and retrieved in GUI which created either by any programming languages like Java, C++, PHP etc. so we need to have very secure database so that there will be no impact for users. SQL allows users to access data in the relational database management systems. SQL is used to communicate with a database.SQL and PL/SQL allows users to create and drop databases tables , views , stored procedures , functions , packages , trigger et...

Basic SQL Commands in Oracle Database #Diksha Oracle Training Centre

  Basic SQL Commands in Oracle Database.   Hello Everyone, In my previous blog I discussed about SQL and Classification of SQL . Today I will discuss about SQL basic commands which widely used in RDBMS. The Topics of SQL command which I am going to cover in this blog are mainly divided into four Categories: ·         DDL:   DDL consists of commands which are used to define and design the database. ·         DML:   DML consists of commands which are mainly used to manipulate the data in the database. ·        DCL: DCL Consists of commands which deal with the user permissions/access and controls in the database. ·       TCL:   TCL Consist of commands which deal with the transaction in the database. If you want to explore theory part please follow my below blog as in today blog I will discuss about how to use the commands. h...

PL/SQL in Oracle and basic Programs in PL/SQL #Diksha Oracle Training Centre

              PL/SQL in Oracle with basic Programs. Hello Everyone, Today I will discuss about PL/SQL in Oracle .In Previous Blog we discussed about cursor and anonymous block used in cursor as well as uses of %TYPE and %ROWTYPE attribute. Before starting this topic please go through my below blog. https://dikshaoracletraining.blogspot.com/2020/10/cursor-and-types-of-cursor-in-oracle.html https://dikshaoracletraining.blogspot.com/2020/11/benefits-of-type-and-rowtype-in-oracle.html PL/SQL is basically a Procedural Language in SQL and in PL/SQL we use separate two parts first is Anonymous Block and second is Named Block. The PL/SQL programming language was developed by Oracle Corporation in the late 1980s as procedural extension language for SQL relational database. PL/SQL high-performance transaction-processing language.PL/SQL is completely portable.   PL/SQL provides a built-in, interpreted and OS independent programming environment. ...