Sei sulla pagina 1di 93

SaIT ISE

CONTENTS SHEET

SL
No. TITLE PAGE NO.

1) INSURANCE DATABASE 3

2) ORDER PROCESSING DATABASE 46

3) STUDENT DATABASE 58

4) BOOK DEALER DATABASE 70

5) BANKING DATABASE 82

DBMS Lab Mannual 1


Dept of ISE SaIT

INSURANCE
DATABASE

DBMS Lab Mannual 2


Dept of ISE SaIT

1. Consider the Insurance database given below. The primary keys are underlined and the
data types are specified:
PERSON(driver-id:string,name:string,address:string)
CAR(Regno:string,model:string,year:int)
ACCIDINT(report-number:int,date:date,location:string)
OWNS(driver-id:string,regno:string)
PARTICIPATED(driver-id:string,regno:string,report-number:int,damage-amount:int)

1) create the above tables by properly specifying the primary keys and the foreign keys
2) Enter atleast five tuples for each relation
3) Demonstrate how you
a) update the damage amount for the car with a specific regno in accident with
report number 12 to 25000
b) add a new accident to the database
4) Find the total number of people who owned cars that were involved in accidents in
2002.
5) Find the number of accidents in which cars belonging to a specific model were
Involved.
6) Generation of suitable reports
7) Create suitable front end for querying and display the results

SQL> create table Person(


Driverid varchar(15),
Name varchar(15) not null,
Address varchar(20),
primary key (Driverid));

Table created.

SQL> create table Car(


Regno varchar(9),
Model varchar(15) not null,
Year integer not null,
primary key (Regno));

Table created.

SQL> create table Accident(


Reportno integer,
Accdate date not null,
Location varchar(15) not null,

DBMS Lab Mannual 3


Dept of ISE SaIT

primary key (Reportno));

Table created.

SQL> create table Owns(


Driverid varchar(15),
Regno varchar(9),
primary key (Driverid,Regno),
foreign key (Driverid) references Person(Driverid),
foreign key (Regno) references Car(Regno));

Table created.

SQL> create table Participated(


Driverid varchar(15),
Regno varchar(9),
Reportno integer,
Damageamount integer,
primary key (Driverid,Regno,Reportno),
foreign key (Driverid) references Person(Driverid),
foreign key (Regno) references Car(Regno),
foreign key (Reportno) references Accident(Reportno));

Table created.

SQL> desc Person;


Name Null? Type
----------------------------------------- -------- ----------------------------
DRIVERID NOT NULL VARCHAR2(15)
NAME NOT NULL VARCHAR2(15)
ADDRESS VARCHAR2(20)

SQL> insert into Person values('1111','Ramu','Jayanagar');

1 row created.

SQL> insert into Person values('2222','Manu','Rajajinagar');

1 row created.

SQL> insert into Person values('3333','Pandit','Indiranagar');

1 row created.

SQL> insert into Person values('4444','Gopal','BTMLayout');

DBMS Lab Mannual 4


Dept of ISE SaIT

1 row created.

SQL> insert into Person values('5555','Lalit','Whitefield');

1 row created.

SQL> select * from Person;

DRIVERID NAME ADDRESS


--------------- --------------- --------------------
1111 Ramu Jayanagar
2222 Manu Rajajinagar
3333 Pandit Indiranagar
4444 Gopal BTMLayout
5555 Lalit Whitefield

SQL> desc Car;


Name Null? Type
----------------------------------------- -------- ----------------------------
REGNO NOT NULL VARCHAR2(9)
MODEL NOT NULL VARCHAR2(15)
YEAR NOT NULL NUMBER(38)

SQL> insert into Car values('KA04Q2301','Maruthi',2000);

1 row created.

SQL> insert into Car values('KA05P1000','Ford',2002);

1 row created.

SQL> insert into Car values('KA03L1234','Honda',1999);

1 row created.

SQL> insert into Car values('KA03L9999','Tata',2002);

1 row created.

SQL> insert into Car values('KA01P4026','Toyota',2003);

1 row created.

SQL> select * from Car;

REGNO MODEL YEAR

DBMS Lab Mannual 5


Dept of ISE SaIT

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


KA04Q2301 Maruthi 2000
KA05P1000 Ford 2002
KA03L1234 Honda 1999
KA03L9999 Tata 2002
KA01P4026 Toyota 2003

SQL> desc Owns;


Name Null? Type
----------------------------------------- -------- ----------------------------
DRIVERID NOT NULL VARCHAR2(15)
REGNO NOT NULL VARCHAR2(9)

SQL> insert into Owns values('1111','KA04Q2301');

1 row created.

SQL> insert into Owns values('2222','KA05P1000');

1 row created.

SQL> insert into Owns values('3333','KA03L1234');

1 row created.

SQL> insert into Owns values('4444','KA03L9999');

1 row created.

SQL> insert into Owns values('5555','KA01P4026');

1 row created.

SQL> select * from Owns;

DRIVERID REGNO
--------------- ---------
1111 KA04Q2301
2222 KA05P1000
3333 KA03L1234
4444 KA03L9999
5555 KA01P4026

SQL> desc Accident;


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

DBMS Lab Mannual 6


Dept of ISE SaIT

REPORTNO NOT NULL NUMBER(38)


ACCDATE NOT NULL DATE
LOCATION NOT NULL VARCHAR2(15)

SQL> insert into Accident values(12,'01-Jun-2001','Jayanagar');

1 row created.

SQL> insert into Accident values(25,'02-Jul-2002','AvenueRoad');

1 row created.

SQL> insert into Accident values(512,'08-Mar-2000','MGRoad');

1 row created.

SQL> insert into Accident values(1024,'25-Oct-2002','BrigadeRoad');

1 row created.

SQL> insert into Accident values(1000,'23-Dec-2003','RichmondCircle');

1 row created.

SQL> select * from Accident;

REPORTNO ACCDATE LOCATION


---------- --------- ---------------
12 01-JUN-01 Jayanagar
25 02-JUL-02 AvenueRoad
512 08-MAR-00 MGRoad
1024 25-OCT-02 BrigadeRoad
1000 23-DEC-03 RichmondCircle

SQL> desc participated;


Name Null? Type
----------------------------------------- -------- ----------------------------
DRIVERID NOT NULL VARCHAR2(15)
REGNO NOT NULL VARCHAR2(9)
REPORTNO NOT NULL NUMBER(38)
DAMAGEAMOUNT NUMBER(38)

SQL> insert into Participated values('1111','KA04Q2301',12,2000);

1 row created.

DBMS Lab Mannual 7


Dept of ISE SaIT

SQL> insert into Participated values('2222','KA05P1000',25,15000);

1 row created.

SQL> insert into Participated values('3333','KA03L1234',512,15500);

1 row created.

SQL> insert into Participated values('4444','KA03L9999',1024,20000);

1 row created.

SQL> insert into Participated values('5555','KA01P4026',1000,5000);

1 row created.

SQL> select * from Participated;

DRIVERID REGNO REPORTNO DAMAGEAMOUNT


--------------- --------- ---------- ------------
1111 KA04Q2301 12 2000
2222 KA05P1000 25 15000
3333 KA03L1234 512 15500
4444 KA03L9999 1024 20000
5555 KA01P4026 1000 5000

***** 1st query *****

BEFORE:

SQL> select * from Participated;

DRIVERID REGNO REPORTNO DAMAGEAMOUNT


--------------- --------- ---------- ------------
1111 KA04Q2301 12 2000
2222 KA05P1000 25 15000
3333 KA03L1234 512 15500
4444 KA03L9999 1024 20000
5555 KA01P4026 1000 5000

SQL> update Participated


2 set Damageamount=25000
3 where Regno='KA04Q2301' and Reportno=12;

1 row updated.

DBMS Lab Mannual 8


Dept of ISE SaIT

AFTER:

SQL> select * from Participated;

DRIVERID REGNO REPORTNO DAMAGEAMOUNT


--------------- --------- ---------- ------------
1111 KA04Q2301 12 25000
2222 KA05P1000 25 15000
3333 KA03L1234 512 15500
4444 KA03L9999 1024 20000
5555 KA01P4026 1000 5000

***** 2nd query *****

SQL> insert into Person values('6666','Bunty','Jayanagar');

1 row created.

SQL> select * from person;

DRIVERID NAME ADDRESS


--------------- --------------- --------------------
1111 Ramu Jayanagar
2222 Manu Rajajinagar
3333 Pandit Indiranagar
4444 Gopal BTMLayout
5555 Lalit Whitefield
6666 Bunty Jayanagar

6 rows selected.

SQL> insert into Car values('KA052005','BMW',2005);

1 row created.

SQL> select * from car;

REGNO MODEL YEAR


--------- --------------- ----------
KA04Q2301 Maruthi 2000
KA05P1000 Ford 2002
KA03L1234 Honda 1999
KA03L9999 Tata 2002
KA01P4026 Toyota 2003
KA052005 BMW 2005

DBMS Lab Mannual 9


Dept of ISE SaIT

6 rows selected.

SQL> insert into owns values('6666','KA052005');

1 row created.

SQL> select * from owns;

DRIVERID REGNO
--------------- ---------
1111 KA04Q2301
2222 KA05P1000
3333 KA03L1234
4444 KA03L9999
5555 KA01P4026
6666 KA052005

6 rows selected.

SQL> insert into accident values(420,'30-Jan-2005','MGroad');

1 row created.

SQL> select * from accident;

REPORTNO ACCDATE LOCATION


---------- --------- ---------------
12 01-JUN-01 Jayanagar
25 02-JUL-02 AvenueRoad
512 08-MAR-00 MGRoad
1024 25-OCT-02 BrigadeRoad
1000 23-DEC-03 RichmondCircle
420 30-JAN-05 MGroad

6 rows selected.

SQL> insert into participated values('6666','KA052005',420,25000);

1 row created.

SQL> select * from participated;

DRIVERID REGNO REPORTNO DAMAGEAMOUNT


