4) INDEX : USED TO IMPROVE PERFORMANCE OF THE QUERIES. 5) SYNONYM : ANOTHER NAME TO AN OBJECTS. -----------------------------------------------------------------------------------THERE ARE FEW NAMING RULES FOR DATABSE OBJECTS Must begin with a letter Must be 1 30 characters long Must contain only A Z, a z, 0 9, _, $, and # Must not duplicate the name of another object owned by the same user Must not be an Oracle server reserved word Note: Names are case-insensitive. For example, EMPLOYEES is treated as the same name as eMPloyees or eMpLOYEES. VIEWS ============ A view contains no data of its own the data which we see is of its base table. T he tables on which a view is based are called base tables. The view is stored as a SELECT sta tement in the data dictionary.We can use view to change data of an actual table. Advantages of Views Views restrict access to the data because the view can display selected columns from the table. Views can be used to make simple queries to retrieve the results of complicated queries. For example, views can be used to query information from multiple table s without the user knowing how to write a join statement. Views provide groups of users access to data according to their particular crite ria. Views are divided into two category 1) SIMPLE VIEW 2) COMPLEX VIEW The basic difference is related to the DML (INSERT, UPDATE, and DELETE) operatio ns.

A simple view is one that: Derives data from only one table Contains no functions or groups of data Can perform DML operations through the view A complex view is one that: Derives data from many tables Contains functions or groups of data Does not always allow DML operations through the view Syntax ======= CREATE [OR REPLACE] [FORCE|NOFORCE] VIEW view [(alias[.email id. create or replace view v1 as select employee_id.department_id from e1. thus replacing the old version of the view for its owner.. create or replace view v1 as select employee_id eid . create view v1 as select employee_id.) WITH CHECK OPTION specifies that only those rows that are accessible to the view can be inserted or updated constraint is the name assigned to the CHECK OPTION constraint WITH READ ONLY en sures that no DML operations can be performed on this view ================================================================================ ================================================================================ ====== create table e1 as select * from] AS subquery [WITH CHECK OPTION [CONSTRAINT constraint]] [WITH READ ONLY [CONSTRAINT constraint]]. alias]. subquery is a complete SELECT statement (You can use aliases for the columns in the SELECT list. NOTE :-With the OR REPLACE option.d .means that the view can be altered without dropping update v1 set employee_id=10 where employee_id=198. Th is -----.first_name from e1.first_name.) The number of aliases must match the number of expressions selected by the view. In the syntax: OR REPLACE re-creates the view if it already exists FORCE creates the view regardless of whether or not the base tables exist NOFORCE creates the view only if the base tables exist (This is the default.first_name. a view can be created even if one exists with this name already..

create or replace view v1 as select e. ---.ERROR create or replace view v1 as select employee_id.last_name.salary. create or replace view v1 .department_id.department_id from e1 where department_id=30.department_name from e1 e join d1 d on e. select * from v1. select * from v1.first_name.last_name. along with the constraint name if that h as been ----. select * from v1. update v1 set fname='raj' where eid=10.d. select * from v1.If there is an attempt to perform DML operations on rows that the view h as not update v1 set fname='King' where eid=10.specified.d.department_id update v1 set salary=99999 where employee_id=10.e. update v1 set employee_id=999 where employee_id=10.epartment_id did from e1.employee_id.department_id from e1 where department_id=50 with check option. update v1 set department_id=20 where department_id=50. create or replace view v1 as select employee_id. NOTE :.department_id=d. an error is displayed.

update v1 set salary=9999 where salary=13000.salary from aaaa. create or replace view v1 as select distinct salary from e1. NOTE select employee_id.last_name. create table aaaa as select * from employees.last_name. select * from user_objects where object_name='V1'. select * from v1. select * from user_objects where object_name='V1'. SEQUENCES ----------- . select * from user_objects where object_name='V1'. select * from v1.department_id from e1 where department_id=50 with read only. create or replace force view v1 as select employee_id.Any attempt to remove a row from a view with a read-only constraint resu lts in an error: ------update v1 set employee_id=198 where employee_id=999. drop view v1. View Information DESCRIBE user_views SELECT text FROM user_views WHERE view_name = 'EMP_DETAILS_VIEW'. select * from v1.

200. insert into d2 values (s1. create table e2(employee_id number(10). insert into e2 values(s1. 1 for .nextval. the sequence increments by 1. select * from e2. department_id number(10)) NEXTVAL returns the next available sequence value.'Admin'.salary number(10). In the syntax: -------------sequence is the name of the sequence generator INCREMENT BY n specifies the interval between sequence numbers.20).) MAXVALUE n specifies the maximum value the sequence can generate NOMAXVALUE specifies a maximum value of 10^27 for an ascending sequence and a descending sequence (This is the default option. the sequence starts with 1.last_name varchar2(10). NEXTVAL must be issued for that sequence before CURRVAL contains a value. where n is an in teger (If this clause is omitted.currval-1.) create sequence s1 start with 100 increment by 10 minvalue 1 cache 3 maxvalue 200 nocycle.1700). CURRVAL obtains the current sequence value.CREATE SEQUENCE sequence [INCREMENT BY n] [START WITH n] [{MAXVALUE n | NOMAXVALUE}] [{MINVALUE n | NOMINVALUE}] [{CYCLE | NOCYCLE}] [{CACHE n | NOCACHE}].) MINVALUE n specifies the minimum sequence value NOMINVALUE specifies a minimum value of 1 for an ascending sequence and (10^26) f or a descending sequence (This is the default option.'52000'.'Meghna'. select * from d2.) START WITH n specifies the first sequence number to be generated (If this clause is omitted. It returns a unique value eve ry time it is referenced. even for different users.

last_number FROM user_sequences. increment_by.) ------------------------------------------------------------------------------------------------------------------------------------------------------------------- An index: ------------Is a schema object Can be used by the Oracle server to speed up the retrieval of rows by using a pointer Can reduce disk I/O by using a rapid path access method to locate data quickly Is independent of the table that it indexes Is used and maintained automatically by the Oracle server How Are Indexes Created? Automatically: A unique index is created automatically when you define a PRIMARY KEY or UNIQUE constraint in a table definition. -------------------------------------------------------------------------------- . max_value. Only future sequence numbers are affected. select * from user_indexes where table_name='D2'. min_value. (The LAST_NUMBER column displays the next available sequence number if NOCACHE is specified. select * from d2. You must be the owner or have the ALTER privilege for the sequence. DESCRIBE user_sequences SELECT sequence_name. The sequence must be dropped and re-created to restart the sequence at a different number. Manually: Users can create nonunique indexes on columns to speed up access to the rows.ALTER SEQUENCE sequence [INCREMENT BY n] [{MAXVALUE n | NOMAXVALUE}] [{MINVALUE n | NOMINVALUE}] [{CYCLE | NOCYCLE}] [{CACHE n | NOCACHE}]. create index x1 on d2(department_id).

---------------------------------------------------------------USER_SYNONYMS View The USER_SYNONYMS dictionary view describes private synonyms (synonyms that are owned by you).employees . The columns in this view are: SYNONYM_NAME: Name of the synonym TABLE_OWNER: Owner of the object that is referenced by the synonym TABLE_NAME: Name of the table or view that is referenced by the synonym DB_LINK: Name of the database link reference (if any) create synonym emp for hr. You can query this view to find your synonyms. You can query ALL_SYNONYMS to fin d out the name of all of the synonyms that are available to you and the objects on which these synonyms apply.