Presentation Description

No description available.


Presentation Transcript

What is Synonyms ?:

What is Synonyms ? A synonym is an alternate name for a schema scoped object. Synonyms allow client applications to use the single-part name of a synonym to reference a base object instead of a using a two-, three-, or four-part name to reference the base object. New DDL Statements New statements Description CREATE SYNONYM Creates a new synonym. DROP SYNONYM Deletes an existing synonym.

Creating Synonyms:

Creating Oracle Synonyms A synonym is named, and points to a specific object. For example, in the ROBERT schema we can create a private synonym for SCOTT.EMP using the create synonym command: SQL> CREATE SYNONYM emp FOR SCOTT.EMP; Now, when we issue the query with just the EMP (removing the SCOTT.)  We will see the data from the SCOTT.EMP table because Oracle will follow the synonym to the correct place as seen here: Creating Synonyms


NOTE Note that we said that this was a private synonym. That means that only the ROBERT user can use the synonym. We can also create public synonyms using the create public synonym command as seen here: SQL> CREATE PUBLIC SYNONYM emp FOR SCOTT.EMP;

Slide 4:

Generally good DBA’s try to avoid public synonyms. They do make management of the database a bit easier, but they also have security and performance issues associated with them. Hence, try not to use public synonyms unless you have to. You can have a public and private synonym of the same name. In fact, you can have a public and private synonym called EMP in the SCOTT schema and have a table called EMP in the same schema. In cases where you have multiple synonyms and/or a table present, it can get confusing which object you are using (this is another reason we hate public synonyms). There is an order of precedence with regards to the use of synonyms and local objects. This is: 1. Local objects will always be accessed first. 2. If a local object does not exist, the object with a private synonym will be accessed. 3. If a private synonym does not exist or the object does not exist, then the public synonym will be used.


NOTE Note that a synonym can be created for an object that does not exist, and an object with an associated synonym can be dropped without removing the synonym. This can cause all sorts of interesting problems for DBA’s, so be careful.

Removing Synonyms:

Removing Synonyms Removing Synonyms The drop synonym command is used to drop public and private synonyms. Here is an example of dropping a private synonym and a public synonym with the drop synonym command: SQL> -- Drop public synony SQL> DROP PUBLIC SYNONYM emp; SQL> -- Drop private synonym SQL> DROP SYNONYM emp;

authorStream Live Help