--------------- --------- ---------- ------------
1111 KA04Q2301 12 25000

DBMS Lab Mannual 10


Dept of ISE SaIT

2222 KA05P1000 25 15000


3333 KA03L1234 512 15500
4444 KA03L9999 1024 20000
5555 KA01P4026 1000 5000
6666 KA052005 420 25000

6 rows selected.

***** 3rd query *****

SQL> select count(*) from Accident where Accdate like '__-___-02';

COUNT(*)
----------
2

***** 4th query *****

SQL> select count(*) from Car C,Participated P


2 where C.Regno=P.Regno and C.Model='Ford';

COUNT(*)
----------
1

DBMS Lab Mannual 11


Dept of ISE SaIT

PERSON FORM

DBMS Lab Mannual 12


Dept of ISE SaIT

DECLARATION

Dim rptcon As ADODB.Connection


Dim rs As New ADODB.Recordset
Dim rs1 As New ADODB.Recordset
Dim check As String

COMMAND BUTTONS

CANCEL BUTTON
Private Sub cmdcancel_Click()
txtname = ""
txtaddr = ""
End Sub

DELETE BUTTON
Private Sub cmddelete_Click()

Dim VBYES As String


VBYES = MsgBox("DO YOU WANT TO DELETE THE SELECTED RECORD",
vbYesNo)
If VBYES = "6" Then
checkchild
If check = False Then
db.BeginTrans
sql = "DELETE FROM person WHERE driverid= " & txtdr_id & ""
db.Execute sql
db.CommitTrans
refreshrecord
clear
MsgBox "RECORD DELETED"
End If
Else
Exit Sub
End If
End Sub

Private Sub checkchild()


Dim rec As New ADODB.Recordset
sql = "select * from owns where driverid='" & txtdr_id & "'"
rec.Open sql, db, adOpenStatic, adLockReadOnly

DBMS Lab Mannual 13


Dept of ISE SaIT

If Not rec.EOF Then


MsgBox "child record found not possible to delete"
check = True
Exit Sub
Else
check = False
End If
End Sub

EXIT BUTTON
Private Sub cmdexit_Click()
Unload Me
End Sub

SAVE BUTTON
Private Sub cmdsave_Click()
checkdata
If check = False Then
db.BeginTrans
sql = "insert into person values("
sql = sql & txtdr_id & ""
sql = sql & ",'" & txtname & "'"
sql = sql & ",'" & txtaddr & "'"
sql = sql & ")"
db.Execute sql
db.CommitTrans
refreshrecord
clear
MsgBox "RECORD SUCCESSFULLY INSERTED"
End If
End Sub

NEW BUTTON
Private Sub cmdnew_Click()
Dim dr_id As Integer
clear
txtdr_id = getrecordno("person", "driverid")
End Sub

FUNCTION TO AUTO GENERATE DRIVER_ID


Private Function getrecordno(tlb As String, recordno As String)
Dim rs As New ADODB.Recordset
sql = "select * from " & tlb & " order by " & recordno & " desc"
rs.Open sql, db, adOpenStatic, adLockReadOnly
If Not rs.EOF Then
rs.MoveFirst

DBMS Lab Mannual 14


Dept of ISE SaIT

recordno = rs!driverid + 1
getrecordno = recordno
Else
recordno = 1
getrecordno = recordno
End If
End Function

RECORD NAVIGATION BUTTONS

MOVE NEXT BUTTON


Private Sub cmdnext_Click()
If rs1.BOF Then
rs1.MoveNext
End If
txtdr_id = rs1!driverid
txtname = rs1!Name
txtaddr = rs1!address
rs1.MoveNext

If rs1.EOF Then
cmdnext.Enabled = False
cmdprev.Enabled = True
Exit Sub
End If
End Sub

MOVE PREVIOUS BUTTON


Private Sub cmdprev_Click()
rs1.MovePrevious
If rs1.BOF Then
cmdprev.Enabled = False
cmdnext.Enabled = True
Exit Sub
End If
txtdr_id = rs1!driverid
txtname = rs1!Name
txtaddr = rs1!address
cmdnext.Enabled = True
End Sub

MOVE LAST BUTTON


Private Sub cmdlast_Click()
rs1.MoveLast
txtdr_id = rs1!driverid
txtname = rs1!Name

DBMS Lab Mannual 15


Dept of ISE SaIT

txtaddr = rs1!address
cmdnext.Enabled = False
cmdfirst.Enabled = True
cmdprev.Enabled = True
End Sub

MOVE FIRST BUTTON


Private Sub cmdfirst_Click()
rs1.MoveFirst
txtdr_id = rs1!driverid
txtname = rs1!Name
txtaddr = rs1!address
cmdfirst.Enabled = False
cmdprev.Enabled = False
cmdnext.Enabled = True
cmdlast.Enabled = True
End Sub

DATAGRID FOR RECORD SELECTION


Private Sub DataGrid1_Click()
On Error GoTo errorhandler
txtdr_id.Text = DataGrid1.Columns(0).Text
txtname.Text = DataGrid1.Columns(1).Text
txtaddr.Text = DataGrid1.Columns(2).Text
errorhandler:
If Err.Number = "6160" Then
MsgBox "no record to select"
End If
End Sub

FORM LOAD SUB FUNCTION


Private Sub Form_Load()
sql = "select * from person"
rs1.Open sql, db, adOpenStatic, adLockReadOnly
End Sub

REFRESH- DATAGRID
Private Sub refreshrecord()
sql = "select * from person"
Adodc2.RecordSource = sql
Adodc2.Refresh
End Sub

Private Sub clear()


txtdr_id = ""
txtname = ""

DBMS Lab Mannual 16


Dept of ISE SaIT

txtaddr = ""
End Sub

FIELD VALIDATION
Private Sub checkdata()
If txtdr_id = "" Then
MsgBox "PLEASE ENTER THE DRIVER ID"
check = True
txtdr_id.SetFocus
Exit Sub
Else
check = False
End If

If txtname = "" Then


MsgBox "PLEASE ENTER THE NAME OF THE PERSON"
check = True
txtname.SetFocus
Exit Sub
Else
check = False
End If

If txtaddr = "" Then


MsgBox "PLEASE ENTER THE ADDRESS"
check = True
txtaddr.SetFocus
Exit Sub
Else
check = False
End If
End Sub

MENU
Private Sub mnuaccidentdetails_Click()
frmaccident.Show
End Sub

Private Sub mnucardetails_Click()


frmcar.Show
End Sub

Private Sub mnucarrpt_Click()


Set rs = db.Execute("select * from car")
Set carsrpt.DataSource = rs

DBMS Lab Mannual 17


Dept of ISE SaIT

carsrpt.Show
End Sub

Private Sub mnuowns_Click()


frmowns.Show
End Sub

Private Sub mnuparticipated_Click()


frmparticipated.Show
End Sub

Private Sub mnupersonrpt_Click()


Set rs = db.Execute("select * from person")
Set personrpt.DataSource = rs
personrpt.Show
End Sub

Private Sub mnutransfer_Click()


frmtransfer.Show
End Sub

DBMS Lab Mannual 18


Dept of ISE SaIT

PERSON REPORT

DBMS Lab Mannual 19


Dept of ISE SaIT

CAR FORM

Dim check As String


Private Sub cmdcancel_Click()
txtregn = ""
txtmodel = ""
End Sub

DELETE BUTTON
Private Sub cmddelete_Click()

DBMS Lab Mannual 20


Dept of ISE SaIT

Dim str As String


str = MsgBox("are you sure you want to delete the selected record", vbYesNo)
If str = 6 Then
checkchild
If check = False Then
db.BeginTrans
db.Execute "delete from car where regno='" & txtregn & "'"
db.CommitTrans
clear
refreshrecord
MsgBox "record deleted"
End If
Else
Exit Sub
End If
End Sub

Private Sub checkchild()


Dim rec As New ADODB.Recordset
sql = "select * from owns where regno='" & txtregn & "'"
rec.Open sql, db, adOpenStatic, adLockReadOnly
If Not rec.EOF Then
MsgBox "child record found not possible to delete"
check = True
Exit Sub
Else
check = False
End If
End Sub

EXIT BUTTON
Private Sub cmdexit_Click()
Unload Me
End Sub

NEW BUTTON
Private Sub cmdnew_Click()
Dim regn_no As Integer
txtregn = getrecordno1("car", "regno")
txtmodel = ""
End Sub

BUTTONSAVE
Private Sub cmdsave_Click()
checkdata
If check = False Then

DBMS Lab Mannual 21


Dept of ISE SaIT

db.BeginTrans
sql = "insert into car values("
sql = sql & "'" & txtregn & "'"
sql = sql & ",'" & txtmodel & "'"
sql = sql & "," & txtyear & ""
sql = sql & ")"
db.Execute sql
db.CommitTrans
refreshrecord
clear
MsgBox "RECORD SUCCESSFULLY INSERTED"
End If
End Sub

DATAGRID FOR RECORD SELECTION


Private Sub DataGrid1_Click()
On Error GoTo errorhandler
txtregn = DataGrid1.Columns(0).Text
txtmodel = DataGrid1.Columns(1).Text
txtyear = DataGrid1.Columns(2).Text
errorhandler:
If Err.Number = "6160" Then
MsgBox "no record to select"
End If
End Sub

FORM LOAD SUB FUNCTION


Private Sub Form_Load()
txtyear = Format(Now, "yyyy")
End Sub

Private Function getrecordno1(tlb As String, regn_no As String)


Dim rs As New ADODB.Recordset
sql = "select * from " & tlb & " order by " & regn_no & " desc"
rs.Open sql, db, adOpenStatic, adLockReadOnly
If Not rs.EOF Then
rs.MoveFirst
recordno = rs!regno + 1
getrecordno1 = recordno
Else
recordno = 1
getrecordno1 = recordno
End If
End Function

FIELD VALIDATION

DBMS Lab Mannual 22


Dept of ISE SaIT

Private Sub checkdata()


