Tuesday, 21 April 2015

Table Aliase

Table aliases help to keep SQL code smaller, therefore using less memory.

Table aliases can be up to 30 characters in length, but shorter aliases are better than longer ones.
If a table alias is used for a particular table name in the FROM clause, then that table alias must be substituted for the table name throughout the SELECT statement.
Table aliases should be meaningful.

The table alias is valid for only the current SELECT statement.


SELECT e.employee_id, e.last_name,
       d.location_id, department_id
FROM   employees e JOIN departments d
USING (department_id) ;



Sunday, 19 April 2015

CREATE SEQUENCE

In Oracle you can create an autonumber field by using sequences.

A Sequence is an object in oracle that is used to generate a number sequence.
This can be useful when we need to create unique number to act as a primary key.

The syntax to create a sequence in oracle is:
Create sequence sequence_name
Minvalue value
Maxvalue value
Start with value
Increment By Value;

For Example:-


Create sequence se1
Minvalue 100
Maxvalue 9999
Start with 100
Increment by 1
Nocache ;

This would create object a sequence called seq1. First sequence would be use as is 100 and increment by 1.





Tuesday, 14 April 2015

What is a cross Join

What is a cross join ? Cross join is defined as the cartesian product of records from the tables present in the join. Cross join will produce result which combines each row from the first table with the each row from the second table. Example :- SELECT last_name, department_name FROM employees CROSS JOIN departments ;