Exforsys.com
 
Home Tutorials Oracle 9i
 

Tutorial 7: More Database Objects

 

Tutorial 7: More Database Objects - Page 2

Page 2 of 2



SYNONYM: A synonym is an alternative name given to the table, sequence etc in oracle. There are two types public Synonym and Private Synonym.


1) Public Synonym: A public synonym is accessible to all the users.


Example:


SQL> SELECT * FROM DICT;


DICT is a public Synonym for table DICTIONARY. To create a public synonym we need to login as user SYSTEM (i.e. DBA) and then type the following


SQL> CREATE SYNONYM EMPLOYEE FOR SCOTT.EMP;
In the above statement you have created synonym EMPLOYEE for EMP. Now you need to grant permissions to all the users over this synonym. The synonym for can be used to perform all DML operations (SELECT, UPDATE, INSERT and DELETE) over the table. We cannot ALTER the table using its SYNONYM.


2) Private Synonym: To create a private synonym we write.


SQL> CREATE SYNONYM EMPLOYEE FOR EMP;
SQL> DROP SYNONYM EMPLOYEE; -------- Will remove the Synonym.


INDEX: Indexes will make data access faster. This index tells where a certain row in the table is stored. It is more like an index in the book. When we create an index on a column it is stored separately in the database. A query on any table initially searches for an Index on that table.


SQL> CREATE INDEX EMP_IDX ON EMP(EMPNO);

SQL> DROP INDEX EMP_IDX;


Creating new user account : To create a new user account one need to logon to the database as a DBA as shown above. Then execute syntax similar to the one shown below.



In the above example we have created 2 user accounts by names U1 and U2. Let us say U1 owns a table by name ORDERS which U2 want to use. This is possible only when U1 has given permission to U2. Privileges can be given using GRANT and taken back by using REVOKE command


Below given screen shots explain these commands.




As U2 when we tried to access data from ORDERS of U1 we failed, as there were no sufficient privileges. Later we could access because U1 granted permission to do so.


To take back the privileges we write


SQL> REVOKE SELECT ON ORDERS FROM U2; ---- For doing this You have to login as U1.


SQL> GRANT SELECT, UPDATE ON ORDERS TO U2;



SQL> REVOKE SELECT, UPDATE ON ORDERS FROM U2;


SQL> GRANT ALL ON ORDERS TO U2; --- To give SELECT, UPDATE, INSERT and DELETE privileges in a single command


SQL> REVOKE ALL ON ORDERS FROM U2;


SQL> GRANT SELECT ON ORDERS TO U2 WITH GRANT OPTION;


Above command authorizes U2 to transfer the same privilege to others on behalf of U1.






First Page: Tutorial 7: More Database Objects


Read Next: Tutorial 8: Building PL/SQL Blocks



 

 

Comments


Khaled said:

  I like your website
June 10, 2006, 5:50 pm

Khaled said:

  But its a little complicated.
June 10, 2006, 5:55 pm

pallavikanala said:

  Excellent work. Keep it up
June 16, 2006, 9:15 pm

Imtiaz Ali said:

  Easy to understand
May 11, 2007, 9:46 pm

rubash said:

  This is the way an tutorial is supposed interspersed with right examples to get a better clarity on the subject matter.

Good work team.
May 18, 2007, 8:02 am

sumanvollala said:

  Thanks for the people who gave all these screen shots,hope we will expect more from you
June 4, 2007, 4:41 pm

Hareesh said:

  Excellent site.Thanks a lot
October 12, 2007, 4:23 am

phatan said:

  Excellent examples. Thanks to Site provoders and God
December 27, 2007, 8:14 am

Jeni said:

  It helps me a lot in excelling it with basic concepts and brilliant examples.
April 1, 2008, 4:31 am

SP.Murugesa Pandian said:

  This is the only way of teaching the oracle to fresher.I hope i could learn more from this site.
June 18, 2008, 7:59 am

Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links

 

Subscribe via RSS


Get Daily Updates via Subscribe to Exforsys Free Training via email


Get Latest Free Training Updates delivered directly to your Inbox...

Enter your email address:


 

Subscribe to Exforsys Free Training via RSS
 

 
Partners -  Privacy and Legal Policy -  Site News -  Contact   Sitemap  

Copyright © 2000 - 2009 exforsys.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape