SQL Natural Join:

It selects the rows from the two tables that have equal value in all matched columns. If the columns have the same name but different data types then natural join will give an error. It is not possible to do a join without explicitly specifying the column in the corresponding tables. It is possible to let the join be completed automatically based on columns in the two tables which have matching data types and names using the natural join keyword.

Example:

Select emp-id, emp-name, dept-id, dept-name
From emp
Natural join dept ;

In the above example dept table is joined to the emp table by the dept-id column which is the only column of the same name and data type in both the tables. The above example can also be written as an equijoin.

Example:

Select emp-id, emp-name, dept-id, dept-name
From emp, dept
Where emp. dept-id = dept. dept-id;

Note:

in a natural join it is also possible to add a where clause.

Views:

A view is a virtual table in the database defined by a query. A view does not exist in the database as a stored set of data values. The rows and columns of data visible through the view are produced by the query that defines the view.

Create view view-name column-name1, column-name2,as query
<the create view statement syntax>

Horizontal view :

Horizontal view restricts a user's access to selected rows of a table.

Create view view_cust AS
Select * From customer_details
Where cust_id in(101,102,103) ;
<horizontal view>

Vertical view :

Vertical view restricts a user's access to select columns of a table.

Create view view_cust AS
Select cust_id, account_no, account_type
From customer_details ;
<vertical view>


  Tutorials

Popular Links

Contact Us

address Plot No-741,2ND Floor
Opp. Bhagabati Temple,Jayadev Vihar
      Bhubaneswar-751013
      Email: info@silantechnology.com
      Phone: 0674-2361252
address
39877, sundale dr, apt#101, Fremont, California 94538, USA
       Phone: +1(262)388-7619

facebook twitter google linked in

© 2018 Silan Technology. All Rights Reserved