If txtregn = "" Then
MsgBox "PLEASE ENTER THE regn_no"
check = True
txtregn.SetFocus
Exit Sub
Else
check = False
End If

If txtmodel = "" Then


MsgBox "PLEASE ENTER THE model"
check = True
txtmodel.SetFocus
Exit Sub
Else
check = False
End If
End Sub

Private Sub clear()


txtmodel = ""
txtregn = ""
End Sub

Private Sub refreshrecord()


sql = "select * from car"
Adodc1.RecordSource = sql
Adodc1.Refresh
End Sub

SEARCH ON REGN_NO
Private Sub txtsearch_Change()
sql = "select * from car where regno like '" & txtsearch & "%'"
Adodc1.RecordSource = sql
Adodc1.Refresh
End Sub

DBMS Lab Mannual 23


Dept of ISE SaIT

CAR REPORT

CAR DETAILS

REGNO MODEL YEAR

Ka03 3992 mustang 1999

Ka05 4993 ford 2000

Ka02 5662 ferrari 2001

Ka05 3456 fiat 2000

Ka 4567 renault 2001

DBMS Lab Mannual 24


Dept of ISE SaIT

OWNS FORM

CANCEL BUTTON
Private Sub cmdcancel_Click()
txtdr_id = ""
txtname = ""
txtaddr = ""
txtregn = ""
txtmodel = ""
txtyear = ""
End Sub

DELETE BUTTON
Private Sub cmddelete_Click()

DBMS Lab Mannual 25


Dept of ISE SaIT

Adodc4.RecordSource = "select car.regno,car.model,car.year from car,owns where


owns.driverid='" & txtdr_id & "'"
Adodc4.Refresh
End Sub

EXIT BUTTON
Private Sub cmdexit_Click()
Unload Me
End Sub

SAVE BUTTON
Private Sub cmdsave_Click()
db.BeginTrans
db.Execute "insert into owns values(" & txtdr_id & ",'" & txtregn & "')"
db.CommitTrans
clear
refreshgrid
MsgBox "CAR SUCCESSFULLY OWNED"
End Sub

DATAGRID FOR RECORD SELECTION OF PERSON DETAILS


Private Sub DataGrid1_Click()
On Error GoTo errorhandler
txtdr_id.Text = DataGrid1.Columns(0).Text
txtname.Text = DataGrid1.Columns(1).Text
txtaddr.Text = DataGrid1.Columns(2).Text
errorhandler:
MsgBox "no record to select"
Exit Sub
End Sub

DATAGRID FOR RECORD SELECTION OF CAR DETAILS


Private Sub DataGrid2_Click()
'On Error GoTo errorhandler
If DataGrid2.RecordSelectors = "false" Then
MsgBox "no records to dispaly"
Exit Sub
End If
txtregn = DataGrid2.Columns(0).Text
txtmodel = DataGrid2.Columns(1).Text
txtyear = DataGrid2.Columns(2).Text
End Sub

DBMS Lab Mannual 26


Dept of ISE SaIT

FORM LOAD SUB FUNCTION


Private Sub Form_Load()
Dim rs As New ADODB.Recordset
End Sub

REFRESH- DATAGRID
Private Sub refreshgrid()
sql = "select car.regno,car.model,car.year from car where regno Not in (select regno from
owns)"
Adodc2.RecordSource = sql
Adodc2.Refresh
DataGrid2.Refresh
End Sub

Private Sub clear()


txtdr_id = ""
txtname = ""
txtaddr = ""
txtregn = ""
txtmodel = ""
txtyear = ""
End Sub

SEARCH BY DRIVER_ID
Private Sub txtsearchdr_id_Change()
sql = "select * from person where driverid like '" & txtsearchdr_id & "%'"
Adodc1.RecordSource = sql
Adodc1.Refresh
DataGrid1.Refresh
End Sub

SEARCH BY REGN_NO
Private Sub txtsearchregn_no_Change()
sql = "select car.regno,car.model,car.year from car where regno like & txtsearchregn_no
& % Not in(select regnolike '" & txtsearchregn_no & "%' from owns)"
MsgBox sql

Adodc2.RecordSource = sql
Adodc2.Refresh
End Sub

DBMS Lab Mannual 27


Dept of ISE SaIT

OWNS REPORT

DBMS Lab Mannual 28


Dept of ISE SaIT

ACCIDENT FORM

Dim check As String


Private Function getrecordno(tlb As String, rep As String)
Dim rs As New ADODB.Recordset
Dim recordno As Integer
sql = "select * from " & tlb & " order by " & rep & " desc"
rs.Open sql, db, adOpenStatic, adLockReadOnly
If Not rs.EOF Then
rs.MoveFirst
recordno = rs!reportno + 1

DBMS Lab Mannual 29


Dept of ISE SaIT

getrecordno = recordno
Else
recordno = 1
getrecordno = recordno
End If
End Function

DELETE BUTTON
Private Sub cmddelete_Click()
checkdata1
If check = False Then
checkchild
If check = False Then
db.BeginTrans
sql = "delete from accident where rep_no='" & txtrepno & "'"
db.Execute sql
db.CommitTrans
clear
refreshgrid
MsgBox "record successfully deleted"
End If
Else
Exit Sub
End If
End Sub

Private Sub checkchild()


Dim rec As New ADODB.Recordset
sql = "select * from participated where reportno=" & txtrepno & ""
rec.Open sql, db, adOpenStatic, adLockReadOnly
If Not rec.EOF Then
MsgBox "child record found not possible to delete"
check = True
Exit Sub
Else
check = False
End If
End Sub

EXIT BUTTON
Private Sub cmdexit_Click()
Unload Me
End Sub

NEW BUTTON

DBMS Lab Mannual 30


Dept of ISE SaIT

Private Sub cmdnew_Click()


txtrepno = getrecordno("accident", "reportno")
End Sub

SAVE BUTTON
Private Sub cmdsave_Click()
checkdata
If check = False Then
db.BeginTrans
sql = "insert into accident values(" & txtrepno & ",'" & cmbdate & "-" & cmbmon
& "-" & cmbyear & "','" & txtloc & "')"
db.Execute sql
db.CommitTrans
clear
refreshgrid
MsgBox "record successfully saved"
End If
End Sub

FIELD VALIDATIONS

Private Sub checkdata()


Dim leap As String
insertyyyy

If txtrepno = "" Then


MsgBox "please enter the reprot number"
txtrepno.SetFocus
check = True
Exit Sub
Else
check = False
End If

If cmbdate = "" Then


MsgBox "please select the date"
cmbdate.SetFocus
check = True
Exit Sub
Else
check = False
End If

If cmbmon = "" Then


MsgBox "please select the month"
cmbmon.SetFocus

DBMS Lab Mannual 31


Dept of ISE SaIT

check = True
Exit Sub
Else
check = False
End If

If cmbyear = "" Then


MsgBox "please select the year"
cmbyear.SetFocus
check = True
Exit Sub
Else
check = False
End If

If cmbmon = "jan" Or cmbmon = "mar" Or cmbmon = "may" Or cmbmon = "jul" Or


cmbmon = "aug" Or cmbmon = "oct" Or cmbmon = "dec" Then
If Not cmbdate <= 31 Then
MsgBox "not a valid date"
cmbdate.SetFocus
check = True
Exit Sub
Else
check = False
End If
End If

If cmbmon = "apr" Or cmbmon = "jun" Or cmbmon = "sep" Or cmbmon = "nov" Then


If Not cmbdate <= 30 Then
MsgBox "not a valid date"
cmbdate.SetFocus
check = True
Exit Sub
Else
check = False
End If
End If

If cmbyear Mod 400 = 0 Or cmbyear Mod 4 = 0 And cmbyear Mod 100 <> 0 Then
leap = "true"
Else
leap = "false"
End If

If cmbmon = "feb" Then

DBMS Lab Mannual 32


Dept of ISE SaIT

If leap = "true" Then


If Not cmbdate <= 29 Then
MsgBox "not a valid date"
cmbdate.SetFocus
check = True
Exit Sub
Else
check = False
End If
End If

If leap = "false" Then


If Not cmbdate <= 28 Then
MsgBox "not a valid date"
cmbdate.SetFocus
check = True
Exit Sub
Else
check = False
End If
End If
End If

If txtloc = "" Then


MsgBox "please enter the accident location"
txtloc.SetFocus
check = True
Exit Sub
Else
check = False
End If
End Sub

DATAGRID FOR RECORD SELECTION


Private Sub DataGrid1_Click()
On Error GoTo errorhandler
txtrepno = DataGrid1.Columns(0).Text
txtadate = DataGrid1.Columns(1).Text
txtloc = DataGrid1.Columns(2).Text
errorhandler:
If Err.Number = "6160" Then
MsgBox "no record to select"
End If
End sub

Private Sub checkdata1()

DBMS Lab Mannual 33


Dept of ISE SaIT

Dim vbstr As String


If txtrepno = "" Then
MsgBox "please select the record you want to delete"
check = True
Exit Sub
Else
check = False
End If

vbstr = MsgBox("are you sure you want to delete the selected record", vbYesNo)
If vbstr = "6" Then
check = False
Else
check = True
End If
End Sub

REFRESH- DATAGRID
Private Sub refreshgrid()
sql = "select * from accident"
Adodc1.RecordSource = sql
Adodc1.Refresh
DataGrid1.Refresh
End Sub
Private Sub clear()
txtrepno = ""
txtadate = ""
txtloc = ""
cmbdate = ""
cmbmon = ""
cmbyear = ""
End Sub

DBMS Lab Mannual 34


Dept of ISE SaIT

ACCIDENT REPORT

Report Date location


-numbe
r

11 12-jun-00 ca

12 02-jan-99 ma

13 01-mar-98 ba

14 04-jul-01 dd

15 05-mar-02 ds

DBMS Lab Mannual 35


Dept of ISE SaIT

PARTICIPATED FORM

Dim check As String

Private Sub cmbrepno_Click()


