DBMS lab AL MCA

download DBMS lab AL MCA

of 72

Transcript of DBMS lab AL MCA

  • 8/3/2019 DBMS lab AL MCA

    1/72

    INDEX

    S.NO DATE NAME OF EXPERIMENTSPAGE

    NOMARK

    STAFF

    SIGN

    1Data Definition Language (DDL)

    commands in RDBMS.

    2

    Data Manipulation Language

    DML) and Data ControlLanguage (DCL) commands in

    RDBMS.

    3High-level language extensionwith Cursors

    4High level language extension

    with Triggers

    5 Procedures and Functions.

    6 Embedded SQL.

    7Database design using E-R model

    and Normalization

    8Design and implementation ofPayroll Processing System.

    9Design and implementation of

    Banking System.

    10Design and implementation ofLibrary Information System.

  • 8/3/2019 DBMS lab AL MCA

    2/72

    EX NO: 1 DATA DEFINITION LANGUAGE (DDL)

    DATE:

    AIM:

    To study and perform SQL commands of data definition language.

    ALGORITHM:1.The data definition language consists of the following commands:

    Create

    Alter

    Truncate

    Drop

    2.Create:

    This command is used to create the table.

    Syntax:

    The following syntax is used to create a table:

    Create table (column name1 data type(size of the data), column name

    n data type(size of the data)>);3.Desc:

    This command is used to describe the structure of the database.

    Syntax:

    The following syntax is used to describe the table:

    Desc ;

    4.Alter:

    This command is used to alter the command(i.e either to add or modify thetable)

    Syntax:

    The following syntax is used to alter the table:

    Alter table add/modify( datatype (size of data));5.Truncate:

    This command is used to delete the content of the table and reuse thememory location.

    Syntax:

    The following syntax is used to truncate the table:Truncate table;

    6.Drop:

    This command is used to delete the table.

    Syntax:

    The following syntax is used to delete (or) drop the table:

    Drop table;

  • 8/3/2019 DBMS lab AL MCA

    3/72

    PROCEDURE:

    Create:

    SQL> create table bank(accno number(3),branch varchar(20),cname varchar(20));

    Table created.

    SQL> desc bank;Name Null? Type------------------------------------------- -------- ------------------------------------

    ACCNO NUMBER(3)

    BRANCH VARCHAR2(20)

    CNAME VARCHAR2(20)

    Alter:

    SQL> desc bank;Name Null? Type

    ------------------------------------------- -------- ------------------------------------

    ACCNO NUMBER(3)BRANCH VARCHAR2(20)

    CNAME VARCHAR2(20)

    SQL> alter table bank add(balance number(4));

    Table altered.

    SQL> desc bank;

    Name Null? Type

    ------------------------------------------- -------- ------------------------------------

    ACCNO NUMBER(3)BRANCH VARCHAR2(20)

    CNAME VARCHAR2(20)BALANCE NUMBER(4)

    Truncate:

    SQL> truncate table bank;

    Table truncated.

    Delete:

    SQL> drop table bank;Table dropped.

    RESULT:

    Thus the DDL commands were studied.

    EX NO:2 DATA MANIPULATION LANGUAGE (DML)

  • 8/3/2019 DBMS lab AL MCA

    4/72

    DATE:

    AIM:

    To study and perform the SQL commands of data manipulation language.

    ALGORITHM:

    1.The data manipulation language consists of the following commands: Insert.

    Select.

    Delete.

    Update.

    2.Insert:

    This command is used to insert the values in the table.

    Syntax:

    The following three types of syntax can be used to insert the values intothe table.

    SQL>insert into (column name1,...column name n)values(value 1,..value n);

    [ If the data is string (or) character type ,it should be given within single quotes]

    SQL>inset into values (value 1,..value n);

    SQL>insert into values(&value1,..&value n);

    3.Select:

    This command is used to display the values of the database or the table.

    Syntax:

    The following two types of syntax can be used to display the values from

    the table.

    SQL>select * from ;The above command will display all the values in the table.

    SQL>select delete from where ;The above command is used to delete particular value from the table based on

    some condition.

    SQL>delete from ;This command is used to delete all the records from the table.

    5.Update:

    This command is used to modify the existing values of the table.

  • 8/3/2019 DBMS lab AL MCA

    5/72

    Syntax:

    The syntax for updating the existing record is as follows.SQL>Update set where ;

    PROCEDURE:

    Insert:

    SQL> insert into bank (accno, cname, branch) values (2444,'dhana','salem');1 row created.

    SQL> insert into bank values(444,'hari','chennai');

    1 row created.

    SQL> insert into bank values(&accno,'&cname','&branch');

    Enter value for accno: 100Enter value for cname: arun

    Enter value for branch: erode

    old 1: insert into bank values(&accno,'&cname','&branch');new 1: insert into bank values(100,'arun','erode')

    select:

    SQL> select*from bank;

    ACCNO CNAME BRANCH--------- -------------------- --------------------

    2444 dhana salem

    444 hari Chennai

    100 arun erode

    SQL>select cname,branch where accno=444;

    ACCNO CNAME BRANCH

    --------- -------------------- --------------------

    444 hari Chennai

    SQL>select branch where accno=100 and branch=Chennai;

    ACCNO CNAME BRANCH--------- -------------------- --------------------

    100 arun erode

    Update:

  • 8/3/2019 DBMS lab AL MCA

    6/72

    SQL>update bank set accno=244 where accno=2444;1 row updated;

    SQL>select*from bank;

    ACCNO CNAME BRANCH--------- -------------------- --------------------244 dhana salem

    444 hari Chennai

    100 arun erode

    Delete:

    SQL>delete from bank where cname=dhana;

    SQL>select*from bank;

    ACCNO CNAME BRANCH

    --------- -------------------- --------------------

    444 hari Chennai

    100 arun erode

    RESULT:

    Thus the DML commands were studied.

  • 8/3/2019 DBMS lab AL MCA

    7/72

    EX NO:3 HIGH LEVEL LANGUAGE EXTENSION WITH CURSORS

    DATE:

    AIM:

    To write and execute a PL/SQL program using cursors.

    ALGORITHM:

    1.create a cursor

    2.declare the variables required.

    3.perform the various cursor commands

    (i)open(ii)fetch.

    (iii)close

    4.open:

    syntax:

    open

    5.Create the cursor without any errors and perform necessary PL/SQL operations.6.FETCH:

    syntax:

    fetchinto

    7.CLOSE:

    syntax:

    8.Execute the cursor and validate the result.9.End the program.

    PROGRAM 1:

    1 declare2 cursor s is select regno,name,mark1,mark2 from ugr;

    3 sregno ugr.regno % type;4 sname ugr.name% type;

    5 smark1 ugr.mark1 % type;

    6 smark2 ugr.mark2 % type;

    7 stot ugr.total% type;8 begin

    9 open s;

    10 loop11 fetch s into sregno,sname,smark1,smark2;

    12 exit when s % notfound;13 stot:=(smark1+smark2);14 update ugr set total=stot where regno=sregno;

    15 end loop;

    16 close s;17* end;

    SQL> /

  • 8/3/2019 DBMS lab AL MCA

    8/72

    PL/SQL procedure successfully completed.

    SQL> set serveroutput on;SQL> /

    PL/SQL procedure successfully completed.SQL> select*from ugr;

    REGNO NAME MARK1 MARK2 TOTAL--------- -------------------- --------- --------- ---------

    1 Rahul 100 100 200

    2 Rohith 90 90 180

    PROGRAM 2:

    1 declare2 cursor emp_cur is select * from emp where dno=10 or dno=20;

    3 vemp emp % rowtype;

    4 begin5 open emp_cur;

    6 dbms_output.put_line(' dno ' || ' eno ' || ' ename ' || ' salary ' );

    7 loop8 fetch emp_cur into Vemp;

    9 if Vemp.salary>=100 then

    10 dbms_output.put_line(vemp.dno|| ' ' || vemp.eno || ' ' || vemp.ename || ' '||vemp.salary);

    11 end if;12 exit when emp_cur % NOTFOUND;

    13 end loop;

    14 dbms_output.put_line('no of employees:'||emp_cur % rowcount);

    15 close emp_cur;16* end;

    17 /

    PL/SQL procedure successfully completed.

    SQL> set serveroutput on;SQL> /

    OUTPUT:

    dno eno ename salary209 523 raja 5000No of employees:1

    RESULT:

    Thus the above program was executed and verified.

  • 8/3/2019 DBMS lab AL MCA

    9/72

    EX NO:4 HIGH LEVEL LANGUAGE EXTENSION WITH TRIGGER

    DATE:

    AIM:

    To write and execute a PL/SQL program using Trigger.

    ALGORITHM:1.Create a trigger.

    2.Declare the variables required.

    3.Specify the triggering condition using following syntax:

    create or replace trigger

    4.Perform the necessary PL/SQL operations

    5.Execute the program and if there is any error display the error message using followingsyntax:

    raise_application_error(error no,error message);20000 to 20999(range for error merssage)

    6.validate the result

    7.End the program.

    PROGRAM:

    1 create or replace trigger acc_up_bal after insert on acctrans for each row

    2 declare3 vaccno acctrans.accno%type;

    4 vtrans acctrans.transamt%type;

    5 vtranstype acctrans.transtype%type;

    6 begin7 vaccno:=:new.accno;

    8 vtrans:=:new.transamt;9 vtranstype:=:new.transtype;

    10 if vtranstype='d' then

    11 update accmaster set bal=bal+vtrans where accno=vaccno;

    12 elsif vtranstype='w' then13 update accmaster set bal=bal-vtrans where accno=vaccno;

    14 end if;

    15* end;SQL> /

    Trigger created.

    SQL> insert into acctrans values(1001,123,'09dec08',7000,'d');

    1 row created.

  • 8/3/2019 DBMS lab AL MCA

    10/72

    Error at line 1

    ORA 20010:Withdraw is not possible.ORA 06512:At SCOTT.acc_update_bal,line14

    ORA 04088:error during execution of trigger SCOTT.acc_update_bal

    SQL> create or replace trigger acc_trig before delete on emp2 begin3 raise_application_error(-20001,'details record may be present');

    4 end;

    5 /

    Trigger created.

    SQL> delete from emp where sal=3000;delete from emp where sal=3000

    *

    ERROR at line 1:ORA-20001: details record may be present

    ORA-06512: at "SCOTT.ACC_TRIG", line 2

    ORA-04088: error during execution of trigger 'SCOTT.ACC_TRIG'

    RESULT:

    Thus the above program was executed and verified.

  • 8/3/2019 DBMS lab AL MCA

    11/72

    EX NO:5 PROCEDURE AND FUNCTIONSDATE:

    AIM:

    To write and execute a PL/SQL program to implement Procedure and function.

    ALGORITHM:1.Create a Procedure and Function

    2.Declare the variables required.

    3.Perform Procedure and Function using commands/query in its main parts.

    4.Main parts of function,procedure are(i) Declaration part.

    (ii) Execution part.

    (iii) Exception part.5.Syntax for procedure:

    create or replace procedure < procedure name>[argument[IN/OUT/INOUT] data

    type[IS/AS]variable data type

    begin

    PL/SQL coding;Execution part;(optional)

    End

    6. Syntax for Functioncreate or replace function< function name>return data type[IS/AS]

    fullname variable data type;(optional)

    begin

    PL/SQL part

    Exception part(optional)End

    7.Execution the result8.Stop the program.

    PROCEDURE:

    1 create or replace procedure acc_detail(accno1 in number) is

    2 cname varchar2(15);

    3 balamt number(6,2);4 b number(6,2);

    5 name varchar2(15);

    6 balance number(6,2);7 minbal number(6,2);8 begin

    9 select name,balance into cname,balamt from bankdet where accno=accno1;

    10 minbal:=5000;11 if balamt>minbal then

    12 b:=balamt-minbal;

    13 dbms_output.put_line('possible withdraw amount is'||b);

  • 8/3/2019 DBMS lab AL MCA

    12/72

    14 else

    15 dbms_output.put_line('withgdraw is not possible');16 end if;

    17* end;

    SQL> /

    Procedure created.

    SQL> exec acc_detail(111);

    possible withdraw amount is 2000.

    PL/SQL procedure successfully completed.

    FUNCTION:

    1 create or replace function acc_detailfun(accno1 number) return number is2 cname varchar2(15);

    3 balamt number(6,2);

    4 b number(5);5 balance number(6,2);

    6 minbal number(6,2);

    7 begin

    8 select cname,balance into cname,balamt from bdet where accno=accno1;9 minbal:=5000;

    10 if balamt>minbal then

    11 b:=balamt-minbal;12 return b;

    13 else

    14 dbms_output.put_line('withdraw is not possible');

    15 end if;16* end;

    SQL> /

    Function created.

    SQL> declare

    2 a number(5);3 b number(5);

    4 begin

    5 a:=&accno;6 b:=acc_detailfun(a);

    7 dbms_output.put_line('possible withdraw amt is'||b);8 end;9 /

    Enter value for accno: 112

    old 5: a:=&accno;

    new 5: a:=112;possible withdraw amt is2000

  • 8/3/2019 DBMS lab AL MCA

    13/72

    PL/SQL procedure successfully completed.

    RESULT:

    Thus the above program was executed and verified.

    EX.NO:6 EMBEDDED SQL

  • 8/3/2019 DBMS lab AL MCA

    14/72

    DATE:

    import java.sql.*;class Emp{

    public static void main(String args[])

    {

    try{

    Class.forName("sun.jdbc.odbc.jdbcOdbcDriver");

    Connection con =DriverManager.getConnection("jdbc:odbc:emp","k6500","k6500");

    Statement stmt=con.CreateStatement();

    ResultSet rs=stmt.execute Query("select * from emp1");while(rs.next())

    {

    System.out.print("Employee No = " + rs.getInt (1) );

    System.out.print("Employee Name = " + rs.getString (2) );System.out.print(Salary = " + rs.getInt (3) );

    System.out.print("\n");

    }stmt.close();

    con.close();

    }

    catch (java.lang.Exception ex)

    {System.out.println("Error:"+ex);

    }

    }

    }

    OUTPUT:

    To Compile:

    Z:\> set path = z:\jdk1.3\bin;Z:\> javac emp.java

    To Run:

    Z:\> java emp

    Employee No=11 Employee Name =a Salary= 6500.5Employee No=12 Employee Name =b Salary= 4500

    Employee No=13 Employee Name =c Salary= 10000

  • 8/3/2019 DBMS lab AL MCA

    15/72

  • 8/3/2019 DBMS lab AL MCA

    16/72

    SQL> select * from employees;

    NO NAME DEPTNO SALARY JOB COMM

    --------- ------------------------- --------- --------- ---------- ---------

    11 a 101 6500.5 clerk 1012 b 101 4500 tech 10

    13 c 110 10000 manager 50

    RESULT:

    Thus the above program was executed and verified.

  • 8/3/2019 DBMS lab AL MCA

    17/72

    EX.NO:7 DATABASE DESIGN USING E-R MODEL AND

    DATE: NORMALIZATION

    TABLE EPROJECT IN FIRST NORMAL FORM NOT IN SECOND NORMALFORM

    SQL> create table eproject(ssn number(5) primary key, pnumber number(3),hoursnumber(5), ename varchar(10), pname varchar(10), plocation varchar(10));

    Table created.

    SQL>desc eproject;

    Name Null? Type------------------------------- -------- ----

    SSN NOT NULL NUMBER(5)

    PNUMBER NUMBER(3)HOURS NUMBER(5)

    ENAME VARCHAR2(10)

    PNAME VARCHAR2(10)

    PLOCATION VARCHAR2(10)

    SQL>insert into eproject values(&ssn, &pnumber, &hours, &ename, &pname,

    &plocation);

    SQL>select * from eproject;

    SQL> select * from eproject;

    SSN PNUMBER HOURS ENAME PNAME PLOCATION--------- --------- --------- ---------- ---------- ----------

    111 100 3 Raj WAP1X Dehradun

    112 101 4 Kavitha SAP1X Varanasi

    113 110 5 Manish SAP1X Varanasi

    NORMALIZING EPROJECT INTO SECOND NORMAL FORM

    SQL>create table eproject1(ssn number(5) primary key, pnumber number(5), hours

    number(5));

    Table created.

    SQL>desc eproject1;

  • 8/3/2019 DBMS lab AL MCA

    18/72

    Name Null? Type------------------------- ------ -------- ----

    SSN NOT NULL NUMBER(5)

    PNUMBER NUMBER(5)HOURS NUMBER(5)

    SQL>insert into eproject1 values(&ssn,&pnumber,&hours);

    SQL>select * from eproject1;

    SSN PNUMBER HOURS--------- --------- ---------

    111 100 3

    112 101 4113 110 5

    SQL>create table eproject2(ssn number(5) primary key, ename varchar(10));

    Table created.

    SQL>desc eproject2;

    Name Null? Type------------------------------- -------- ----

    SSN NOT NULL NUMBER(5)

    ENAME VARCHAR2(10)

    SQL>insert into eproject2 values(&ssn,&ename);

    SQL>select * from eproject2;

    SSN ENAME----- ----------

    111 Raj

    112 Kavitha113 Manish

    SQL>create table eproject3(pnumber number(5) primary key,pnamevarchar(10),plocation varchar(10));

    Table created.

    SQL>desc eproject3;

  • 8/3/2019 DBMS lab AL MCA

    19/72

    Name Null? Type

    ----------------------- -------- -------- ----PNUMBER NOT NULL NUMBER(5)

    PNAME VARCHAR2(10)

    PLOCATION VARCHAR2(10)

    SQL>insert into eproject3 values(&pnumber,&pname,&plocation);

    SQL>select * from eproject3;

    PNUMBER PNAME PLOCATION-------- ---------- ----------

    100 WAP1X Dehradun

    101 SAP1X Varanasi110 WAP1X Dehradun

    TABLE EDEPT IN FIRST NORMAL FORM NOT IN THIRD NORMAL FORM

    SQL>create table edept(ename varchar(10),ssn number(5),address varchar(10),dnonumber(5), dname varchar(10),dmgrssn number(5));

    Table created.

    SQL>desc edept;

    Name Null? Type------------------------------- -------- ----

    ENAME VARCHAR2(10)SSN NUMBER(5)

    ADDRESS VARCHAR2(10)

    DNO NUMBER(5)

    DNAME VARCHAR2(10)DMGRSSN NUMBER(5)

    SQL>insert into edept values (&ename,&ssn,&address,&dno,&dname, &dmgrssn);

  • 8/3/2019 DBMS lab AL MCA

    20/72

    SQL> select * from edept;

    ENAME SSN ADDRESS DNO DNAME DMGRSSN

    ---------- --------- ---------- --------- ---------- ---------Raj 111 Northst 900 EDP 200

    Kavitha 112 Souhtst 901 MAT 201Manish 113 Westst 902 IT 202

    NORMALIZING EDEPT INTO THIRD NORMAL FORM

    SQL>create table edept1(ename varchar(10),ssn number primary key,address

    varchar(10),dno number(5));

    Table created.

    SQL>desc edept1;

    Name Null? Type

    -------------------- ----------- -------- ----

    ENAME VARCHAR2(10)SSN NOT NULL NUMBER

    ADDRESS VARCHAR2(10)

    DNO NUMBER(5)

    SQL>insert into edept1 values(&ename,&ssn,&address,&dno);

    ENAME SSN ADDRESS DNO---------- - -------- ---------- ---------

    Raj 111 Northst 900Kavitha 112 Southst 901

    Manish 113 Westst 902

    SQL>select * from edept1;

    SQL>create table edept2(dno number(5)primary key,dname varchar(20),dmgrssn

    number(5));

    Table created.

    SQL>desc edept2;

    Name Null? Type

    ----------------------- -------- -------- ----DNO NOT NULL NUMBER(5)

    DNAME VARCHAR2(20)

  • 8/3/2019 DBMS lab AL MCA

    21/72

    DMGRSSN NUMBER(5)

    SQL>insert into edept2 values(&dno, &dname, &dmgrssn);

    SQL>select * from edept2;

    DNO DNAME DMGRSSN---- -------------------- ---------900 EDP 200

    901 MAT 201

    902 IT 202

    RESULT:

    Thus the above program was executed and verified.

  • 8/3/2019 DBMS lab AL MCA

    22/72

    EX.NO:8 DESIGN & IMPLEMENTATION OF PAYROLL PROCESSING

    DATE : SYSTEM

    SQL> create table payroll( name varchar(20), no number(10), des varchar(10), dept

    varchar(10), basicpay number(10,3), da number(10,3), hra number (10,3), pfnumber(10,3), grosspay number(10,3), netpay number(10,3));

    SQL> desc payroll;

    Name Null? Type------------------------------- -------- ----

    NAME VARCHAR2(20)

    NO NUMBER(10)DES VARCHAR2(10)

    DEPT VARCHAR2(10)

    BASICPAY NUMBER(10,3)DA NUMBER(10,3)

    HRA NUMBER(10,3)

    PF NUMBER(10,3)

    GROSSPAY NUMBER(10,3)NETPAY NUMBER(10,3)

    Form name: Payroll SystemCanvas name: Canvas2

    Type: Trigger

    Function name: when_mouse_click

    PL/SQL CODING:

    Move to the First record:

    FIRST_RECORD;

    COMMIT;

    Move to the Last record:

    LAST_RECORD;

    COMMIT;

    Move to the Next record:

    NEXT_RECORD;

    COMMIT;

    Move to the Previous record:

  • 8/3/2019 DBMS lab AL MCA

    23/72

    PREVIOUS_RECORD;COMMIT;

    Execute Record:

    EXECUTE_QUERY(ALL_RECORDS);COMMIT;

    Save a record:

    BEGINCOMMIT;

    NEXT_RECORD;

    END;

    Delete a record:

    DELETE_RECORD;

    COMMIT;

    Clear the Form:

    CLEAR_FORM(DO_COMMIT);

    To Exit:

    EXIT_FORM;

    Calculate:

    BEGIN

    IF :BASICPAY >= 10000 THEN

    :DA := 0.5 * :BASICPAY;

    :HRA := 0.1 * :BASICPAY;

    ELSIF :BASICPAY < 1000 AND :BASICPAY >= 5000 THEN

    :DA := 0.4 * :BASICPAY;:HRA := 0.1 * :BASICPAY;

    ELSE

    :DA := 0.2 * :BASICPAY;

    :HRA := 0.1 * :BASICPAY;

  • 8/3/2019 DBMS lab AL MCA

    24/72

    END IF;

    :PF := 0.2 * :BASICPAY;

    :GROSSPAY := :BASICPAY + :DA + :HRA;:NETPAY := :GROSSPAY - :PF;

    END;

    SQL> select * from payroll;

    NAME NO DES DEPT BASICPAY DA HRA

    -------- ---------- ---------- --------- --------- --------- ---------

    MSS 113 PA EDP 500 100 50

    SIVA 112 CLERK EDP 5000 1000 500

    GANGA 111 MANAGER OFFICE 10000 5000 1000

    PF GROSSPAY NETPAY---- ----------- ----------

    100 650 550

    1000 6500 55002000 16000 14000

  • 8/3/2019 DBMS lab AL MCA

    25/72

    PAYROLL PROCESSING SYSTEM - DESIGN AND OUTPUT

  • 8/3/2019 DBMS lab AL MCA

    26/72

    RESULT:

    Thus the above program was executed and verified.

  • 8/3/2019 DBMS lab AL MCA

    27/72

    EX.NO: 9 DESIGN & IMPLEMENTATION OF BANKING

    DATE : SYSTEMS

    SQL> create table accounts(Acno number(5),CustomerName varchar(25),Branchvarchar(25),City varchar(25),Balance number(10,2),Amount number(10,2));

    Table created.

    SQL> desc accounts;

    Name Null? Type

    ------------------------------- -------- ----

    ACNO NUMBER(5)CUSTOMERNAME VARCHAR2(25)

    BRANCH VARCHAR2(25)

    CITY VARCHAR2(25)BALANCE NUMBER(10,2)

    AMOUNT NUMBER(10,2)

    Form name: Account Details

    Canvas name: Canvas2

    Type: Trigger Function name: when_mouse_click

    PL/SQL CODING:

    Move to the First record:

    FIRST_RECORD;

    COMMIT;

    Move to the Last record:

    LAST_RECORD;

    COMMIT;

    Move to the Next record:

    NEXT_RECORD;

    COMMIT;

    Move to the Previous record:

    PREVIOUS_RECORD;

  • 8/3/2019 DBMS lab AL MCA

    28/72

    COMMIT;

    Execute Record:

    EXECUTE_QUERY (ALL_RECORDS);COMMIT;

    Save a record:

    BEGIN

    COMMIT;

    NEXT_RECORD;END;

    Delete a record:

    DELETE_RECORD;COMMIT;

    Clear the Form:

    CLEAR_FORM (DO_COMMIT);

    To Exit:

    EXIT_FORM;

    Deposit:

    BEGIN

    IF :AMOUNT > 0 AND :BALANCE > 0 THEN

    :BALANCE := :BALANCE + :AMOUNT;

    END IF;

    END;

    WithDraw:

    BEGIN

    IF :AMOUNT > 0 AND :BALANCE > 0 THEN

    :BALANCE := :BALANCE - :AMOUNT;

  • 8/3/2019 DBMS lab AL MCA

    29/72

    END IF;

    END;

    SQL> select * from accounts;

    ACNO CUSTOMERNAME BRANCH CITY

    --------- ------------------------- ------------------ -----------

    101 SIVA SRIRANGAM TRICHY

    102 PREM BHEL TRICHY

    BALANCE AMOUNT

    ------------- ------------

    4900 100

    6000 1000

  • 8/3/2019 DBMS lab AL MCA

    30/72

    BANKING SYSTEMS - DESIGN AND OUTPUT

    Result:

    Thus the program was verified successfully verified and executed.

  • 8/3/2019 DBMS lab AL MCA

    31/72

    EX.NO:10 DESIGN & IMPLEMENTATION OF LIBRARY

    DATE: INFORMATION SYSTEM.

    SQL> create table library(Bookno number(5),Bookname varchar(25),Authornamevarchar(25),Price number(4),Publication varchar(25),Edition number(5),EntryDate

    date,Returndate date,Duedate date,Fine number(4));

    Table created.

    SQL>desc library;

    Name Null? Type

    ------------------------------- -------- ----

    BOOKNO NUMBER(5)BOOKNAME VARCHAR2(25)

    AUTHORNAME VARCHAR2(25)

    PRICE NUMBER(4)PUBLICATION VARCHAR2(25)

    EDITION NUMBER(5)

    ENTRYDATE DATE

    RETURNDATE DATEDUEDATE DATE

    FINE NUMBER(4)

    Form name: Library Details

    Canvas name: Canvas2

    Type: Trigger Function name: when_mouse_click

    PL/SQL CODING:

    Move to the First record:

    FIRST_RECORD;

    COMMIT;

    Move to the Last record:

    LAST_RECORD;COMMIT;

    Move to the Next record:

    NEXT_RECORD;

    COMMIT;

  • 8/3/2019 DBMS lab AL MCA

    32/72

    Move to the Previous record:

    PREVIOUS_RECORD;

    COMMIT;

    Execute Record:

    EXECUTE_QUERY (ALL_RECORDS);

    COMMIT;

    Save a record:

    BEGIN

    COMMIT;NEXT_RECORD;

    END;

    Delete a record:

    DELETE_RECORD;COMMIT;

    Clear the Form:

    CLEAR_FORM (DO_COMMIT);

    To Exit:

    EXIT_FORM;

    Calculate:

    BEGIN

    :DUEDATE := :ENTRYDATE + 30;

    IF :DUEDATE < :RETURNDATE THEN:FINE := ( :RETURNDATE - :DUEDATE ) * 3;

    END IF;END;LIBRARY INFORMATION SYSTEM - DESIGN AND OUTPUT

  • 8/3/2019 DBMS lab AL MCA

    33/72

    RESULT:

    Thus the above program was executed and verified.

  • 8/3/2019 DBMS lab AL MCA

    34/72

    S.NO DATE NAME OF EXPERIMENTSPAGE

    NOMARK

    STAFF

    SIGN

    1Data Definition Language (DDL)

    commands in RDBMS.

    2

    Data Manipulation Language

    DML) and Data ControlLanguage (DCL) commands in

    RDBMS.

    3High-level language extensionwith Cursors

    4High level language extension

    with Triggers

    5 Procedures and Functions.

    6 Embedded SQL.

    7Database design using E-R model

    and Normalization

    8Design and implementation ofPayroll Processing System.

    9Design and implementation of

    Banking System.

    10Design and implementation ofLibrary Information System.

  • 8/3/2019 DBMS lab AL MCA

    35/72

    EX NO: 1 DATA DEFINITION LANGUAGE (DDL)DATE:

    AIM:

    To study and perform SQL commands of data definition language.

    ALGORITHM:

    1.The data definition language consists of the following commands:

    Create

    Alter

    Truncate

    Drop

    2.Create:

    This command is used to create the table.Syntax:

    The following syntax is used to create a table:

    Create table (column name1 data type(size of the data), column namen data type(size of the data)>);

    3.Desc:

    This command is used to describe the structure of the database.Syntax:

    The following syntax is used to describe the table:

    Desc ;

    4.Alter:This command is used to alter the command(i.e either to add or modify the

    table)

    Syntax:

    The following syntax is used to alter the table:Alter table add/modify( datatype (size of data));

    5.Truncate:This command is used to delete the content of the table and reuse the

    memory location.

    Syntax:The following syntax is used to truncate the table:

    Truncate table;

    6.Drop:

    This command is used to delete the table.Syntax:

    The following syntax is used to delete (or) drop the table:Drop table;

  • 8/3/2019 DBMS lab AL MCA

    36/72

    PROCEDURE:

    Create:

    SQL> create table bank(accno number(3),branch varchar(20),cname varchar(20));

    Table created.

    SQL> desc bank;Name Null? Type------------------------------------------- -------- ------------------------------------

    ACCNO NUMBER(3)

    BRANCH VARCHAR2(20)

    CNAME VARCHAR2(20)

    Alter:

    SQL> desc bank;Name Null? Type

    ------------------------------------------- -------- ------------------------------------

    ACCNO NUMBER(3)BRANCH VARCHAR2(20)

    CNAME VARCHAR2(20)

    SQL> alter table bank add(balance number(4));

    Table altered.

    SQL> desc bank;

    Name Null? Type

    ------------------------------------------- -------- ------------------------------------

    ACCNO NUMBER(3)BRANCH VARCHAR2(20)

    CNAME VARCHAR2(20)BALANCE NUMBER(4)

    Truncate:

    SQL> truncate table bank;

    Table truncated.

    Delete:

    SQL> drop table bank;Table dropped.

    RESULT:

    Thus the DDL commands were studied.

    EX NO:2 DATA MANIPULATION LANGUAGE (DML)

  • 8/3/2019 DBMS lab AL MCA

    37/72

    DATE:

    AIM:

    To study and perform the SQL commands of data manipulation language.

    ALGORITHM:

    1.The data manipulation language consists of the following commands: Insert.

    Select.

    Delete.

    Update.2.Insert:

    This command is used to insert the values in the table.

    Syntax:

    The following three types of syntax can be used to insert the values intothe table.

    SQL>insert into (column name1,...column name n)values(value 1,..value n);

    [ If the data is string (or) character type ,it should be given within single quotes]

    SQL>inset into values (value 1,..value n);

    SQL>insert into values(&value1,..&value n);

    3.Select:This command is used to display the values of the database or the table.

    Syntax:

    The following two types of syntax can be used to display the values from

    the table.

    SQL>select * from ;The above command will display all the values in the table.

    SQL>select delete from where ;The above command is used to delete particular value from the table based on

    some condition.

    SQL>delete from ;This command is used to delete all the records from the table.

    5.Update:

    This command is used to modify the existing values of the table.

  • 8/3/2019 DBMS lab AL MCA

    38/72

    Syntax:

    The syntax for updating the existing record is as follows.SQL>Update set where ;

    PROCEDURE:

    Insert:

    SQL> insert into bank(accno,cname,branch) values(2444,'dhana','salem');1 row created.

    SQL> insert into bank values(444,'hari','chennai');

    1 row created.

    SQL> insert into bank values(&accno,'&cname','&branch');

    Enter value for accno: 100Enter value for cname: arun

    Enter value for branch: erode

    old 1: insert into bank values(&accno,'&cname','&branch');new 1: insert into bank values(100,'arun','erode')

    select:

    SQL> select*from bank;

    ACCNO CNAME BRANCH--------- -------------------- --------------------

    2444 dhana salem

    444 hari Chennai

    100 arun erode

    SQL>select cname,branch where accno=444;

    ACCNO CNAME BRANCH

    --------- -------------------- --------------------

    444 hari Chennai

    SQL>select branch where accno=100 and branch=Chennai;

    ACCNO CNAME BRANCH--------- -------------------- --------------------

    100 arun erode

    Update:

  • 8/3/2019 DBMS lab AL MCA

    39/72

    SQL>update bank set accno=244 where accno=2444;

    1 row updated;

    SQL>select*from bank;

    ACCNO CNAME BRANCH

    --------- -------------------- --------------------244 dhana salem444 hari Chennai

    100 arun erode

    Delete:

    SQL>delete from bank where cname=dhana;

    SQL>select*from bank;

    ACCNO CNAME BRANCH--------- -------------------- --------------------

    444 hari Chennai

    100 arun erode

    RESULT:Thus the DML commands were studied.

  • 8/3/2019 DBMS lab AL MCA

    40/72

    EX NO:3 HIGH LEVEL LANGUAGE EXTENSION WITH CURSORS

    DATE:

    AIM:

    To write and execute a PL/SQL program using cursors.

    ALGORITHM:

    1.create a cursor

    2.declare the variables required.

    3.perform the various cursor commands

    (i)open(ii)fetch.

    (iii)close

    4.OPEN:syntax:

    open

    5.Create the cursor without any errors and perform necessary PL/SQL operations.6.FETCH:

    syntax:

    fetchinto

    7.CLOSE:syntax:

    8.Execute the cursor and validate the result.9.End the program.

    PROGRAM 1:

    1 declare2 cursor s is select regno,name,mark1,mark2 from ugr;

    3 sregno ugr.regno % type;4 sname ugr.name% type;

    5 smark1 ugr.mark1 % type;

    6 smark2 ugr.mark2 % type;

    7 stot ugr.total% type;8 begin

    9 open s;

    10 loop11 fetch s into sregno,sname,smark1,smark2;

    12 exit when s % notfound;13 stot:=(smark1+smark2);14 update ugr set total=stot where regno=sregno;

    15 end loop;

    16 close s;17* end;

    SQL> /

  • 8/3/2019 DBMS lab AL MCA

    41/72

    PL/SQL procedure successfully completed.

    SQL> set serveroutput on;SQL> /

    PL/SQL procedure successfully completed.SQL> select*from ugr;

    REGNO NAME MARK1 MARK2 TOTAL--------- -------------------- --------- --------- ---------

    1 Rahul 100 100 200

    2 Rohith 90 90 180

    PROGRAM 2:

    1 declare2 cursor emp_cur is select * from emp where dno=10 or dno=20;

    3 vemp emp % rowtype;

    4 begin5 open emp_cur;

    6 dbms_output.put_line(' dno ' || ' eno ' || ' ename ' || ' salary ' );

    7 loop8 fetch emp_cur into Vemp;

    9 if Vemp.salary>=100 then

    10 dbms_output.put_line(vemp.dno|| ' ' || vemp.eno || ' ' || vemp.ename || ' '||vemp.salary);

    11 end if;12 exit when emp_cur % NOTFOUND;

    13 end loop;

    14 dbms_output.put_line('no of employees:'||emp_cur % rowcount);

    15 close emp_cur;16* end;

    17 /

    PL/SQL procedure successfully completed.

    SQL> set serveroutput on;SQL> /

    OUTPUT:

    dno eno ename salary209 523 raja 5000No of employees:1

    RESULT:

    Thus the above program was executed and verified.

  • 8/3/2019 DBMS lab AL MCA

    42/72

    EX NO:4 HIGH LEVEL LANGUAGE EXTENSION WITH TRIGGER

    DATE:

    AIM:

    To write and execute a PL/SQL program using Trigger.

    ALGORITHM:1.Create a trigger.2.Declare the variables required.

    3.Specify the triggering condition using following syntax:

    create or replace trigger 4.Perform the necessary PL/SQL operations

    5.Execute the program and if there is any error display the error message using following

    syntax:

    raise_application_error(error no,error message);

    20000 to 20999(range for error merssage)6.validate the result

    7.End the program.

    PROGRAM:

    1 create or replace trigger acc_up_bal after insert on acctrans for each row

    2 declare

    3 vaccno acctrans.accno%type;4 vtrans acctrans.transamt%type;

    5 vtranstype acctrans.transtype%type;

    6 begin

    7 vaccno:=:new.accno;8 vtrans:=:new.transamt;

    9 vtranstype:=:new.transtype;10 if vtranstype='d' then

    11 update accmaster set bal=bal+vtrans where accno=vaccno;

    12 elsif vtranstype='w' then

    13 update accmaster set bal=bal-vtrans where accno=vaccno;14 end if;

    15* end;

    SQL> /

    Trigger created.

    SQL> insert into acctrans values(1001,123,'09dec08',7000,'d');

    1 row created.

    Error at line 1

  • 8/3/2019 DBMS lab AL MCA

    43/72

    ORA 20010:Withdraw is not possible.

    ORA 06512:At SCOTT.acc_update_bal,line14ORA 04088:error during execution of trigger SCOTT.acc_update_bal

    SQL> create or replace trigger acc_trig before delete on emp

    2 begin3 raise_application_error(-20001,'details record may be present');4 end;

    5 /

    Trigger created.

    SQL> delete from emp where sal=3000;

    delete from emp where sal=3000*

    ERROR at line 1:

    ORA-20001: details record may be presentORA-06512: at "SCOTT.ACC_TRIG", line 2

    ORA-04088: error during execution of trigger 'SCOTT.ACC_TRIG'

    RESULT:

    Thus the above program was executed and verified.

  • 8/3/2019 DBMS lab AL MCA

    44/72

    EX NO:5 PROCEDURE AND FUNCTIONSDATE:

    AIM:

    To write and execute a PL/SQL program to implement Procedure and function.

    ALGORITHM:

    1.Create a Procedure and Function

    2.Declare the variables required.

    3.Perform Procedure and Function using commands/query in its main parts.4.Main parts of function,procedure are

    (i) Declaration part.

    (ii) Execution part.(iii) Exception part.

    5.Syntax for procedure:

    create or replace procedure < procedure name>[argument[IN/OUT/INOUT] datatype[IS/AS]

    variable data type

    beginPL/SQL coding;

    Execution part;(optional)

    End6. Syntax for Function

    create or replace function< function name>return data type[IS/AS]

    fullname variable data type;(optional)

    begin

    PL/SQL partException part(optional)

    End7.Execution the result

    8.Stop the program.

    PROCEDURE:

    1 create or replace procedure acc_detail(accno1 in number) is

    2 cname varchar2(15);3 balamt number(6,2);

    4 b number(6,2);

    5 name varchar2(15);6 balance number(6,2);7 minbal number(6,2);

    8 begin

    9 select name,balance into cname,balamt from bankdet where accno=accno1;10 minbal:=5000;

    11 if balamt>minbal then

    12 b:=balamt-minbal;

  • 8/3/2019 DBMS lab AL MCA

    45/72

    13 dbms_output.put_line('possible withdraw amount is'||b);

    14 else15 dbms_output.put_line('withgdraw is not possible');

    16 end if;

    17* end;SQL> /

    Procedure created.

    SQL> exec acc_detail(111);

    possible withdraw amount is 2000.

    PL/SQL procedure successfully completed.

    FUNCTION:

    1 create or replace function acc_detailfun(accno1 number) return number is

    2 cname varchar2(15);

    3 balamt number(6,2);4 b number(5);

    5 balance number(6,2);

    6 minbal number(6,2);

    7 begin8 select cname,balance into cname,balamt from bdet where accno=accno1;

    9 minbal:=5000;

    10 if balamt>minbal then11 b:=balamt-minbal;

    12 return b;

    13 else

    14 dbms_output.put_line('withdraw is not possible');15 end if;

    16* end;SQL> /

    Function created.

    SQL> declare

    2 a number(5);

    3 b number(5);4 begin

    5 a:=&accno;6 b:=acc_detailfun(a);7 dbms_output.put_line('possible withdraw amt is'||b);

    8 end;

    9 /

  • 8/3/2019 DBMS lab AL MCA

    46/72

    Enter value for accno: 112

    old 5: a:=&accno;new 5: a:=112;

    possible withdraw amt is2000

    PL/SQL procedure successfully completed.

    RESULT:

    Thus the above program was executed and verified.

  • 8/3/2019 DBMS lab AL MCA

    47/72

    EX.NO:6 EMBEDDED SQL

    DATE:

    import java.sql.*;

    class Emp{

    public static void main(String args[]){

    try

    {

    Class.forName("sun.jdbc.odbc.jdbcOdbcDriver");

    Connection con =DriverManager.getConnection("jdbc:odbc:emp","k6500","k6500");

    Statement stmt=con.CreateStatement();

    ResultSet rs=stmt.execute Query("select * from emp1");while(rs.next())

    {

    System.out.print("Employee No = " + rs.getInt (1) );System.out.print("Employee Name = " + rs.getString (2) );

    System.out.print(Salary = " + rs.getInt (3) );

    System.out.print("\n");

    }stmt.close();

    con.close();

    }

    catch (java.lang.Exception ex)

    {

    System.out.println("Error:"+ex);}

    }}

    OUTPUT:

    To Compile:

    Z:\> set path = z:\jdk1.3\bin;

    Z:\> javac emp.java

    To Run:Z:\> java empEmployee No=11 Employee Name =a Salary= 6500.5

    Employee No=12 Employee Name =b Salary= 4500

    Employee No=13 Employee Name =c Salary= 10000

  • 8/3/2019 DBMS lab AL MCA

    48/72

    SQL> select * from employees;

    NO NAME DEPTNO SALARY JOB COMM

    --------- ------------------------- --------- --------- ---------- ---------

    11 a 101 6500.5 clerk 1012 b 101 4500 tech 10

    13 c 110 10000 manager 50

    RESULT:

    Thus the above program was executed and verified.

  • 8/3/2019 DBMS lab AL MCA

    49/72

    EX.NO:7 DATABASE DESIGN USING E-R MODEL ANDDATE: NORMALIZATION

    TABLE EPROJECT IN FIRST NORMAL FORM NOT IN SECOND NORMAL

    FORM

    SQL> create table eproject(ssn number(5) primary key, pnumber number(3),hours

    number(5), ename varchar(10), pname varchar(10), plocation varchar(10));

    Table created.

    SQL>desc eproject;

    Name Null? Type

    ------------------------------- -------- ----

    SSN NOT NULL NUMBER(5)PNUMBER NUMBER(3)

    HOURS NUMBER(5)

    ENAME VARCHAR2(10)

    PNAME VARCHAR2(10)PLOCATION VARCHAR2(10)

    SQL>insert into eproject values(&ssn, &pnumber, &hours, &ename, &pname,&plocation);

    SQL>select * from eproject;

    SQL> select * from eproject;

    SSN PNUMBER HOURS ENAME PNAME PLOCATION

    --------- --------- --------- ---------- ---------- ----------

    111 100 3 Raj WAP1X Dehradun

    112 101 4 Kavitha SAP1X Varanasi113 110 5 Manish SAP1X Varanasi

    NORMALIZING EPROJECT INTO SECOND NORMAL FORM

    SQL>create table eproject1(ssn number(5) primary key, pnumber number(5), hours

    number(5));

    Table created.

  • 8/3/2019 DBMS lab AL MCA

    50/72

    SQL>desc eproject1;

    Name Null? Type

    ------------------------- ------ -------- ----

    SSN NOT NULL NUMBER(5)PNUMBER NUMBER(5)

    HOURS NUMBER(5)

    SQL>insert into eproject1 values(&ssn,&pnumber,&hours);

    SQL>select * from eproject1;

    SSN PNUMBER HOURS

    --------- --------- ---------

    111 100 3112 101 4

    113 110 5

    SQL>create table eproject2(ssn number(5) primary key, ename varchar(10));

    Table created.

    SQL>desc eproject2;

    Name Null? Type

    ------------------------------- -------- ----

    SSN NOT NULL NUMBER(5)

    ENAME VARCHAR2(10)

    SQL>insert into eproject2 values(&ssn,&ename);

    SQL>select * from eproject2;

    SSN ENAME

    ----- ----------

    111 Raj112 Kavitha

    113 Manish

    SQL>create table eproject3(pnumber number(5) primary key,pname

    varchar(10),plocation varchar(10));

    Table created.

    SQL>desc eproject3;

  • 8/3/2019 DBMS lab AL MCA

    51/72

    Name Null? Type----------------------- -------- -------- ----

    PNUMBER NOT NULL NUMBER(5)

    PNAME VARCHAR2(10)PLOCATION VARCHAR2(10)

    SQL>insert into eproject3 values(&pnumber,&pname,&plocation);

    SQL>select * from eproject3;

    PNUMBER PNAME PLOCATION

    -------- ---------- ----------

    100 WAP1X Dehradun101 SAP1X Varanasi

    110 WAP1X Dehradun

    TABLE EDEPT IN FIRST NORMAL FORM NOT IN THIRD NORMAL FORM

    SQL>create table edept(ename varchar(10),ssn number(5),address varchar(10),dno

    number(5), dname varchar(10),dmgrssn number(5));

    Table created.

    SQL>desc edept;

    Name Null? Type

    ------------------------------- -------- ----ENAME VARCHAR2(10)

    SSN NUMBER(5)

    ADDRESS VARCHAR2(10)

    DNO NUMBER(5)DNAME VARCHAR2(10)

    DMGRSSN NUMBER(5)

    SQL>insert into edept values (&ename,&ssn,&address,&dno,&dname, &dmgrssn);

  • 8/3/2019 DBMS lab AL MCA

    52/72

    SQL> select * from edept;

    ENAME SSN ADDRESS DNO DNAME DMGRSSN

    ---------- --------- ---------- --------- ---------- ---------Raj 111 Northst 900 EDP 200

    Kavitha 112 Souhtst 901 MAT 201Manish 113 Westst 902 IT 202

    NORMALIZING EDEPT INTO THIRD NORMAL FORM

    SQL>create table edept1(ename varchar(10),ssn number primary key,address

    varchar(10),dno number(5));

    Table created.

    SQL>desc edept1;

    Name Null? Type

    -------------------- ----------- -------- ----

    ENAME VARCHAR2(10)SSN NOT NULL NUMBER

    ADDRESS VARCHAR2(10)

    DNO NUMBER(5)

    SQL>insert into edept1 values(&ename,&ssn,&address,&dno);

    ENAME SSN ADDRESS DNO---------- - -------- ---------- ---------

    Raj 111 Northst 900Kavitha 112 Southst 901

    Manish 113 Westst 902

    SQL>select * from edept1;

    SQL>create table edept2(dno number(5)primary key,dname varchar(20),dmgrssn

    number(5));

    Table created.

    SQL>desc edept2;

    Name Null? Type

    ----------------------- -------- -------- ----DNO NOT NULL NUMBER(5)

    DNAME VARCHAR2(20)

  • 8/3/2019 DBMS lab AL MCA

    53/72

    DMGRSSN NUMBER(5)

    SQL>insert into edept2 values(&dno, &dname, &dmgrssn);

    SQL>select * from edept2;

    DNO DNAME DMGRSSN---- -------------------- ---------900 EDP 200

    901 MAT 201

    902 IT 202

    RESULT:

    Thus the above program was executed and verified.

  • 8/3/2019 DBMS lab AL MCA

    54/72

    EX.NO:8 DESIGN & IMPLEMENTATION OF PAYROLL PROCESSING

    DATE : SYSTEM

    SQL> create table payroll( name varchar(20), no number(10), des varchar(10), dept

    varchar(10), basicpay number(10,3), da number(10,3), hra number (10,3), pfnumber(10,3), grosspay number(10,3), netpay number(10,3));

    SQL> desc payroll;

    Name Null? Type------------------------------- -------- ----

    NAME VARCHAR2(20)

    NO NUMBER(10)DES VARCHAR2(10)

    DEPT VARCHAR2(10)

    BASICPAY NUMBER(10,3)DA NUMBER(10,3)

    HRA NUMBER(10,3)

    PF NUMBER(10,3)

    GROSSPAY NUMBER(10,3)NETPAY NUMBER(10,3)

    Form name: Payroll SystemCanvas name: Canvas2

    Type: Trigger

    Function name: when_mouse_click

    PL/SQL CODING:

    Move to the First record:

    FIRST_RECORD;

    COMMIT;

    Move to the Last record:

    LAST_RECORD;

    COMMIT;

    Move to the Next record:

    NEXT_RECORD;

    COMMIT;

    Move to the Previous record:

  • 8/3/2019 DBMS lab AL MCA

    55/72

    PREVIOUS_RECORD;COMMIT;

    Execute Record:

    EXECUTE_QUERY(ALL_RECORDS);COMMIT;

    Save a record:

    BEGINCOMMIT;

    NEXT_RECORD;

    END;

    Delete a record:

    DELETE_RECORD;

    COMMIT;

    Clear the Form:

    CLEAR_FORM(DO_COMMIT);

    To Exit:

    EXIT_FORM;

    Calculate:

    BEGIN

    IF :BASICPAY >= 10000 THEN

    :DA := 0.5 * :BASICPAY;

    :HRA := 0.1 * :BASICPAY;

    ELSIF :BASICPAY < 1000 AND :BASICPAY >= 5000 THEN

    :DA := 0.4 * :BASICPAY;:HRA := 0.1 * :BASICPAY;

    ELSE

    :DA := 0.2 * :BASICPAY;

    :HRA := 0.1 * :BASICPAY;

  • 8/3/2019 DBMS lab AL MCA

    56/72

    END IF;

    :PF := 0.2 * :BASICPAY;

    :GROSSPAY := :BASICPAY + :DA + :HRA;:NETPAY := :GROSSPAY - :PF;

    END;

    SQL> select * from payroll;

    NAME NO DES DEPT BASICPAY DA HRA

    -------- ---------- ---------- --------- --------- --------- ---------

    MSS 113 PA EDP 500 100 50

    SIVA 112 CLERK EDP 5000 1000 500

    GANGA 111 MANAGER OFFICE 10000 5000 1000

    PF GROSSPAY NETPAY---- ----------- ----------

    100 650 550

    1000 6500 55002000 16000 14000

  • 8/3/2019 DBMS lab AL MCA

    57/72

    PAYROLL PROCESSING SYSTEM - DESIGN AND OUTPUT

  • 8/3/2019 DBMS lab AL MCA

    58/72

    RESULT:

    Thus the above program was executed and verified.

  • 8/3/2019 DBMS lab AL MCA

    59/72

    EX.NO: 9 DESIGN & IMPLEMENTATION OF BANKING

    DATE : SYSTEMS

    SQL> create table accounts(Acno number(5),CustomerName varchar(25),Branchvarchar(25),City varchar(25),Balance number(10,2),Amount number(10,2));

    Table created.

    SQL> desc accounts;

    Name Null? Type

    ------------------------------- -------- ----

    ACNO NUMBER(5)CUSTOMERNAME VARCHAR2(25)

    BRANCH VARCHAR2(25)

    CITY VARCHAR2(25)BALANCE NUMBER(10,2)

    AMOUNT NUMBER(10,2)

    Form name: Account Details

    Canvas name: Canvas2

    Type: Trigger Function name: when_mouse_click

    PL/SQL CODING:

    Move to the First record:

    FIRST_RECORD;

    COMMIT;

    Move to the Last record:

    LAST_RECORD;

    COMMIT;

    Move to the Next record:

    NEXT_RECORD;

    COMMIT;

    Move to the Previous record:

    PREVIOUS_RECORD;

  • 8/3/2019 DBMS lab AL MCA

    60/72

    COMMIT;

    Execute Record:

    EXECUTE_QUERY (ALL_RECORDS);COMMIT;

    Save a record:

    BEGIN

    COMMIT;

    NEXT_RECORD;END;

    Delete a record:

    DELETE_RECORD;COMMIT;

    Clear the Form:

    CLEAR_FORM (DO_COMMIT);

    To Exit:

    EXIT_FORM;

    Deposit:

    BEGIN

    IF :AMOUNT > 0 AND :BALANCE > 0 THEN

    :BALANCE := :BALANCE + :AMOUNT;

    END IF;

    END;

    WithDraw:

    BEGIN

    IF :AMOUNT > 0 AND :BALANCE > 0 THEN

    :BALANCE := :BALANCE - :AMOUNT;

  • 8/3/2019 DBMS lab AL MCA

    61/72

    END IF;

    END;

    SQL> select * from accounts;

    ACNO CUSTOMERNAME BRANCH CITY

    --------- ------------------------- ------------------ -----------

    101 SIVA SRIRANGAM TRICHY

    102 PREM BHEL TRICHY

    BALANCE AMOUNT

    ------------- ------------

    4900 100

    6000 1000

  • 8/3/2019 DBMS lab AL MCA

    62/72

    BANKING SYSTEMS - DESIGN AND OUTPUT

    Result:

    Thus the program was verified successfully verified and executed.

  • 8/3/2019 DBMS lab AL MCA

    63/72

    EX.NO:10 DESIGN & IMPLEMENTATION OF LIBRARY

    DATE: INFORMATION SYSTEM.

    SQL> create table library(Bookno number(5),Bookname varchar(25),Authornamevarchar(25),Price number(4),Publication varchar(25),Edition number(5),EntryDate

    date,Returndate date,Duedate date,Fine number(4));

    Table created.

    SQL>desc library;

    Name Null? Type

    ------------------------------- -------- ----

    BOOKNO NUMBER(5)BOOKNAME VARCHAR2(25)

    AUTHORNAME VARCHAR2(25)

    PRICE NUMBER(4)PUBLICATION VARCHAR2(25)

    EDITION NUMBER(5)

    ENTRYDATE DATE

    RETURNDATE DATEDUEDATE DATE

    FINE NUMBER(4)

    Form name: Library Details

    Canvas name: Canvas2

    Type: Trigger Function name: when_mouse_click

    PL/SQL CODING:

    Move to the First record:

    FIRST_RECORD;

    COMMIT;

    Move to the Last record:

    LAST_RECORD;COMMIT;

    Move to the Next record:

    NEXT_RECORD;

    COMMIT;

  • 8/3/2019 DBMS lab AL MCA

    64/72

    Move to the Previous record:

    PREVIOUS_RECORD;

    COMMIT;

    Execute Record:

    EXECUTE_QUERY (ALL_RECORDS);

    COMMIT;

    Save a record:

    BEGIN

    COMMIT;NEXT_RECORD;

    END;

    Delete a record:

    DELETE_RECORD;COMMIT;

    Clear the Form:

    CLEAR_FORM (DO_COMMIT);

    To Exit:

    EXIT_FORM;

    Calculate:

    BEGIN

    :DUEDATE := :ENTRYDATE + 30;

    IF :DUEDATE < :RETURNDATE THEN:FINE := ( :RETURNDATE - :DUEDATE ) * 3;

    END IF;END;LIBRARY INFORMATION SYSTEM - DESIGN AND OUTPUT

  • 8/3/2019 DBMS lab AL MCA

    65/72

    RESULT:

    Thus the above program was executed and verified.

  • 8/3/2019 DBMS lab AL MCA

    66/72

    VIVA QUESTIONS

    1. Define database management system?Database management system (DBMS) is a collection of interrelateddata and aset of programs to access those data.

    2. List any eight applications of DBMS.a) Bankingb) Airlinesc) Universitiesd) Credit card transactionse) Tele communicationf) Financeg) Salesh) Manufacturingi) Human resources3. What are the disadvantages of file processing system?

    The disadvantages of file processing systems area) Data redundancy and inconsistencyb) Difficulty in accessing datac) Data isolationd) Integrity problemse) Atomicity problemsf) Concurrent access anomalies4. What are the advantages of using a DBMS?The advantages of using a DBMS area) Controlling redundancyb) Restricting unauthorized access

    c) Providing multiple user interfacesd) Enforcing integrity constraints.e) Providing back up and recovery5. Give the levels of data abstraction?a) Physical levelb) logical levelc) view level6. Define instance and schema?Instance: Collection of data stored in the data base at a particularmoment iscalled an Instance of the database.Schema:The overall design of the data base is called the data baseschema.7. Define the terms 1) physical schema 2) logical schema.Physical schema:The physical schema describes the databasedesign at thephysical level, which is the lowest level of abstraction describing howthe data are

  • 8/3/2019 DBMS lab AL MCA

    67/72

    actually stored.Logical schema:The logical schema describes the database designat the logicallevel, which describes what data are stored in the database and whatrelationship existsamong the data.

    8. What is conceptual schema?The schemas at the view level are called subschemas that describedifferent viewsof the database.9. Define data model?A data model is a collection of conceptual tools for describing data,datarelationships, data semantics and consistency constraints.10. What is storage manager?A storage manager is a program module that provides the interfacebetween the

    low level data stored in a database and the application programs andqueries submitted tothe system.11. What is the use of group by clause?Group by clause is used to apply aggregate functions to a set oftuples.Theattributes given in the group by clause are used to formgroups.Tuples with thesame value on all attributes in the group by clause are placed in onegroup.12. What is the use of sub queries?

    A sub query is a select-from-where expression that is nested with inanotherquery. A common use of sub queries is to perform tests for setmembership, makesetcomparisions, and determine set cardinality.13. What is view in SQL? How is it defined?Any relation that is not part of the logical model, but is made visible toa user as avirtual relation is called a view.We define view in SQL by using the create view command. The formof thecreate view command isCreate view v as 14. What is the use of with clause in SQL?The with clause provides a way of defining a temporary view whosedefinition isavailable only to the query in which the with clause occurs.15. List the table modification commands in SQL?

  • 8/3/2019 DBMS lab AL MCA

    68/72

    _ Deletion_ Insertion_ Updates_ Update of a view16. List out the statements associated with a databasetransaction?

    _ Commit work_ Rollback work17. What is transaction?Transaction is a unit of program execution that accesses and possiblyupdatedvarious data items.18. List the SQL domain Types?SQL supports the following domain types.1) Char(n) 2) varchar(n) 3) int 4) numeric(p,d)5) float(n) 6) date.19. What is the use of integrity constraints?

    Integrity constraints ensure that changes made to the database byauthorized usersdo not result in a loss of data consistency. Thus integrity constraintsguard againstaccidental damage to the database.20. Mention the 2 forms of integrity constraints in ER model?_ Key declarations_ Form of a relationshipWhat are the factors to be taken into account when choosing aRAID level?o Monetary cost of extra disk storage requirements.o Performance requirements in terms of number of I/O operationso Performance when a disk has failed.o Performances during rebuild.22. What is meant by software and hardware RAID systems?RAID can be implemented with no change at the hardware level, usingonlysoftware modification. Such RAID implementations are called softwareRAID systemsand the systems with special hardware support are called hardwareRAID systems.23. Define hot swapping?Hot swapping permits the removal of faulty disks and replaces it bynew oneswithout turning power off. Hot swapping reduces the mean time torepair.24. What are the ways in which the variable-length recordsarise in databasesystems?

  • 8/3/2019 DBMS lab AL MCA

    69/72

    _ Storage of multiple record types in a file._ Record types that allow variable lengths for one or more fields._ Record types that allow repeating fields.25. What is the use of a slotted-page structure and what is theinformation presentin the header?

    The slotted-page structure is used for organizing records within asingle block.The header contains the following information._The number of record entries in the header._The end of free space_An array whose entries contain the location and size of each record.26. What are the two types of blocks in the fixed lengthrepresentation? Definethem. Anchor block: Contains the first record of a chain. Overflow block: Contains the records other than those that are thefirstrecord of a chain.27. What is known as heap file organization?In the heap file organization, any record can be placed anywhere in thefile wherethere is space for the record. There is no ordering of records. There is asingle file foreach relation.28. What is known as sequential file organization?In the sequential file organization, the records are stored in sequentialorder,according to the value of a search key of each record.29. What is hashing file organization?In the hashing file organization, a hash function is computed on someattribute ofeach record. The result of the hash function specifies in which block ofthe file the recordshould be placed.30. What is known as clustering file organization?In the clustering file organization, records of several different relationsare stored

    in the same file.

    31. What is transaction?Collections of operations that form a single logical unit of work arecalledtransactions.32. What are the two statements regarding transaction?The two statements regarding transaction of the form:

  • 8/3/2019 DBMS lab AL MCA

    70/72

    _ Begin transaction_ End transaction33. What are the properties of transaction?The properties of transactions are:_ Atomicity_ Consistency

    _ Isolation_ Durability34. What is recovery management component?Ensuring durability is the responsibility of a software component of thebasesystem called the recovery management component.35. When is a transaction rolled back?Any changes that the aborted transaction made to the database mustbe undone.Once the changes caused by an aborted transaction have beenundone, then the

    transaction has been rolled back.36. What are the states of transaction?The states of transaction are_ Active_ Partially committed_ Failed_ Aborted_ Committed_ Terminated37. What is a shadow copy scheme?It is simple, but efficient, scheme called the shadow copy schemes. It is

    based onmaking copies of the database called shadow copies that onetransaction is active at atime. The scheme also assumes that the database is simply a file ondisk.38. Give the reasons for allowing concurrency?The reasons for allowing concurrency is if the transactions run serially,a shorttransaction may have to wait for a preceding long transaction tocomplete, which can leadto unpredictable delays in running a transaction.So concurrent execution reduces the unpredictable delays in runningtransactions.39. What is average response time?The average response time is that the average time for a transactionto becompleted after it has been submitted.40. What are the two types of serializability?

  • 8/3/2019 DBMS lab AL MCA

    71/72

    The two types of serializability is_ Conflict serializability_ View serializability41.What is meant by object-oriented data model?The object-oriented paradigm is based on encapsulation of data andcode related

    to an object in to a single unit, whose contents are not visible to theoutside world.42. What is the major advantage of object-orientedprogramming paradigm?The ability to modify the definition of an object without affecting therest of thesystem is the major advantage of object-oriented programmingparadigm.43. What are the methods used in object-orientedprogramming paradigm?*read-only

    *update44. What is the main difference between read-only and updatemethods?A read-only method does not affect the values of a variable in anobject, whereasan update method may change the values of the variables.45. What is the use of keyword ISA?The use of keyword ISA is to indicate that a class is a specialization ofanotherclass.46. Differentiate sub-class and super-class?

    The specialization of a class is called subclasses.eg: employee is asubclass ofperson and teller is a subclass of employee.Conversely, employee is asuper classof teller, and person is a super class of employee.47. What is substitutability?Any method of a class-say A can equally well be invoked with anyobjectbelonging to any subclasses B of A. This characteristic leads to codereuse, sincethe messages, methods, and functions do not have to be written againfor objectsof class B.48. What is multiple inheritance?Multiple inheritance permits a class to inherit variables and methodsfrommultiple super classes.49. What is DAG?

  • 8/3/2019 DBMS lab AL MCA

    72/72

    The class-subclass relationship is represented by a directed acyclicgraph.eg:employees can be temporary or permanenet.we may create subclassestemporaryand permanenet, of the class employee.50. What is disadvantage of multiple inheritance?

    There is potential ambiguity if the same variable or method can beinherited frommore than one superclass.eg: student class may have a variable deptidentifying astudent's department, and the teacher class may correspondingly havea variabledept identifying a teacher's department.