Showing posts with label DBMS. Show all posts
Showing posts with label DBMS. Show all posts

Wednesday, September 23, 2015

Explain the different types of normalization form.

Solution:-

TYPES OF NORMALIZATION FORM:-

       A. First normalization (1NF):-

                  i. Each attribute of the table should be unique.
                  ii. Each value of the table should be atomic.
                  iii. There should not be any duplicate rows.

        B. Second normalization (2NF):-

                   i. It should be in first normal form.
                   ii. Non-key attributes are functionally dependent on the key – attribute. X à y or, X
                        determines Y
                   Or, X determinant and Y is dependent.
                    iii. If the key has more than one attributes then no non-key attributes should be
                          functionally dependent upon a past of the key attributes.

         C. Third normalization ( 3NF ):-

                     A relation is 3NF if and only if it satisfies 2NF and every non-key attributes is
                     non-transitively dependent on the primary key.
                     Roll_no à year , year à hostel_name , Roll_no à hostel_name

         D. Boyce-code normal form (BCNF):-

                      A 3NF relation will not be BCNF if there are multiple candidate keys in the
                      relation such that,
                      i. The candidate keys in the relation are composite keys &
                      ii. The keys   are  not disjoint , that is candidate keys overlap.

What are the different types of join? Explain with example.

Solution:-

 JOIN:-    
             The ‘JOIN’ keyword is used in an SQL statement to query date from two or more tables, based on relationship between certain columns in these tables. 
                                                                                                                        

 Types of JOIN:-

I.         Join (Inner-Join):- Return all rows when there is at least one match

       in both tables.

Example:- 

                Join (Inner Join):-

                SELECT Fname , Lname , order_no

                From cusromers inner join orders

                On customers.c_id = order.c_id ;



II.       Left Join (Left Outer Join):- Return all rows from the left table, even if there are
            no matches in the right table.
            Example:- 
                Left Join (Left Outer Join):-

                SELECT Fname , Lname , order_no

                From cusromers Left join orders

                On customers.c_id = order.c_id ;



III.     Right Join (Right Outer Join):- Return all rows from Right table  even if there
            are no matches in the left table.
     Example:- 
                Right Join (Right Outer Join):-

                SELECT Fname , Lname , order_no

                From cusromers Right  join orders

                On customers.c_id = order.c_id ;


IV.     Full Join(Full Outer Join):- Returns roes when there is a match in one of the 
           table.

Tuesday, September 22, 2015

Define DDL , DML and DCL.

Solution:-
         DDL (Data Definition Language) is used by the database designers and programmers to specify the content and structure of the table. Commands are:- CREATE , DROP , RENAME etc.

Example:- 
 CREATE DATABASE campus ;
CREATE TABLE student ( Roll_no int , Fname varchar(25) , Lname varchar(25) , Address varchar(25) ) ;

            DML (Data Manipulation Language) is related with manipulations of record such as retrieval , sorting , display & deletion of record of data. Commands are:- SELECT , UPDATE , INSERT etc.
Example:- 
 INSERT INTO student values(1001 , “NP”, “Rijal”, “KTM” ) ;
SELECT * FROM student ;
UPDATE student SET Address=”VKT” WHERE Roll_no=1001 ;

           DCL (Data Control Language) is used in controlling the transaction that happened in the database. Example, Rollback commit are DCL and we can use commit statement to finalize the transaction in the database. Once the transaction is committed it cannot be rolled back.
Example are:- GRANT , REVOKE etc.
Example:-
GRANT SELECT ON student TO netra;
REVOKE SELECT ON student to netra;