Dim rs As New ADODB.Recordset
sql = "select dmg_amt from participated where reportno=" & cmbrepno & ""
rs.Open sql, db, adOpenStatic, adLockReadOnly
If Not rs.EOF Then
txtdmgamt = rs!dmg_amt

DBMS Lab Mannual 36


Dept of ISE SaIT

End If
End Sub

DELETE BUTTON
Private Sub cmddelete_Click()
checkdelete
If check = False Then
db.BeginTrans
db.Execute "delete from participated where driverid='" & txtdr_id & "' and regno='" &
txtregno & "'and reportno='" & cmbrepno & "'"
db.CommitTrans
clear
MsgBox "selected record deleted"
End If
End Sub

Private Sub checkdelete()


Dim VBYES As String
If txtdr_id = "" Or txtregno = "" Then
MsgBox "please select the record to delete"
check = True
Exit Sub
Else
check = False
End If

VBYES = MsgBox("DO YOU WANT TO DELETE THE SELECTED RECORD",


vbYesNo)
If VBYES = "6" Then
check = False
Else
check = True
End If
End Sub

UPDATE BUTTON
Private Sub cmdupdate_Click()
If cmbrepno = "" Then
MsgBox "please select report to update"
check = True
Exit Sub
Else
check = False
End If
If check = False Then
db.BeginTrans

DBMS Lab Mannual 37


Dept of ISE SaIT

db.Execute "update participated set dmg_amt=" & txtdmgamt & " where driverid='" &
txtdr_id & "' and regno='" & txtregno & "'and reportno='" & cmbrepno & "' "
db.CommitTrans
clear
MsgBox "successfully updated"
End If
End Sub

EXIT BUTTON
Private Sub cmdexit_Click()
Unload Me
End Sub

NEW BUTTON
Private Sub cmdnew_Click()
Dim rs As New ADODB.Recordset
txtdmgamt = ""
sql = "select reportno from accident where reportno not in (select reportno from
participated)"
rs.Open sql, db, adOpenStatic, adLockReadOnly
cmbrepno.clear
If Not rs.EOF Then
Do Until rs.EOF
cmbrepno.AddItem (rs!reportno)
rs.MoveNext
Loop
Else
Form_Load
txtdmgamt = ""
End If
End Sub

SAVE BUTTON
Private Sub cmdsave_Click()
checkdata
If check = False Then
db.BeginTrans
db.Execute "insert into participated values('" & txtdr_id & "','" & txtregno & "'," &
cmbrepno & "," & txtdmgamt & ")"
db.CommitTrans
Form_Load
clear
MsgBox "record successfully created"
End If

DBMS Lab Mannual 38


Dept of ISE SaIT

End Sub

DATAGRID FOR RECORD SELECTION


Private Sub DataGrid1_Click()
On Error GoTo errorhandler
Dim rs As New ADODB.Recordset
Dim rs1 As New ADODB.Recordset
txtdr_id = DataGrid1.Columns(0).Text
txtregno = DataGrid1.Columns(1).Text
txtdmgamt = ""
sql = "select reportno,dmg_amt from participated where driverid='" & txtdr_id & "' and
regno='" & txtregno & "'"
rs.Open sql, db, adOpenStatic, adLockReadOnly
cmbrepno.clear
If Not rs.EOF Then
Do Until rs.EOF
cmbrepno.AddItem (rs!reportno)
rs.MoveNext
Loop
Else
Form_Load
txtdmgamt = ""
End If

sql = "select * from participated where driverid='" & txtdr_id & "' and regno='" &
txtregno & "'"
rs1.Open sql, db, adOpenStatic, adLockReadOnly
If Not rs1.EOF Then
lblstatus.Caption = "report exists"
Else
lblstatus.Caption = "report not found"
End If
errorhandler:
If Err.Number = "6160" Then
MsgBox "no record to select"
End If
End Sub
FORM LOAD SUB FUNCTION
Private Sub Form_Load()
Dim rs As New ADODB.Recordset
sql = "select accident.reportno from accident where reportno Not in (select reportno from
participated)"
rs.Open sql, db, adOpenStatic, adLockReadOnly
cmbrepno.clear
If Not rs.EOF Then
Do Until rs.EOF

DBMS Lab Mannual 39


Dept of ISE SaIT

cmbrepno.AddItem (rs!reportno)
rs.MoveNext
Loop
End If
cmbrepno.Refresh
End Sub

FIELD VALIDATIONS
Private Sub checkdata()
If txtdr_id = "" Then
MsgBox "please select the driverid"
txtdr_id.SetFocus
check = True
Exit Sub
Else
check = False
End If

If txtregno = "" Then


MsgBox "please select the regno"
txtregno.SetFocus
check = True
Exit Sub
Else
check = False
End If

If cmbrepno = "" Then


MsgBox "please select the report number"
cmbrepno.SetFocus
check = True
Exit Sub
Else
check = False
End If

If txtdmgamt = "" Then


MsgBox "please enter the damage amount"
txtdmgamt.SetFocus
check = True
Exit Sub
Else
check = False
End If

End Sub

DBMS Lab Mannual 40


Dept of ISE SaIT

Private Sub clear()


txtdr_id = ""
txtregno = ""
cmbrepno = ""
txtdmgamt = ""
End Sub
Private Sub checkdelete()
Dim VBYES As String
If txtdr_id = "" Or txtregno = "" Then
MsgBox "please select the record to delete"
check = True
Exit Sub
Else
check = False
End If

VBYES = MsgBox("DO YOU WANT TO DELETE THE SELECTED RECORD",


vbYesNo)
If VBYES = "6" Then
check = False
Else
check = True
End If
End Sub

DBMS Lab Mannual 41


Dept of ISE SaIT

PARTICIPATED REPORT

DBMS Lab Mannual 42


Dept of ISE SaIT

DELETE FORM

Private Sub cmbdr_id_Click()


Dim rs As New ADODB.Recordset
cmbregno.clear
sql = "select regno from owns where driverid='" & cmbdr_id & "'"
rs.Open sql, db, adOpenStatic, adLockReadOnly
If Not rs.EOF Then
Do Until rs.EOF
cmbregno.AddItem (rs!regno)
rs.MoveNext
Loop
End If

DBMS Lab Mannual 43


Dept of ISE SaIT

End Sub

EXIT BUTTON
Private Sub cmdexit_Click()
Unload Me
End Sub

TRANSFER BUTTON
Private Sub cmdtransfer_Click()
checkdata
If check = False Then
db.BeginTrans
sql = "delete from owns where driverid='" & cmbdr_id & "' and regno='" & cmbregno &
"'"
db.Execute sql
db.CommitTrans
clear
MsgBox "successfully transfered"
End If
End Sub

FORM LOAD SUB FUNCTION


Private Sub Form_Load()
Dim rs As New ADODB.Recordset
sql = "select driverid from person"
rs.Open sql, db, adOpenStatic, adLockReadOnly
If Not rs.EOF Then
Do Until rs.EOF
cmbdr_id.AddItem (rs!driverid)
rs.MoveNext
Loop
End If
End Sub
Private Sub checkdata()
If cmbdr_id = "" Then
MsgBox "please select the driver id"
check = True
Exit Sub
Else
check = False
End If

If cmbregno = "" Then


MsgBox "please select the reg number"
check = True
Exit Sub

DBMS Lab Mannual 44


Dept of ISE SaIT

Else
check = False
End If
End Sub
Private Sub clear()
cmbdr_id = ""
cmbregno = ""
End Sub

ORDER
PROCESSING
DATABASE

DBMS Lab Mannual 45


Dept of ISE SaIT

2. Consider the following relations for an order processing database applications in a


Company
CUSTOMER(cust:int,cname:string,city:string)
ORDER(order:int,odate:date,cust:int,ord-amt:int)
ORDER-ITEM(order:int,item:int,qty:int)
ITEM(item:int,unitprice:int)
SHIPMENT(order:int,warehouse:int,ship-date:date)
WAREHOUSE(warehouse:int,city:string)
1) create the above tables by properly specifying the primary keys and the foreign
keys
2) enter atleast five tuples for each relation
3) produce a listing:CUSTNAME,# of orders,AVG_ORDER_AMT,where the
middle column is the total no of orders by the customer and the last column is the
average order amount for that customer
4) list the order # for orders that were shipped from all warehouses that the company
has in a specified city
5) demonstrate how you delete item #10 from ITEM table and make the field null in
the ORDER_ITEM table.
6) Generation of suitable reports.
7) Create suitable front end for querying and displaying the results.

SQL> create table customer(


2 Custno integer,
3 Cname varchar(15) not null,
4 City varchar(15),
5 primary key (Custno));

Table created.

SQL> create table corder(


2 Orderno integer,
3 Odate date not null,
4 Custno integer,

DBMS Lab Mannual 46


Dept of ISE SaIT

5 OrderAmount integer not null,


6 primary key (Orderno),
7 foreign key (Custno) references Customer(Custno));

Table created.

SQL> create table item(


2 itemno integer,
3 unitprice integer not null,
4 primary key (itemno));

Table created.

SQL> create table order_item(


orderno integer,
itemno integer,
quantity integer,
primary key (orderno,itemno),
foreign key (orderno) references corder(orderno),
foreign key (itemno) references item(itemno));

Table created.

SQL> create table warehouse(


2 warehouseno integer,
3 city varchar(15) not null,
4 primary key (warehouseno));

Table created.

SQL> create table shipment(


2 orderno integer,
3 warehouseno integer,
4 shipdate date,
5 primary key (orderno,warehouseno),
6 foreign key (orderno) references corder(orderno),
7 foreign key (warehouseno) references warehouse(warehouseno));

Table created.

SQL> desc customer;


Name Null? Type
----------------------------------------- -------- ----------------------------
CUSTNO NOT NULL NUMBER(38)
CNAME NOT NULL VARCHAR2(15)

DBMS Lab Mannual 47


Dept of ISE SaIT

CITY VARCHAR2(15)

