More Database Objects
More Database Objects
SQL*PLUS has a facility to automatically commit all the work, without explicitly issuing the
commit command i.e. SET AUTOCOMMIT ON -- Enables autocommit feature.
SET AUTOCOMMIT OFF -- Is the default and disables the automatic committing
Note: Certain actions automatically force a commit. DDL Commands CREATE, DROP,
ALTER and DCL commands EXIT, GRANT, REVOKE, CONNECT, DISCONNECT, AUDIT and
NOAUDIT are example for this. (i.e. the work done by these commands can not be taken
back by ROLLBACK command).
SAVEPOINT: This statement is used to mark a point in the transaction to which you can
later ROLLBACK. (i.e. Undo the changes made to the database till that point)
Following screen shots explain the usage of SAVEPOINT and ROLLBACK commands
RENAME COMMAND: This Command is used to change the name of a table.
LOCK TABLE : The LOCK TABLE command is used to prevent concurrent processes from
changing a table or from using it.
The two Locking modes are
1)IN SHARE MODE: In which concurrent processes are allowed to perform only read-only
operations.
2)IN EXCLUSIVE MODE:Prevents concurrent processes from performing any operation the
table.
Only the Owner of the table, DBA, or a user having ALTER, DELETE, INSERT, SELECT,
UPDATE can lock a table. A table can have multiple SHARE LOCKS but only one EXCLUSIVE
LOCK
If we try to obtain a lock using the first statement then Oracle waits if the table is not
available for locking. In second statement it returns immediately.
SQL> LOCK TABLE STUD in SHARE MODE; --- to obtain shared mode lock
MAXVALUE 99999;
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:
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
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.
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
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> GRANT ALL ON ORDERS TO U2; --- To give SELECT, UPDATE, INSERT and DELETE
privileges in a single command
Above command authorizes U2 to transfer the same privilege to others on behalf of U1.