Tuesday, November 5, 2013

How To Run previus query again and again in Oracle


We Have 3 option to run the query again in oracle
1) by "/"
2) by "R"
3) by "RUN"

  • OPTION 1) By "/" Character..













 
  •  option 2) By Writing "R" 














  • OPTION 3) By Writing "RUN"
There Is no Difference between "R" and "RUN" both are same but when we write "/" it doesn't show Query but when we write "R" or "RUN" it shows the Query....!!!!

how to Clear All previous Query output in Oracle Command prompt

To Clear the Output We Have command name "CL SCR" Which is Used to Clear the output

Monday, April 29, 2013

Create index

CREATE INDEX
--------------------------------
Que What do you mean by index ????
Ans :

  1.   In a  General we all that  index is  that  in which we have list of important topics having page no on which it is written or  found. so  through the  index the work of searching particular topic is reduced and we got the fast and  optimum result .
  2. Same in the database we  create an Index on particular field so that we can easy to find the data and got the result as fast as possible.if we create index that will also  help to retrieve the result that will matter in performance tuning.

For DESCRIBE the  USER_INDEXES TABLE  we have Command  DESC user_indexes
f
DESC USER_INDEXES  command  will  display above  information of  user_indexes table
which has different columns and their data type of that table.

  1. Above image  list  the list of  index for the  particular table .  index start from SYS are the  implicit  index which are create when  we create primary key  column.
  2. implicit index is create when primary key constraint is add and removed when Primary key constraint is removed.



Sequence table Description and list of sequence

How to get List of  List of  SEQUENCES Created by the User  ????
--------------------------------------------------------------------------------------------
QUERY :: select * from user_sequences

Result::

DESCRIPTION::
user_Seuences is table which stores all the information all about the created sequences. like MINVAL,MAXVAL,INCREMENT_BY,CYCLE,CACHE_SIZE

MinValue :: this attribute  will define what is the minimum value of Sequence.
MaxValue:: this  attribute  will define what is the maximum value of Sequence.
INCREMENT_BY::this  attribute  will define what is the Increment value of Sequences.
Cycle_FLAG:: This attribute will define that  you want to  restart the cycle after define maximum value.
CACHE_SIZE:: this attribute will define size of cache. this will allow to define  how many value are there in Cache or  buffer ??

Saturday, April 27, 2013

Create sequence with by Different ways and parameters

Following  post will  Help  you  to create  sequence  in oracle


Create SEQUENCE  Command
-----------------------------------------
Syntax:

CREATE SEQUENCE   SEQUENCE_NAME
MINVALUE  [-100 ]   //optional   [Can be  positive or Negative]
MAXVALUE [100]    //optional    [Can be  positive or Negative]
START WITH 0        //optional     [Can be  positive or Negative]
INCREMT BY 1      //optional      [Can be  positive or Negative]

-----------------------------------------
create sequence SqEmp
minvalue 1
maxvalue 500
start with 1
increment by 2


Above Image has  Create Command for Creating Sequence like [ 1,3,5,7,9....]   because   we  Increment Sequence by  "2"  so.. Here We define minimum value  is   1.
Maximum  value is 500 [Here maximum value will be  499].
sequence will no  display index value  more  than  500.

From Above  Image  you can  see that  we can create sequence  with  different style  and  different  parameters.
In a  Image[1]  we have parameter's start with in which we define

  1.  start with (1) 
  2.  increment by (1) 

  if  we Don't  assign such parameter it by default  take (1) for that parameters.

Thursday, April 25, 2013

Cascade delete

In Following Image you can see 2  different result set 
  1. result set 1 is before Delete. [Before delete Query]
  2. result set 2 is after Delete. [After delete Query]


When you perform Delete operation on dept [parent] table it delete its own table and also delete child table (EMP) table's record which are connected to it.

If we Don't Give  on DELETE CASCADE then it will not allow you to delete this parent table records.

Add new Column with Foreign key Constraint


ADDING NEW COLUMN AFTER TABLE CREATION  with FK Constraint

 alter table emp
 add deptno number(3,0)
 add constraint fk_deptno
 foreign key (deptno) references dept(deptno)
on delete cascade

after above option  table  EMP will be  look like


  • Here DEPTNO is Foreign key of DEPT table.


  1. ON DELETE CASCADE option is  optionally.  this  option will  delete all the record when user delete any deptno from its parent table DEPT.
  2. dept is Parent table.
  3. all Child record  will be deleted when its releted Parent table is deleted.