SQL> insert into customer values(1111,'Jack','Bangalore');

1 row created.

SQL> insert into customer values(2222,'Fred','New York');

1 row created.

SQL> insert into customer values(3333,'George','Amsterdam');

1 row created.

SQL> insert into customer values(4444,'Kumar','Bangalore');

1 row created.

SQL> insert into customer values(5555,'Das','Bangalore');

1 row created.

SQL> select * from customer;

CUSTNO CNAME CITY


---------- --------------- ---------------
1111 Jack Bangalore
2222 Fred New York
3333 George Amsterdam
4444 Kumar Bangalore
5555 Das Bangalore

SQL> desc corder;


Name Null? Type
----------------------------------------- -------- ----------------------------
ORDERNO NOT NULL NUMBER(38)
ODATE NOT NULL DATE
CUSTNO NUMBER(38)
ORDERAMOUNT NOT NULL NUMBER(38)

SQL> insert into corder values(1,'10-Mar-2004',1111,10000);

1 row created.

SQL> insert into corder values(2,'15-Apr-2005',2222,25000);

DBMS Lab Mannual 48


Dept of ISE SaIT

1 row created.

SQL> insert into corder values(3,'15-Dec-2004',3333,30000);

1 row created.

SQL> insert into corder values(4,'17-Jun-2004',4444,40000);

1 row created.

SQL> insert into corder values(5,'11-Jul-2004',2222,50000);

1 row created.

SQL> select * from corder;

ORDERNO ODATE CUSTNO ORDERAMOUNT


---------- --------- ---------- -----------
1 10-MAR-04 1111 10000
2 15-APR-05 2222 25000
3 15-DEC-04 3333 30000
4 17-JUN-04 4444 40000
5 11-JUL-04 2222 50000

SQL> desc item;


Name Null? Type
----------------------------------------- -------- ----------------------------
ITEMNO NOT NULL NUMBER(38)
UNITPRICE NOT NULL NUMBER(38)

SQL> insert into item values(11,500);

1 row created.

SQL> insert into item values(22,250);

1 row created.

SQL> insert into item values(33,100);

1 row created.

SQL> insert into item values(44,50);

1 row created.

DBMS Lab Mannual 49


Dept of ISE SaIT

SQL> insert into item values(55,2);

1 row created.

SQL> insert into item values(10,150);

1 row created.

SQL> select * from item;

ITEMNO UNITPRICE
---------- ----------
11 500
22 250
33 100
44 50
55 2
10 150

6 rows selected.

SQL> desc order_item;


Name Null? Type
----------------------------------------- -------- ----------------------------
ORDERNO NOT NULL NUMBER(38)
ITEMNO NOT NULL NUMBER(38)
QUANTITY NUMBER(38)

SQL> insert into order_item values (1,11,150);

1 row created.

SQL> insert into order_item values (2,22,200);

1 row created.

SQL> insert into order_item values (3,33,300);

1 row created.

SQL> insert into order_item values (4,44,400);

1 row created.

SQL> insert into order_item values (5,55,500);

DBMS Lab Mannual 50


Dept of ISE SaIT

1 row created.

SQL> insert into order_item values(2,10,500);

1 row created.

SQL> select * from order_item;

ORDERNO ITEMNO QUANTITY


---------- ---------- ----------
1 11 150
2 22 200
3 33 300
4 44 400
5 55 500
2 10 500

6 rows selected.

SQL> desc warehouse;


Name Null? Type
----------------------------------------- -------- ----------------------------
WAREHOUSENO NOT NULL NUMBER(38)
CITY NOT NULL VARCHAR2(15)

SQL> insert into warehouse values(17,'Bangalore');

1 row created.

SQL> insert into warehouse values(27,'Chennai');

1 row created.

SQL> insert into warehouse values(37,'Pune');

1 row created.

SQL> insert into warehouse values(47,'Coimbatore');

1 row created.

SQL> insert into warehouse values(57,'Cochin');

1 row created.

DBMS Lab Mannual 51


Dept of ISE SaIT

SQL> select * from warehouse;

WAREHOUSENO CITY
----------- ---------------
17 Bangalore
27 Chennai
37 Pune
47 Coimbatore
57 Cochin

SQL> desc shipment;


Name Null? Type
----------------------------------------- -------- ----------------------------
ORDERNO NOT NULL NUMBER(38)
WAREHOUSENO NOT NULL NUMBER(38)
SHIPDATE DATE

SQL> insert into shipment values(1,17,'02-Jul-2005');

1 row created.

SQL> insert into shipment values(2,17,'15-Apr-2005');

1 row created.

SQL> insert into shipment values(3,27,'6-Jun-2005');

1 row created.

SQL> insert into shipment values(4,37,'10-May-2005');

1 row created.

SQL> insert into shipment values(5,47,'9-Feb-2005');

1 row created.

SQL> select * from shipment;

ORDERNO WAREHOUSENO SHIPDATE


---------- ----------- ---------
1 17 02-JUL-05
2 17 15-APR-05
3 27 06-JUN-05
4 37 10-MAY-05
5 47 09-FEB-05

DBMS Lab Mannual 52


Dept of ISE SaIT

***** 1st query *****

SQL> select C.Cname,count(CO.orderno),Avg(CO.Orderamount)


2 from Customer C,corder CO
3 where C.custno=CO.custno
4 group by C.Cname,CO.custno;

CNAME COUNT(CO.ORDERNO) AVG(CO.ORDERAMOUNT)


--------------- ----------------- -------------------
Fred 2 37500
George 1 30000
Jack 1 10000
Kumar 1 40000

***** 2nd query *****

SQL> select orderno,warehouseno


2 from shipment
3 where warehouseno in
4 (select warehouseno
5 from warehouse
6 where city='Bangalore');

ORDERNO WAREHOUSENO
---------- -----------
1 17
2 17

DBMS Lab Mannual 53


Dept of ISE SaIT

CUSTOMER FORM

EXIT BUTTON
Private Sub cmdexit_Click()
Unload Me
End Sub

NEW BUTTON
Private Sub cmdnew_Click()
txtcustomerno = getrecordno("customer", "custno")
End Sub

DBMS Lab Mannual 54


Dept of ISE SaIT

SAVE BUTTON
Private Sub cmdsave_Click()
checkdata
If check = False Then
db.BeginTrans
sql = "insert into customer values(" & txtcustno & ",'" & txtename "','" & txtcity
"')"
db.Execute sql
db.CommitTrans
clear
refreshgrid
MsgBox "record successfully saved"
End If
End Sub

DELETE BUTTON
Private Sub cmddelete_Click()
checkdata1
If check = False Then
checkchild
If check = False Then
db.BeginTrans
sql = "delete from customer where custno='" & txtcustno & "'"
db.Execute sql
db.CommitTrans
clear
refreshgrid
MsgBox "record successfully deleted"
End If
Else
Exit Sub
End If
End Sub

Private Sub checkchild()


Dim rec As New ADODB.Recordset
sql = "select * from customer where custno=" & txtcustno & ""
rec.Open sql, db, adOpenStatic, adLockReadOnly
If Not rec.EOF Then
MsgBox "child record found not possible to delete"
check = True
Exit Sub
Else
check = False

DBMS Lab Mannual 55


Dept of ISE SaIT

End If
End Sub
CANCEL BUTTON
Private Sub cmdcancel_Click()
txtcustno=””
txtename = ""
txtcity = ""
End Sub

CUSTOMER REPORT

CUSTOMER CUSTOMER CITY


NO NAME

11 aaa bangalore

12 bbb Mysore

13 ccc bangalore

14 ddd hubli

15 eee mysore

DBMS Lab Mannual 56


Dept of ISE SaIT

STUDENT
DATABASE

DBMS Lab Mannual 57


Dept of ISE SaIT

3. consider the following database of student enrollment in courses and books adopted for
each course
STUDENT(regno:string,name:string,major:string,bdate:date)
COURSE(course:int,cname:string,dept:string)
ENROLL(regno:string,course:int,marks:int)
BOOK_ADOPTION(course:int,sem:int,book-ISBN:int)
TEXT(book-ISBN:int,book-title:string,publisher:string,author:string)

1) create the above tables by properly specifying the primary keys and foreign keys
2) enter five tuples for each relation
3) demonstrate how you add a new text book to the database and make this book be
adopted by some department
4) produce a list of text books in alphabetical order for courses offered by CS
department that use more than two books
5) list any department that has all its adopted books published by a specific publisher
6) generation of suitable reports
7) create suitable front end for querying and displaying the results

SQL> create table Student(


2 Regno varchar(10),
3 Name varchar(10) not null,
4 Major varchar(10) not null,
5 Bdate date,
6 primary key (Regno));

Table created.

SQL> create table Course(


2 Courseno integer,
3 Cname varchar(10) not null,
4 Dept varchar(10) not null,
5 primary key (Courseno));

DBMS Lab Mannual 58


Dept of ISE SaIT

Table created.

SQL> create table Enroll(


2 Regno varchar(10),
3 Courseno integer,
4 Sem integer not null,
5 Marks integer,
6 primary key (Regno,Courseno),
7 foreign key (Regno) references Student(Regno),
8 foreign key (Courseno) references Course(Courseno));

Table created.

SQL> create table Text(


2 ISBN integer,
3 Booktitle varchar(20) not null,
4 Publisher varchar(20),
5 Author varchar(15),
6 primary key (ISBN));

Table created.

SQL> create table Book_adoption(


2 Courseno integer,
3 Sem integer,
4 ISBN integer,
5 primary key (Courseno,Sem),
6 foreign key (Courseno) references Course(Courseno),
7 foreign key (ISBN) references Text(ISBN));

Table created.

SQL> desc student;


Name Null? Type
----------------------------------------- -------- ----------------------------
REGNO NOT NULL VARCHAR2(10)
NAME NOT NULL VARCHAR2(10)
MAJOR NOT NULL VARCHAR2(10)
BDATE DATE

SQL> insert into Student values('1BI02CS010','Karan','CSE','02-Jan-1984');

1 row created.

SQL> insert into Student values('1BI02EE015','Jack','EEE','15-Apr-1983');

DBMS Lab Mannual 59


Dept of ISE SaIT

1 row created.

SQL> insert into Student values('1BI00CS010','Adi','CSE','02-Jan-1982');

1 row created.

SQL> insert into Student values('1BI01EC089','Rahul','ECE','01-Dec-1983');

1 row created.

SQL> insert into student values ('1BI01ME075','Sachin','MECH','18-Jul-1983');

1 row created.

SQL> select * from student;

REGNO NAME MAJOR BDATE


---------- ---------- ---------- ---------
1BI01ME075 Sachin MECH 18-JUL-83
1BI02CS010 Karan CSE 02-JAN-84
1BI02EE015 Jack EEE 15-APR-83
1BI00CS010 Adi CSE 02-JAN-82
1BI01EC089 Rahul ECE 01-DEC-83

SQL> desc course;


Name Null? Type
----------------------------------------- -------- ----------------------------
COURSENO NOT NULL NUMBER(38)
CNAME NOT NULL VARCHAR2(10)
DEPT NOT NULL VARCHAR2(10)

SQL> insert into course values(11,'DSC','CSE');

1 row created.

SQL> insert into course values(22,'ADA','CSE');

1 row created.

SQL> insert into course values(33,'CN','EC');

1 row created.

SQL> insert into course values(44,'TD','MECH');

1 row created.

DBMS Lab Mannual 60


Dept of ISE SaIT

SQL> insert into course values(55,'MP','EC');

1 row created.

SQL> select * from course;

COURSENO CNAME DEPT


---------- ---------- ----------
11 DSC CSE
22 ADA CSE
33 CN EC
44 TD MECH
55 MP EC

SQL> desc enroll;


Name Null? Type
----------------------------------------- -------- ----------------------------
REGNO NOT NULL VARCHAR2(10)
COURSENO NOT NULL NUMBER(38)
SEM NOT NULL NUMBER(38)
MARKS NUMBER(38)

SQL> insert into enroll values('1BI02CS010',22,5,72);

1 row created.

SQL> insert into enroll values('1BI00CS010',11,3,90);

1 row created.

SQL> insert into enroll values('1BI01EC089',33,6,52);

1 row created.

SQL> insert into enroll values('1BI01ME075',44,4,85);

1 row created.

SQL> insert into enroll values('1BI02EE015',22,5,75);

1 row created.

SQL> select * from enroll;

REGNO COURSENO SEM MARKS

DBMS Lab Mannual 61


Dept of ISE SaIT

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


1BI02CS010 22 5 72
1BI00CS010 11 3 90
1BI01EC089 33 6 52
1BI01ME075 44 4 85
1BI02EE015 22 5 75

SQL> desc text;


Name Null? Type
----------------------------------------- -------- ----------------------------
ISBN NOT NULL NUMBER(38)
BOOKTITLE NOT NULL VARCHAR2(20)
PUBLISHER VARCHAR2(20)
AUTHOR VARCHAR2(15)

SQL> insert into text values(7722,'VB6','Dreamtech','Holzner');

1 row created.

SQL> insert into text values(1144,'DS with C','Sapna','Nandagopalan');

1 row created.

SQL> insert into text values(4400,'C Programming','TMH','Balaguruswamy');

1 row created.

SQL> insert into text values(5566,'Computer Nw','PHI','Tennenbaum');

1 row created.

SQL> insert into text values(3388,'MP','PHI','Brey');

1 row created.

SQL> select * from text;

ISBN BOOKTITLE PUBLISHER AUTHOR


---------- -------------------- -------------------- ---------------
7722 VB6 Dreamtech Holzner
1144 DS with C Sapna Nandagopalan
4400 C Programming TMH Balaguruswamy
5566 Computer Nw PHI Tennenbaum
3388 MP PHI Brey

DBMS Lab Mannual 62


Dept of ISE SaIT

SQL> desc book_adoption;


Name Null? Type
----------------------------------------- -------- ------------------------
COURSENO NOT NULL NUMBER(38)
SEM NOT NULL NUMBER(38)
ISBN NUMBER(38)

SQL> insert into book_adoption values(11,3,7722);

1 row created.

SQL> insert into book_adoption values(22,4,7722);

1 row created.

SQL> insert into book_adoption values(11,5,4400);

1 row created.

SQL> insert into book_adoption values(11,8,5566);

1 row created.

SQL> insert into book_adoption values(55,4,3388);

1 row created.

SQL> insert into book_adoption values(44,4,5566);

1 row created.

SQL> insert into book_adoption values(44,7,3388);

1 row created.

SQL> select * from book_adoption;

COURSENO SEM ISBN


---------- ---------- ----------
11 3 7722
22 4 7722
11 5 4400
11 8 5566
55 4 3388

DBMS Lab Mannual 63


Dept of ISE SaIT

44 4 5566
44 7 3388

7 rows selected.

***** 1st query *****


SQL> insert into text values(1234,'Elec.Circuits','Sapna','Giridhar');

1 row created.

SQL> insert into book_adoption values(55,3,1234);

1 row created.

SQL> select * from text;

ISBN BOOKTITLE PUBLISHER AUTHOR


---------- -------------------- -------------------- ---------------
7722 VB6 Dreamtech Holzner
1144 DS with C Sapna Nandagopalan
4400 C Programming TMH Balaguruswamy
5566 Computer Nw PHI Tennenbaum
3388 MP PHI Brey
1234 Elec.Circuits Sapna Giridhar

6 rows selected.

SQL> select * from book_adoption;

COURSENO SEM ISBN


---------- ---------- ----------
11 3 7722
22 4 7722
11 5 4400
11 8 5566
55 4 3388
44 4 5566
44 7 3388
55 3 1234

8 rows selected.

***** 2nd query *****

SQL> select C.Courseno,T.ISBN,T.Booktitle

DBMS Lab Mannual 64


Dept of ISE SaIT

2 from Course C,Book_adoption BA,Text T


3 where C.Courseno=BA.Courseno and BA.ISBN=T.ISBN and C.Dept='CSE'
4 group by C.Courseno,T.ISBN,T.Booktitle;

COURSENO ISBN BOOKTITLE


---------- ---------- --------------------
11 4400 C Programming
11 5566 Computer Nw
11 7722 VB6
22 7722 VB6

***** 3rd query *****

SQL> select distinct C.Dept


2 from Course C, Book_adoption A,Text T
3 where C.Courseno=A.Courseno and
4 A.ISBN=T.ISBN and
5 not exists (( select Y.ISBN
6 from Course X,Book_Adoption Y
7 where X.Courseno=Y.Courseno
8 and X.Dept=C.Dept)
9 minus
10 (select ISBN
11 from Text
12 where publisher='PHI'));

DEPT
----------
MECH

DBMS Lab Mannual 65


Dept of ISE SaIT

STUDENT FORM

EXIT BUTTON
Private Sub cmdexit_Click()
Unload Me
End Sub

NEW BUTTON

DBMS Lab Mannual 66


Dept of ISE SaIT

Private Sub cmdnew_Click()


txtregno = getrecordno("student", "regno")
End Sub

SAVE BUTTON
Private Sub cmdsave_Click()
checkdata
If check = False Then
db.BeginTrans
sql = "insert into student values(" & txtregno & ",'" & txtname "','" & txtmajor,’
“’&txtbdate "')"
db.Execute sql
db.CommitTrans
clear
refreshgrid
MsgBox "record successfully saved"
End If
End Sub

DELETE BUTTON
Private Sub cmddelete_Click()
checkdata1
If check = False Then
checkchild
If check = False Then
db.BeginTrans
sql = "delete from student where regno='" & txtregno & "'"
db.Execute sql
db.CommitTrans
clear
refreshgrid
MsgBox "record successfully deleted"
End If
Else
Exit Sub
End If
End Sub

Private Sub checkchild()


Dim rec As New ADODB.Recordset
sql = "select * from student where regno=" & txtregno & ""
rec.Open sql, db, adOpenStatic, adLockReadOnly
If Not rec.EOF Then
MsgBox "child record found not possible to delete"
check = True
Exit Sub

DBMS Lab Mannual 67


Dept of ISE SaIT

Else
check = False
End If
End Sub

CANCEL BUTTON
Private Sub cmdcancel_Click()
txtregno=””
txtname = ""
txtmajor = ""
txtblue=””
End Sub
STUDENT REPORT

REGNO NAME MAJOR BDATE

1 a Mech 18-JUL-83

2 b CS 02-JAN-84

3 c EC 15-APR-83

4 d Civil 02-JAN-82

5 e CS 01-DEC-83

DBMS Lab Mannual 68


Dept of ISE SaIT

BOOK DEALER
DATABASE

DBMS Lab Mannual 69


Dept of ISE SaIT

4.The following tables are maintained by a book dealer


AUTHOR(author-id:int,name:string,city:string,country:string)
PUBLISHER(publisher-id:int,name:string,city:string,country:string)
CATALOG(book-id:int,title:string,author-id:int,publisher-id:int,category-
id:int,year:int,price:int)
CATEGORY(category-id:int,description:script)
ORDER-DETAILS(order-no:int,book-id:int,quantity:int)
1) create the above details by properly specifying the primary keys and foreign keys
2) enter atleast five tuples for each relation
3) find the author of the book which has maximium sales
4) demonstrate how you increase the price of books published by a specific publisher
by 10%
5) generation of suitable reports
6) create suitable front end for querying and display the results
SQL> create table Author(
Authorid integer,
Aname varchar(15),
Acity varchar(15),
Acountry varchar(15),
primary key (Authorid));

Table created.

SQL> create table Publisher(


Publisherid integer,
Pname varchar(15),
Pcity varchar(15),
Pcountry varchar(15),
primary key (Publisherid));

Table created.

SQL> create table Category(


Categoryid integer,

DBMS Lab Mannual 70


Dept of ISE SaIT

Description varchar(20),
primary key (Categoryid));

Table created.

SQL> create table Catalog(


Bookid integer,
Title varchar(20),
Authorid integer,
Publisherid integer,
Categoryid integer,
Year integer,
Price integer,
primary key (Bookid),
foreign key (Authorid) references Author(Authorid),
foreign key (Publisherid) references Publisher(Publisherid),
foreign key (Categoryid) references Category(Categoryid));

Table created.

SQL> create table Order_details(


Orderno integer,
Bookid integer,
Quantity integer,
primary key (Orderno,Bookid),
foreign key (Bookid) references Catalog(Bookid));

Table created.

SQL> desc author;


Name Null? Type
----------------------------------------- -------- ----------------------------
AUTHORID NOT NULL NUMBER(38)
ANAME VARCHAR2(15)
ACITY VARCHAR2(15)
ACOUNTRY VARCHAR2(15)

SQL> insert into Author values(1000,'Nandagopalan','Bangalore','India');

1 row created.

SQL> insert into Author values(2000,'Tony','Haywood','USA');

1 row created.

SQL> insert into Author values(3000,'Holzner','New York','USA');

DBMS Lab Mannual 71


Dept of ISE SaIT

1 row created.

SQL> insert into Author values(4000,'Tennenbaum','London','UK');

1 row created.

SQL> insert into Author values(5000,'Balaguruswamy','Chennai','India');

1 row created.

SQL> select * from Author;

AUTHORID ANAME ACITY ACOUNTRY


---------- --------------- --------------- ---------------
1000 Nandagopalan Bangalore India
2000 Tony Haywood USA
3000 Holzner New York USA
4000 Tennenbaum London UK
5000 Balaguruswamy Chennai India

SQL> desc publisher;


Name Null? Type
----------------------------------------- -------- ----------------------------
PUBLISHERID NOT NULL NUMBER(38)
PNAME VARCHAR2(15)
PCITY VARCHAR2(15)
PCOUNTRY VARCHAR2(15)

SQL> insert into publisher values(11,'Wiely','NewDelhi','India');

1 row created.

SQL> insert into publisher values(22,'PHI','California','USA');

1 row created.

SQL> insert into publisher values(33,'Sapna','Bangalore','India');

1 row created.

SQL> insert into publisher values(44,'TMH','NewYork','USA');

1 row created.

SQL> insert into publisher values(55,'Wrox','Texas','USA');

DBMS Lab Mannual 72


Dept of ISE SaIT

1 row created.

SQL> select * from publisher;

PUBLISHERID PNAME PCITY PCOUNTRY


----------- --------------- --------------- ---------------
11 Wiely NewDelhi India
22 PHI California USA
33 Sapna Bangalore India
44 TMH NewYork USA
55 Wrox Texas USA

SQL> desc category;


Name Null? Type
----------------------------------------- -------- ----------------------------
CATEGORYID NOT NULL NUMBER(38)
DESCRIPTION VARCHAR2(20)

SQL> insert into category values(1,'OS');

1 row created.

SQL> insert into category values(2,'Languages');

1 row created.

SQL> insert into category values(3,'Hardware');

1 row created.

SQL> insert into category values(4,'Algorithms');

1 row created.

SQL> insert into category values(5,'Internet');

1 row created.

SQL> select * from category;

CATEGORYID DESCRIPTION
---------- --------------------
1 OS
2 Languages

DBMS Lab Mannual 73


Dept of ISE SaIT

3 Hardware
4 Algorithms
5 Internet

SQL> desc catalog;


Name Null? Type
----------------------------------------- -------- ----------------------------
BOOKID NOT NULL NUMBER(38)
TITLE VARCHAR2(20)
AUTHORID NUMBER(38)
PUBLISHERID NUMBER(38)
CATEGORYID NUMBER(38)
YEAR NUMBER(38)
PRICE NUMBER(38)

SQL> insert into catalog values(123,'DSC',1000,33,2,2000,185);

1 row created.

SQL> insert into catalog values(456,'Networks',4000,44,4,2002,365);

1 row created.

SQL> insert into catalog values(789,'VB6',2000,11,2,2000,300);

1 row created.

SQL> insert into catalog values(213,'Frontpage2002',4000,44,5,2003,500);

1 row created.

SQL> insert into catalog values(879,'ADA',1000,33,4,2001,195);

1 row created.

SQL> select * from catalog;

BOOKID TITLE AUTHORID PUBLISHERID CATEGORYID YEAR


---------- -------------------- ---------- ----------- ---------- ----------
PRICE
----------
123 DSC 1000 33 2 2000
185

456 Networks 4000 44 4 2002

DBMS Lab Mannual 74


Dept of ISE SaIT

365

789 VB6 2000 11 2 2000


300

BOOKID TITLE AUTHORID PUBLISHERID CATEGORYID YEAR


---------- -------------------- ---------- ----------- ---------- ----------
PRICE
----------
213 Frontpage2002 4000 44 5 2003
500

879 ADA 1000 33 4 2001


195
SQL> desc order_details;
Name Null? Type
----------------------------------------- -------- ----------------------------
ORDERNO NOT NULL NUMBER(38)
BOOKID NOT NULL NUMBER(38)
QUANTITY NUMBER(38)

SQL> insert into order_details values(112,123,100);

1 row created.

SQL> insert into order_details values(113,123,20);

1 row created.

SQL> insert into order_details values(114,213,50);

1 row created.

SQL> insert into order_details values(115,789,500);

1 row created.

SQL> insert into order_details values(116,879,8);

1 row created.

SQL> select * from order_details;

ORDERNO BOOKID QUANTITY


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

DBMS Lab Mannual 75


Dept of ISE SaIT

112 123 100


113 123 20
114 213 50
115 789 500
116 879 8

***** 1st query *****

SQL> select C.Authorid,A.Aname


2 from Catalog C,Author A
3 where A.Authorid=C.Authorid and C.Year>2000 and C.Price>(Select Avg(Price)
from Catalog)
4 group by C.Authorid,A.Aname
5 having count(C.Authorid)>=2;

AUTHORID ANAME
---------- ---------------
4000 Tennenbaum

***** 2nd query *****

SQL> create view salesdetails as(


Select OD.Bookid as Book#,C.Price as Cost,Sum(OD.quantity) as Qty,
sum(OD.quantity*C.price) as sales
from Order_details OD,Catalog C,Author A
where OD.Bookid=C.Bookid and C.Authorid=A.Authorid
group by OD.Bookid,C.Price);

View created.

SQL> select A.Authorid,A.Aname,S.Book#,S.Sales


from Author A,Catalog C,Salesdetails S
where A.Authorid=C.Authorid and S.Book#=C.Bookid and sales=(
select Max(Sales) from Salesdetails);

AUTHORID ANAME BOOK# SALES


---------- --------------- ---------- ----------
2000 Tony 789 150000

***** 3rd query *****

BEFORE:

SQL> select * from Catalog;

DBMS Lab Mannual 76


Dept of ISE SaIT

BOOKID TITLE AUTHORID PUBLISHERID CATEGORYID YEAR


---------- -------------------- ---------- ----------- ---------- ----------
PRICE
----------
123 DSC 1000 33 2 2000
185

456 Networks 4000 44 4 2002


365

789 VB6 2000 11 2 2000


300

BOOKID TITLE AUTHORID PUBLISHERID CATEGORYID YEAR


---------- -------------------- ---------- ----------- ---------- ----------
PRICE
----------
213 Frontpage2002 4000 44 5 2003
500

879 ADA 1000 33 4 2001


195

SQL> update catalog


2 set price=price*1.10
3 where publisherid=33;

2 rows updated.

AFTER:

SQL> select * from catalog;

BOOKID TITLE AUTHORID PUBLISHERID CATEGORYID YEAR


---------- -------------------- ---------- ----------- ---------- ----------
PRICE
----------
123 DSC 1000 33 2 2000
204

456 Networks 4000 44 4 2002


365

DBMS Lab Mannual 77


Dept of ISE SaIT

789 VB6 2000 11 2 2000


300

BOOKID TITLE AUTHORID PUBLISHERID CATEGORYID YEAR PRICE


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

213 Frontpage2002 4000 44 5 2003 213


500 ADA 1000 33 4 2001 215

AUTHOR FORM

EXIT BUTTON
Private Sub cmdexit_Click()
Unload Me
End Sub

DBMS Lab Mannual 78


Dept of ISE SaIT

NEW BUTTON
Private Sub cmdnew_Click()
txtauthorid = getrecordno("author", "authorid")
End Sub

SAVE BUTTON
Private Sub cmdsave_Click()
checkdata
If check = False Then
db.BeginTrans
sql = "insert into author values(" & txtauthorid & ",'" & txtename "','" & txtcity,”’
&txtcountry"')"
db.Execute sql
db.CommitTrans
clear
refreshgrid
MsgBox "record successfully saved"
End If
End Sub

DELETE BUTTON
Private Sub cmddelete_Click()
checkdata1
If check = False Then
checkchild
If check = False Then
db.BeginTrans
sql = "delete from author where authorid='" & txtauthorid & "'"
db.Execute sql
db.CommitTrans
clear
refreshgrid
MsgBox "record successfully deleted"
End If
Else
Exit Sub
End If
End Sub

Private Sub checkchild()


Dim rec As New ADODB.Recordset
sql = "select * from author where authorid=" & txtauthorid & ""
rec.Open sql, db, adOpenStatic, adLockReadOnly
If Not rec.EOF Then
MsgBox "child record found not possible to delete"
check = True

DBMS Lab Mannual 79


Dept of ISE SaIT

Exit Sub
Else
check = False
End If
End Sub
CANCEL BUTTON
Private Sub cmdcancel_Click()
txtauthorid=””
txtename = ""
txtcity = ""
txtcountry=””
End Sub
AUTHOR REPORT

Author ID NAME CITY COUNTRY

100 JD CA USA

200 FO MA USA

300 EC NJ USA

400 MOF NY USA

500 COL MA USA

DBMS Lab Mannual 80


Dept of ISE SaIT

BANKING
DATABASE

DBMS Lab Mannual 81


Dept of ISE SaIT

5. Consider the following database for a banking enterprise


BRANCH(branch-name:string,branch-city:string,assets:real)
ACCOUNT(accno:int,branch-name:string,balance:real)
DEPOSITOR(customer-name:string,accno:int)
CUSTOMER(customer-name:string,customer-street:string,city:string)
LOAN(loan-number:int,branch-name:string,loan-number-int)
BORROWER(customer-name:string,customer-street:string,city:string)
1) create the above tables by properly specifying the primary and foreign keys
2) enter 5 tuples for each relation
3) find all the customers who have atleast two accounts at the main branch
4) find all the customers who have an account at all the branches located in a
specified city
5) demonstrate how you delete all account tuples at every branch located in a
specified city
6) genetration of suitable reports
7) create suitable front end for querying and display the results

SQL> create table branch(


2 branchname varchar(15),
3 branchcity varchar(15),
4 assets real,
5 primary key (branchname));

Table created.

SQL> create table accnt(


2 accountno integer,
3 branchname varchar(15),
4 balance real,
5 primary key (accountno),
6 foreign key (branchname) references branch(branchname));

DBMS Lab Mannual 82


Dept of ISE SaIT

Table created.

SQL> create table depositor(


2 customername varchar(15),
3 accountno integer,
4 primary key (customername,accountno),
5 foreign key (accountno) references accnt(accountno));

Table created.

SQL> create table custmer(


2 customername varchar(15),
3 customerstreet varchar(15),
4 city varchar(15),
5 primary key (customername));

Table created.

SQL> create table loan(


2 loanno integer,
3 branchname varchar(15),
4 amount real,
5 primary key (loanno),
6 foreign key (branchname) references branch(branchname));

Table created.

SQL> create table borrower(


2 customername varchar(15),
3 loanno integer,
4 primary key (customername,loanno),
5 foreign key (customername) references custmer(customername),
6 foreign key (loanno) references loan(loanno));

Table created.

SQL> desc branch;


Name Null? Type
----------------------------------------- -------- ----------------------------
BRANCHNAME NOT NULL VARCHAR2(15)
BRANCHCITY VARCHAR2(15)
ASSETS NUMBER(63)

SQL> insert into branch values('Jayanagar','Bangalore','15000000');

DBMS Lab Mannual 83


Dept of ISE SaIT

1 row created.

SQL> insert into branch values('Basavanagudi','Bangalore','25000000');

1 row created.

SQL> insert into branch values('Noida','NewDelhi','50000000');

1 row created.

SQL> insert into branch values('Marinedrive','Mumbai','40000000');

1 row created.

SQL> insert into branch values('GreenPark','Newdelhi','30000000');

1 row created.

SQL> select * from branch;

BRANCHNAME BRANCHCITY ASSETS


--------------- --------------- ----------
Jayanagar Bangalore 15000000
Basavanagudi Bangalore 25000000
Noida NewDelhi 50000000
Marinedrive Mumbai 40000000
GreenPark Newdelhi 30000000

SQL> desc accnt;


Name Null? Type
----------------------------------------- -------- ---------------
ACCOUNTNO NOT NULL NUMBER(38)
BRANCHNAME VARCHAR2(15)
BALANCE NUMBER(63)

SQL> insert into accnt values('123','Jayanagar','25000');

1 row created.

SQL> insert into accnt values('156','Jayanagar','30000');

1 row created.

SQL> insert into accnt values('456','Basavanagudi','15000');

1 row created.

DBMS Lab Mannual 84


Dept of ISE SaIT

SQL> insert into accnt values('789','Noida','25000');

1 row created.

SQL> insert into accnt values('478','Marinedrive','48000');

1 row created.

SQL> insert into accnt values('778','GreenPark','60000');

1 row created.

SQL> insert into accnt values('189','Basavanagudi','48888');

1 row created.

SQL> select * from accnt;

ACCOUNTNO BRANCHNAME BALANCE


---------- --------------- ----------
123 Jayanagar 25000
156 Jayanagar 30000
456 Basavanagudi 15000
789 Noida 25000
478 Marinedrive 48000
778 GreenPark 60000
189 Basavanagudi 48888

7 rows selected.

SQL> desc custmer;


Name Null? Type
----------------------------------------- -------- ----------------------------
CUSTOMERNAME NOT NULL VARCHAR2(15)
CUSTOMERSTREET VARCHAR2(15)
CITY VARCHAR2(15)

SQL> insert into custmer values('Ramu','Jayanagar','Bangalore');

1 row created.

SQL> insert into custmer values('Kumar','Basavanagudi','Bangalore');

1 row created.

DBMS Lab Mannual 85


Dept of ISE SaIT

SQL> insert into custmer values('John','Noida','Newdelhi');

1 row created.

SQL> insert into custmer values('Mike','Marinedrive','Mumbai');

1 row created.

SQL> insert into custmer values('Sachin','GreenPark','NewDelhi');

1 row created.

SQL> select * from custmer;

CUSTOMERNAME CUSTOMERSTREET CITY


--------------- --------------- ---------------
Ramu Jayanagar Bangalore
Kumar Basavanagudi Bangalore
John Noida Newdelhi
Mike Marinedrive Mumbai
Sachin GreenPark NewDelhi

SQL> desc depositor;


Name Null? Type
----------------------------------------- -------- ----------------------------
CUSTOMERNAME NOT NULL VARCHAR2(15)
ACCOUNTNO NOT NULL NUMBER(38)

SQL> insert into depositor values('Ramu',123);

1 row created.

SQL> insert into depositor values('Ramu',156);

1 row created.

SQL> insert into depositor values('Ramu',189);

1 row created.

SQL> insert into depositor values('Kumar',456);

1 row created.

DBMS Lab Mannual 86


Dept of ISE SaIT

SQL> insert into depositor values('John',789);

1 row created.

SQL> insert into depositor values('Mike',478);

1 row created.

SQL> insert into depositor values('Sachin',778);

1 row created.

SQL> select * from depositor;

CUSTOMERNAME ACCOUNTNO
--------------- ----------
Ramu 123
Ramu 156
Ramu 189
Kumar 456
John 789
Mike 478
Sachin 778

7 rows selected.

SQL> desc loan;


Name Null? Type
----------------------------------------- -------- ----------------------------
LOANNO NOT NULL NUMBER(38)
BRANCHNAME VARCHAR2(15)
AMOUNT NUMBER(63)

SQL> insert into loan values('1111','Jayanagar','250000');

1 row created.

SQL> insert into loan values('2222','Basavanagudi','350000');

1 row created.

SQL> insert into loan values('3333','Noida','150000');

1 row created.

SQL> insert into loan values('4444','Marinedrive','1500000');

DBMS Lab Mannual 87


Dept of ISE SaIT

1 row created.

SQL> insert into loan values('5555','GreenPark','7500000');

1 row created.

SQL> select * from loan;

LOANNO BRANCHNAME AMOUNT


---------- --------------- ----------
1111 Jayanagar 250000
2222 Basavanagudi 350000
3333 Noida 150000
4444 Marinedrive 1500000
5555 GreenPark 7500000

SQL> desc borrower;


Name Null? Type
----------------------------------------- -------- ---------------------------
CUSTOMERNAME NOT NULL VARCHAR2(15)
LOANNO NOT NULL NUMBER(38)

SQL> insert into borrower values('Ramu',1111);

1 row created.

SQL> insert into borrower values('Kumar',2222);

1 row created.

SQL> insert into borrower values('John',3333);

1 row created.

SQL> insert into borrower values('Mike',4444);

1 row created.

SQL> insert into borrower values('Sachin',5555);

1 row created.

SQL> select * from borrower;

CUSTOMERNAME LOANNO

DBMS Lab Mannual 88


Dept of ISE SaIT

--------------- ----------
Ramu 1111
Kumar 2222
John 3333
Mike 4444
Sachin 5555

***** 1st query *****

SQL> select customername


2 from Depositor D,Accnt A
3 where D.accountno=A.accountno and
4 branchname='Jayanagar'
5 having count(D.accountno)>=2
6 group by customername;

CUSTOMERNAME
---------------
Ramu

***** 2nd query *****

SQL> select customername


2 from Branch B,Accnt A,Depositor D
3 where B.Branchname=A.Branchname and
4 A.Accountno=D.Accountno and
5 B.Branchcity='Bangalore'
6 having count(distinct B.Branchname)=(Select
7 count(Branchname)
8 from Branch
9 where Branchcity='Bangalore')
10 group by customername;

CUSTOMERNAME
---------------
Ramu

***** 3rd query *****

delete from ACCOUNT


where BNAME in ( select BNAME
from BRANCH
where BCITY = '&CITY' ) ;

DBMS Lab Mannual 89


Dept of ISE SaIT

BRANCH FORM

Dim con As New ADODB.Connection

DBMS Lab Mannual 90


Dept of ISE SaIT

DELETE
Private Sub cmddelete_Click()
con.BeginTrans
con.Execute "delete from branch where br_name='" & txtbr_name & "'"
con.CommitTrans
txtbr_name = ""
txtbr_city = ""
txtassets = ""
MsgBox "record successfully deleted"
End Sub

INSERT
Private Sub cmdinsert_Click()
con.BeginTrans
con.Execute "insert into branch values('" & txtbr_name & "','" & txtbr_city & "'," &
txtassets & ")"
con.CommitTrans
txtbr_name = ""
txtbr_city = ""
txtassets = ""
MsgBox "record successfully inserted"
End Sub

QUIT
Private Sub cmdquit_Click()
MsgBox "end"
End Sub

DBMS Lab Mannual 91


Dept of ISE SaIT

BRANCH REPORT

DBMS Lab Mannual 92


Dept of ISE SaIT

DBMS Lab Mannual 93

Potrebbero piacerti anche