dbms lab manual (06 csl 57)

120
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

Upload: suddensmoker

Post on 22-Nov-2014

195 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Dbms Lab Manual (06 Csl 57)

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

Page 2: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

INSURANCE DATABASE

DBMS Lab Mannual 2

Page 3: Dbms Lab Manual (06 Csl 57)

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

Page 4: Dbms Lab Manual (06 Csl 57)

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

Page 5: Dbms Lab Manual (06 Csl 57)

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 Jayanagar2222 Manu Rajajinagar3333 Pandit Indiranagar4444 Gopal BTMLayout5555 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

Page 6: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

--------- --------------- ----------KA04Q2301 Maruthi 2000KA05P1000 Ford 2002KA03L1234 Honda 1999KA03L9999 Tata 2002KA01P4026 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 KA04Q23012222 KA05P10003333 KA03L12344444 KA03L99995555 KA01P4026

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

DBMS Lab Mannual 6

Page 7: Dbms Lab Manual (06 Csl 57)

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

Page 8: Dbms Lab Manual (06 Csl 57)

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 20002222 KA05P1000 25 150003333 KA03L1234 512 155004444 KA03L9999 1024 200005555 KA01P4026 1000 5000

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

BEFORE:

SQL> select * from Participated;

DRIVERID REGNO REPORTNO DAMAGEAMOUNT--------------- --------- ---------- ------------1111 KA04Q2301 12 20002222 KA05P1000 25 150003333 KA03L1234 512 155004444 KA03L9999 1024 200005555 KA01P4026 1000 5000

SQL> update Participated 2 set Damageamount=25000 3 where Regno='KA04Q2301' and Reportno=12;

1 row updated.

DBMS Lab Mannual 8

Page 9: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

AFTER:

SQL> select * from Participated;

DRIVERID REGNO REPORTNO DAMAGEAMOUNT--------------- --------- ---------- ------------1111 KA04Q2301 12 250002222 KA05P1000 25 150003333 KA03L1234 512 155004444 KA03L9999 1024 200005555 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 Jayanagar2222 Manu Rajajinagar3333 Pandit Indiranagar4444 Gopal BTMLayout5555 Lalit Whitefield6666 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 2000KA05P1000 Ford 2002KA03L1234 Honda 1999KA03L9999 Tata 2002KA01P4026 Toyota 2003KA052005 BMW 2005

DBMS Lab Mannual 9

Page 10: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

6 rows selected.

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

1 row created.

SQL> select * from owns;

DRIVERID REGNO--------------- ---------1111 KA04Q23012222 KA05P10003333 KA03L12344444 KA03L99995555 KA01P40266666 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

Page 11: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

2222 KA05P1000 25 150003333 KA03L1234 512 155004444 KA03L9999 1024 200005555 KA01P4026 1000 50006666 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

Page 12: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

PERSON FORM

DBMS Lab Mannual 12

Page 13: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

DECLARATION

Dim rptcon As ADODB.ConnectionDim rs As New ADODB.RecordsetDim rs1 As New ADODB.RecordsetDim check As String

COMMAND BUTTONS

CANCEL BUTTONPrivate Sub cmdcancel_Click()txtname = ""txtaddr = ""End Sub

DELETE BUTTONPrivate Sub cmddelete_Click()

Dim VBYES As StringVBYES = MsgBox("DO YOU WANT TO DELETE THE SELECTED RECORD", vbYesNo)If VBYES = "6" ThencheckchildIf check = False Thendb.BeginTranssql = "DELETE FROM person WHERE driverid= " & txtdr_id & ""db.Execute sqldb.CommitTransrefreshrecordclearMsgBox "RECORD DELETED"End IfElseExit SubEnd IfEnd Sub

Private Sub checkchild()Dim rec As New ADODB.Recordsetsql = "select * from owns where driverid='" & txtdr_id & "'"rec.Open sql, db, adOpenStatic, adLockReadOnly

DBMS Lab Mannual 13

Page 14: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

If Not rec.EOF ThenMsgBox "child record found not possible to delete"check = TrueExit SubElsecheck = FalseEnd IfEnd Sub

EXIT BUTTONPrivate Sub cmdexit_Click()Unload MeEnd Sub

SAVE BUTTONPrivate Sub cmdsave_Click()checkdataIf check = False Then

db.BeginTranssql = "insert into person values("sql = sql & txtdr_id & ""sql = sql & ",'" & txtname & "'"sql = sql & ",'" & txtaddr & "'"sql = sql & ")"db.Execute sqldb.CommitTransrefreshrecordclearMsgBox "RECORD SUCCESSFULLY INSERTED"

End IfEnd Sub

NEW BUTTONPrivate Sub cmdnew_Click()Dim dr_id As Integercleartxtdr_id = getrecordno("person", "driverid")End Sub

FUNCTION TO AUTO GENERATE DRIVER_IDPrivate Function getrecordno(tlb As String, recordno As String)Dim rs As New ADODB.Recordsetsql = "select * from " & tlb & " order by " & recordno & " desc"rs.Open sql, db, adOpenStatic, adLockReadOnlyIf Not rs.EOF Then

rs.MoveFirst

DBMS Lab Mannual 14

Page 15: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

recordno = rs!driverid + 1getrecordno = recordno

Elserecordno = 1getrecordno = recordno

End IfEnd Function

RECORD NAVIGATION BUTTONS

MOVE NEXT BUTTONPrivate Sub cmdnext_Click()If rs1.BOF Then

rs1.MoveNextEnd If

txtdr_id = rs1!driveridtxtname = rs1!Nametxtaddr = rs1!addressrs1.MoveNext

If rs1.EOF Thencmdnext.Enabled = Falsecmdprev.Enabled = TrueExit Sub

End IfEnd Sub

MOVE PREVIOUS BUTTONPrivate Sub cmdprev_Click()rs1.MovePreviousIf rs1.BOF Then

cmdprev.Enabled = Falsecmdnext.Enabled = TrueExit Sub

End Iftxtdr_id = rs1!driveridtxtname = rs1!Nametxtaddr = rs1!addresscmdnext.Enabled = True

End Sub

MOVE LAST BUTTONPrivate Sub cmdlast_Click()rs1.MoveLasttxtdr_id = rs1!driveridtxtname = rs1!Name

DBMS Lab Mannual 15

Page 16: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

txtaddr = rs1!addresscmdnext.Enabled = Falsecmdfirst.Enabled = Truecmdprev.Enabled = TrueEnd Sub

MOVE FIRST BUTTONPrivate Sub cmdfirst_Click()rs1.MoveFirsttxtdr_id = rs1!driveridtxtname = rs1!Nametxtaddr = rs1!addresscmdfirst.Enabled = Falsecmdprev.Enabled = Falsecmdnext.Enabled = Truecmdlast.Enabled = TrueEnd Sub DATAGRID FOR RECORD SELECTIONPrivate Sub DataGrid1_Click()On Error GoTo errorhandlertxtdr_id.Text = DataGrid1.Columns(0).Texttxtname.Text = DataGrid1.Columns(1).Texttxtaddr.Text = DataGrid1.Columns(2).Texterrorhandler:If Err.Number = "6160" ThenMsgBox "no record to select"End IfEnd Sub

FORM LOAD SUB FUNCTIONPrivate Sub Form_Load()sql = "select * from person"rs1.Open sql, db, adOpenStatic, adLockReadOnlyEnd Sub

REFRESH- DATAGRIDPrivate Sub refreshrecord()sql = "select * from person"Adodc2.RecordSource = sqlAdodc2.RefreshEnd Sub

Private Sub clear()txtdr_id = ""txtname = ""

DBMS Lab Mannual 16

Page 17: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

txtaddr = ""End Sub

FIELD VALIDATIONPrivate Sub checkdata()If txtdr_id = "" Then

MsgBox "PLEASE ENTER THE DRIVER ID"check = Truetxtdr_id.SetFocusExit Sub

Elsecheck = False

End If

If txtname = "" ThenMsgBox "PLEASE ENTER THE NAME OF THE PERSON"check = Truetxtname.SetFocusExit Sub

Elsecheck = False

End If

If txtaddr = "" ThenMsgBox "PLEASE ENTER THE ADDRESS"check = Truetxtaddr.SetFocusExit Sub

Elsecheck = False

End IfEnd Sub

MENUPrivate Sub mnuaccidentdetails_Click()frmaccident.ShowEnd Sub

Private Sub mnucardetails_Click()frmcar.ShowEnd Sub

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

DBMS Lab Mannual 17

Page 18: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

carsrpt.ShowEnd Sub

Private Sub mnuowns_Click()frmowns.ShowEnd Sub

Private Sub mnuparticipated_Click()frmparticipated.ShowEnd Sub

Private Sub mnupersonrpt_Click()Set rs = db.Execute("select * from person")Set personrpt.DataSource = rspersonrpt.ShowEnd Sub

Private Sub mnutransfer_Click()frmtransfer.ShowEnd Sub

DBMS Lab Mannual 18

Page 19: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

PERSON REPORT

DBMS Lab Mannual 19

Page 20: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

CAR FORM

Dim check As StringPrivate Sub cmdcancel_Click()txtregn = ""txtmodel = ""End Sub

DELETE BUTTONPrivate Sub cmddelete_Click()

DBMS Lab Mannual 20

Page 21: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

Dim str As Stringstr = MsgBox("are you sure you want to delete the selected record", vbYesNo)If str = 6 ThencheckchildIf check = False Thendb.BeginTransdb.Execute "delete from car where regno='" & txtregn & "'"db.CommitTransclearrefreshrecordMsgBox "record deleted"End IfElseExit SubEnd IfEnd Sub

Private Sub checkchild()Dim rec As New ADODB.Recordsetsql = "select * from owns where regno='" & txtregn & "'"rec.Open sql, db, adOpenStatic, adLockReadOnlyIf Not rec.EOF ThenMsgBox "child record found not possible to delete"check = TrueExit SubElsecheck = FalseEnd IfEnd Sub

EXIT BUTTONPrivate Sub cmdexit_Click()Unload MeEnd Sub

NEW BUTTONPrivate Sub cmdnew_Click()Dim regn_no As Integertxtregn = getrecordno1("car", "regno")txtmodel = ""End Sub

BUTTONSAVE Private Sub cmdsave_Click()checkdataIf check = False Then

DBMS Lab Mannual 21

Page 22: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

db.BeginTranssql = "insert into car values("sql = sql & "'" & txtregn & "'"sql = sql & ",'" & txtmodel & "'"sql = sql & "," & txtyear & ""sql = sql & ")"db.Execute sqldb.CommitTransrefreshrecordclearMsgBox "RECORD SUCCESSFULLY INSERTED"

End IfEnd Sub

DATAGRID FOR RECORD SELECTIONPrivate Sub DataGrid1_Click()On Error GoTo errorhandlertxtregn = DataGrid1.Columns(0).Texttxtmodel = DataGrid1.Columns(1).Texttxtyear = DataGrid1.Columns(2).Texterrorhandler:If Err.Number = "6160" ThenMsgBox "no record to select"End IfEnd Sub

FORM LOAD SUB FUNCTIONPrivate Sub Form_Load()txtyear = Format(Now, "yyyy")End Sub

Private Function getrecordno1(tlb As String, regn_no As String)Dim rs As New ADODB.Recordsetsql = "select * from " & tlb & " order by " & regn_no & " desc"rs.Open sql, db, adOpenStatic, adLockReadOnlyIf Not rs.EOF Then

rs.MoveFirst recordno = rs!regno + 1 getrecordno1 = recordnoElse

recordno = 1getrecordno1 = recordno

End IfEnd Function

FIELD VALIDATION

DBMS Lab Mannual 22

Page 23: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

Private Sub checkdata()If txtregn = "" Then

MsgBox "PLEASE ENTER THE regn_no"check = Truetxtregn.SetFocusExit Sub

Elsecheck = False

End If

If txtmodel = "" ThenMsgBox "PLEASE ENTER THE model"check = Truetxtmodel.SetFocusExit Sub

Elsecheck = False

End IfEnd Sub

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

Private Sub refreshrecord()sql = "select * from car"Adodc1.RecordSource = sqlAdodc1.RefreshEnd Sub

SEARCH ON REGN_NOPrivate Sub txtsearch_Change()sql = "select * from car where regno like '" & txtsearch & "%'"Adodc1.RecordSource = sqlAdodc1.RefreshEnd Sub

DBMS Lab Mannual 23

Page 24: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

CAR REPORT

CAR DETAILS

DBMS Lab Mannual 24

REGNO MODEL YEAR

Ka05 4993 ford 2000

Ka03 3992 mustang 1999

Ka02 5662 ferrari 2001

Ka05 3456 fiat 2000

Ka 4567 renault 2001

Page 25: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

OWNS FORM

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

DELETE BUTTONPrivate Sub cmddelete_Click()

DBMS Lab Mannual 25

Page 26: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

Adodc4.RecordSource = "select car.regno,car.model,car.year from car,owns where owns.driverid='" & txtdr_id & "'"Adodc4.RefreshEnd Sub

EXIT BUTTONPrivate Sub cmdexit_Click()Unload MeEnd Sub

SAVE BUTTONPrivate Sub cmdsave_Click()db.BeginTransdb.Execute "insert into owns values(" & txtdr_id & ",'" & txtregn & "')"db.CommitTransclearrefreshgridMsgBox "CAR SUCCESSFULLY OWNED"End Sub

DATAGRID FOR RECORD SELECTION OF PERSON DETAILSPrivate Sub DataGrid1_Click()On Error GoTo errorhandlertxtdr_id.Text = DataGrid1.Columns(0).Texttxtname.Text = DataGrid1.Columns(1).Texttxtaddr.Text = DataGrid1.Columns(2).Texterrorhandler:MsgBox "no record to select"Exit SubEnd Sub

DATAGRID FOR RECORD SELECTION OF CAR DETAILSPrivate Sub DataGrid2_Click()'On Error GoTo errorhandlerIf DataGrid2.RecordSelectors = "false" Then

MsgBox "no records to dispaly"Exit Sub

End Iftxtregn = DataGrid2.Columns(0).Texttxtmodel = DataGrid2.Columns(1).Texttxtyear = DataGrid2.Columns(2).Text

End Sub

DBMS Lab Mannual 26

Page 27: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

FORM LOAD SUB FUNCTIONPrivate Sub Form_Load()Dim rs As New ADODB.RecordsetEnd Sub

REFRESH- DATAGRIDPrivate Sub refreshgrid()sql = "select car.regno,car.model,car.year from car where regno Not in (select regno from owns)"Adodc2.RecordSource = sqlAdodc2.RefreshDataGrid2.RefreshEnd Sub

Private Sub clear()txtdr_id = ""txtname = ""txtaddr = ""txtregn = ""txtmodel = ""txtyear = ""End Sub

SEARCH BY DRIVER_IDPrivate Sub txtsearchdr_id_Change()sql = "select * from person where driverid like '" & txtsearchdr_id & "%'"Adodc1.RecordSource = sqlAdodc1.RefreshDataGrid1.RefreshEnd Sub

SEARCH BY REGN_NOPrivate 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 = sqlAdodc2.RefreshEnd Sub

DBMS Lab Mannual 27

Page 28: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

OWNS REPORT

DBMS Lab Mannual 28

Page 29: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

ACCIDENT FORM

Dim check As StringPrivate Function getrecordno(tlb As String, rep As String)Dim rs As New ADODB.RecordsetDim recordno As Integersql = "select * from " & tlb & " order by " & rep & " desc"rs.Open sql, db, adOpenStatic, adLockReadOnlyIf Not rs.EOF Thenrs.MoveFirstrecordno = rs!reportno + 1

DBMS Lab Mannual 29

Page 30: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

getrecordno = recordnoElserecordno = 1getrecordno = recordnoEnd IfEnd Function

DELETE BUTTONPrivate Sub cmddelete_Click()checkdata1If check = False ThencheckchildIf check = False Thendb.BeginTranssql = "delete from accident where rep_no='" & txtrepno & "'"db.Execute sqldb.CommitTransclearrefreshgridMsgBox "record successfully deleted"End IfElseExit SubEnd IfEnd Sub

Private Sub checkchild()Dim rec As New ADODB.Recordsetsql = "select * from participated where reportno=" & txtrepno & ""rec.Open sql, db, adOpenStatic, adLockReadOnlyIf Not rec.EOF ThenMsgBox "child record found not possible to delete"check = TrueExit SubElsecheck = FalseEnd IfEnd Sub

EXIT BUTTONPrivate Sub cmdexit_Click()Unload MeEnd Sub

NEW BUTTON

DBMS Lab Mannual 30

Page 31: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

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

SAVE BUTTONPrivate Sub cmdsave_Click()checkdataIf check = False Then

db.BeginTranssql = "insert into accident values(" & txtrepno & ",'" & cmbdate & "-" & cmbmon & "-" & cmbyear & "','" & txtloc & "')"db.Execute sqldb.CommitTransclearrefreshgridMsgBox "record successfully saved"

End IfEnd Sub

FIELD VALIDATIONS

Private Sub checkdata()Dim leap As Stringinsertyyyy

If txtrepno = "" ThenMsgBox "please enter the reprot number"txtrepno.SetFocuscheck = TrueExit Sub

Elsecheck = False

End If

If cmbdate = "" ThenMsgBox "please select the date"cmbdate.SetFocuscheck = TrueExit Sub

Elsecheck = False

End If

If cmbmon = "" ThenMsgBox "please select the month"cmbmon.SetFocus

DBMS Lab Mannual 31

Page 32: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

check = TrueExit Sub

Elsecheck = False

End If

If cmbyear = "" ThenMsgBox "please select the year"cmbyear.SetFocuscheck = TrueExit Sub

Elsecheck = False

End If

If cmbmon = "jan" Or cmbmon = "mar" Or cmbmon = "may" Or cmbmon = "jul" Or cmbmon = "aug" Or cmbmon = "oct" Or cmbmon = "dec" ThenIf Not cmbdate <= 31 Then

MsgBox "not a valid date"cmbdate.SetFocuscheck = TrueExit Sub

Elsecheck = False

End IfEnd If

If cmbmon = "apr" Or cmbmon = "jun" Or cmbmon = "sep" Or cmbmon = "nov" ThenIf Not cmbdate <= 30 Then

MsgBox "not a valid date"cmbdate.SetFocuscheck = TrueExit Sub

Elsecheck = False

End IfEnd 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

Page 33: Dbms Lab Manual (06 Csl 57)

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" ThenIf Not cmbdate <= 28 Then MsgBox "not a valid date" cmbdate.SetFocus check = True Exit Sub Else check = False End If End IfEnd If

If txtloc = "" ThenMsgBox "please enter the accident location"txtloc.SetFocuscheck = TrueExit Sub

Elsecheck = False

End IfEnd Sub

DATAGRID FOR RECORD SELECTIONPrivate Sub DataGrid1_Click()On Error GoTo errorhandlertxtrepno = DataGrid1.Columns(0).Texttxtadate = DataGrid1.Columns(1).Texttxtloc = DataGrid1.Columns(2).Texterrorhandler:If Err.Number = "6160" ThenMsgBox "no record to select"End IfEnd sub

Private Sub checkdata1()

DBMS Lab Mannual 33

Page 34: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

Dim vbstr As StringIf txtrepno = "" Then

MsgBox "please select the record you want to delete"check = TrueExit Sub

Elsecheck = False

End If

vbstr = MsgBox("are you sure you want to delete the selected record", vbYesNo)If vbstr = "6" Thencheck = FalseElsecheck = TrueEnd IfEnd Sub

REFRESH- DATAGRIDPrivate Sub refreshgrid()sql = "select * from accident"Adodc1.RecordSource = sqlAdodc1.RefreshDataGrid1.RefreshEnd SubPrivate Sub clear()

txtrepno = ""txtadate = ""txtloc = ""cmbdate = ""cmbmon = ""cmbyear = ""

End Sub

DBMS Lab Mannual 34

Page 35: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

ACCIDENT REPORT

Report -number

Date location

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

Page 36: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

PARTICIPATED FORM

Dim check As String

Private Sub cmbrepno_Click()Dim rs As New ADODB.Recordsetsql = "select dmg_amt from participated where reportno=" & cmbrepno & ""rs.Open sql, db, adOpenStatic, adLockReadOnlyIf Not rs.EOF Thentxtdmgamt = rs!dmg_amtEnd IfEnd Sub

DBMS Lab Mannual 36

Page 37: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

DELETE BUTTONPrivate Sub cmddelete_Click()checkdeleteIf check = False Thendb.BeginTransdb.Execute "delete from participated where driverid='" & txtdr_id & "' and regno='" & txtregno & "'and reportno='" & cmbrepno & "'"db.CommitTransclearMsgBox "selected record deleted"End IfEnd Sub

Private Sub checkdelete()Dim VBYES As StringIf txtdr_id = "" Or txtregno = "" ThenMsgBox "please select the record to delete"check = TrueExit SubElsecheck = FalseEnd If

VBYES = MsgBox("DO YOU WANT TO DELETE THE SELECTED RECORD", vbYesNo)If VBYES = "6" Thencheck = FalseElsecheck = TrueEnd IfEnd Sub

UPDATE BUTTONPrivate Sub cmdupdate_Click()If cmbrepno = "" ThenMsgBox "please select report to update"check = TrueExit SubElsecheck = FalseEnd IfIf check = False Thendb.BeginTransdb.Execute "update participated set dmg_amt=" & txtdmgamt & " where driverid='" & txtdr_id & "' and regno='" & txtregno & "'and reportno='" & cmbrepno & "' "

DBMS Lab Mannual 37

Page 38: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

db.CommitTransclearMsgBox "successfully updated"End IfEnd Sub

EXIT BUTTONPrivate Sub cmdexit_Click()Unload MeEnd Sub

NEW BUTTONPrivate Sub cmdnew_Click()Dim rs As New ADODB.Recordsettxtdmgamt = ""sql = "select reportno from accident where reportno not in (select reportno from participated)"rs.Open sql, db, adOpenStatic, adLockReadOnlycmbrepno.clearIf Not rs.EOF ThenDo Until rs.EOFcmbrepno.AddItem (rs!reportno)rs.MoveNextLoopElseForm_Loadtxtdmgamt = ""End IfEnd Sub

SAVE BUTTONPrivate Sub cmdsave_Click()checkdataIf check = False Thendb.BeginTransdb.Execute "insert into participated values('" & txtdr_id & "','" & txtregno & "'," & cmbrepno & "," & txtdmgamt & ")"db.CommitTransForm_LoadclearMsgBox "record successfully created"End IfEnd Sub

DBMS Lab Mannual 38

Page 39: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

DATAGRID FOR RECORD SELECTIONPrivate Sub DataGrid1_Click()On Error GoTo errorhandlerDim rs As New ADODB.RecordsetDim rs1 As New ADODB.Recordsettxtdr_id = DataGrid1.Columns(0).Texttxtregno = DataGrid1.Columns(1).Texttxtdmgamt = ""sql = "select reportno,dmg_amt from participated where driverid='" & txtdr_id & "' and regno='" & txtregno & "'"rs.Open sql, db, adOpenStatic, adLockReadOnlycmbrepno.clearIf Not rs.EOF ThenDo Until rs.EOFcmbrepno.AddItem (rs!reportno)rs.MoveNextLoopElseForm_Loadtxtdmgamt = ""End If

sql = "select * from participated where driverid='" & txtdr_id & "' and regno='" & txtregno & "'"rs1.Open sql, db, adOpenStatic, adLockReadOnlyIf Not rs1.EOF Thenlblstatus.Caption = "report exists"Elselblstatus.Caption = "report not found"End Iferrorhandler:If Err.Number = "6160" ThenMsgBox "no record to select"End IfEnd SubFORM LOAD SUB FUNCTIONPrivate Sub Form_Load()Dim rs As New ADODB.Recordsetsql = "select accident.reportno from accident where reportno Not in (select reportno from participated)"rs.Open sql, db, adOpenStatic, adLockReadOnlycmbrepno.clearIf Not rs.EOF ThenDo Until rs.EOFcmbrepno.AddItem (rs!reportno)rs.MoveNext

DBMS Lab Mannual 39

Page 40: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

LoopEnd Ifcmbrepno.RefreshEnd Sub

FIELD VALIDATIONSPrivate Sub checkdata()If txtdr_id = "" ThenMsgBox "please select the driverid"txtdr_id.SetFocuscheck = TrueExit SubElsecheck = FalseEnd If

If txtregno = "" ThenMsgBox "please select the regno"txtregno.SetFocuscheck = TrueExit SubElsecheck = FalseEnd If

If cmbrepno = "" ThenMsgBox "please select the report number"cmbrepno.SetFocuscheck = TrueExit SubElsecheck = FalseEnd If

If txtdmgamt = "" ThenMsgBox "please enter the damage amount"txtdmgamt.SetFocuscheck = TrueExit SubElsecheck = FalseEnd If

End SubPrivate Sub clear()txtdr_id = ""

DBMS Lab Mannual 40

Page 41: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

txtregno = ""cmbrepno = ""txtdmgamt = ""End SubPrivate Sub checkdelete()Dim VBYES As StringIf txtdr_id = "" Or txtregno = "" ThenMsgBox "please select the record to delete"check = TrueExit SubElsecheck = FalseEnd If

VBYES = MsgBox("DO YOU WANT TO DELETE THE SELECTED RECORD", vbYesNo)If VBYES = "6" Thencheck = FalseElsecheck = TrueEnd IfEnd Sub

DBMS Lab Mannual 41

Page 42: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

PARTICIPATED REPORT

DBMS Lab Mannual 42

Page 43: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

DELETE FORM

Private Sub cmbdr_id_Click()Dim rs As New ADODB.Recordsetcmbregno.clearsql = "select regno from owns where driverid='" & cmbdr_id & "'"rs.Open sql, db, adOpenStatic, adLockReadOnlyIf Not rs.EOF ThenDo Until rs.EOFcmbregno.AddItem (rs!regno)rs.MoveNextLoopEnd IfEnd Sub

DBMS Lab Mannual 43

Page 44: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

EXIT BUTTONPrivate Sub cmdexit_Click()Unload MeEnd Sub

TRANSFER BUTTONPrivate Sub cmdtransfer_Click()checkdataIf check = False Thendb.BeginTranssql = "delete from owns where driverid='" & cmbdr_id & "' and regno='" & cmbregno & "'"db.Execute sqldb.CommitTransclearMsgBox "successfully transfered"End IfEnd Sub

FORM LOAD SUB FUNCTIONPrivate Sub Form_Load()Dim rs As New ADODB.Recordsetsql = "select driverid from person"rs.Open sql, db, adOpenStatic, adLockReadOnlyIf Not rs.EOF ThenDo Until rs.EOFcmbdr_id.AddItem (rs!driverid)rs.MoveNextLoopEnd IfEnd SubPrivate Sub checkdata()If cmbdr_id = "" ThenMsgBox "please select the driver id"check = TrueExit SubElsecheck = FalseEnd If

If cmbregno = "" ThenMsgBox "please select the reg number"check = TrueExit SubElsecheck = False

DBMS Lab Mannual 44

Page 45: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

End IfEnd SubPrivate Sub clear()cmbdr_id = ""cmbregno = ""End Sub

ORDER PROCESSING

DATABASE

DBMS Lab Mannual 45

Page 46: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

2. Consider the following relations for an order processing database applications in a CompanyCUSTOMER(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 relation3) 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, 5 OrderAmount integer not null, 6 primary key (Orderno),

DBMS Lab Mannual 46

Page 47: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

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) CITY VARCHAR2(15)

DBMS Lab Mannual 47

Page 48: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

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);

1 row created.

DBMS Lab Mannual 48

Page 49: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

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.

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

DBMS Lab Mannual 49

Page 50: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

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);

1 row created.

DBMS Lab Mannual 50

Page 51: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

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.

SQL> select * from warehouse;

DBMS Lab Mannual 51

Page 52: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

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

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

DBMS Lab Mannual 52

Page 53: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

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 37500George 1 30000Jack 1 10000Kumar 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

Page 54: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

CUSTOMER FORM

EXIT BUTTONPrivate Sub cmdexit_Click()Unload MeEnd Sub

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

DBMS Lab Mannual 54

Page 55: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

SAVE BUTTONPrivate Sub cmdsave_Click()checkdataIf check = False Then

db.BeginTranssql = "insert into customer values(" & txtcustno & ",'" & txtename "','" & txtcity "')"db.Execute sqldb.CommitTransclearrefreshgridMsgBox "record successfully saved"

End IfEnd Sub

DELETE BUTTONPrivate Sub cmddelete_Click()checkdata1If check = False ThencheckchildIf check = False Thendb.BeginTranssql = "delete from customer where custno='" & txtcustno & "'"db.Execute sqldb.CommitTransclearrefreshgridMsgBox "record successfully deleted"End IfElseExit SubEnd IfEnd Sub

Private Sub checkchild()Dim rec As New ADODB.Recordsetsql = "select * from customer where custno=" & txtcustno & ""rec.Open sql, db, adOpenStatic, adLockReadOnlyIf Not rec.EOF ThenMsgBox "child record found not possible to delete"check = TrueExit SubElsecheck = FalseEnd IfEnd Sub

DBMS Lab Mannual 55

Page 56: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

CANCEL BUTTONPrivate Sub cmdcancel_Click()txtcustno=””txtename = ""txtcity = ""End Sub

CUSTOMER REPORT

DBMS Lab Mannual 56

CUSTOMER NO

CUSTOMERNAME

CITY

11 aaa bangalore

12 bbb Mysore

13 ccc bangalore

14 ddd hubli

15 eee mysore

Page 57: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

STUDENT DATABASE

DBMS Lab Mannual 57

Page 58: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

3. consider the following database of student enrollment in courses and books adopted for each courseSTUDENT(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 keys2) enter five tuples for each relation3) demonstrate how you add a new text book to the database and make this book be

adopted by some department4) produce a list of text books in alphabetical order for courses offered by CS

department that use more than two books5) list any department that has all its adopted books published by a specific publisher6) generation of suitable reports7) 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));

Table created.

DBMS Lab Mannual 58

Page 59: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

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');

1 row created.

DBMS Lab Mannual 59

Page 60: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

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-831BI02CS010 Karan CSE 02-JAN-841BI02EE015 Jack EEE 15-APR-831BI00CS010 Adi CSE 02-JAN-821BI01EC089 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.

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

DBMS Lab Mannual 60

Page 61: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

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---------- ---------- ---------- ----------1BI02CS010 22 5 72

DBMS Lab Mannual 61

Page 62: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

1BI00CS010 11 3 901BI01EC089 33 6 521BI01ME075 44 4 851BI02EE015 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

SQL> desc book_adoption;

DBMS Lab Mannual 62

Page 63: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

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 44 4 5566 44 7 3388

DBMS Lab Mannual 63

Page 64: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

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 2 from Course C,Book_adoption BA,Text T 3 where C.Courseno=BA.Courseno and BA.ISBN=T.ISBN and C.Dept='CSE'

DBMS Lab Mannual 64

Page 65: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

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

Page 66: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

STUDENT FORM

EXIT BUTTONPrivate Sub cmdexit_Click()Unload MeEnd Sub

NEW BUTTONPrivate Sub cmdnew_Click()txtregno = getrecordno("student", "regno")

DBMS Lab Mannual 66

Page 67: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

End Sub

SAVE BUTTONPrivate Sub cmdsave_Click()checkdataIf check = False Then

db.BeginTranssql = "insert into student values(" & txtregno & ",'" & txtname "','" & txtmajor,’ “’&txtbdate "')"db.Execute sqldb.CommitTransclearrefreshgridMsgBox "record successfully saved"

End IfEnd Sub

DELETE BUTTONPrivate Sub cmddelete_Click()checkdata1If check = False ThencheckchildIf check = False Thendb.BeginTranssql = "delete from student where regno='" & txtregno & "'"db.Execute sqldb.CommitTransclearrefreshgridMsgBox "record successfully deleted"End IfElseExit SubEnd IfEnd Sub

Private Sub checkchild()Dim rec As New ADODB.Recordsetsql = "select * from student where regno=" & txtregno & ""rec.Open sql, db, adOpenStatic, adLockReadOnlyIf Not rec.EOF ThenMsgBox "child record found not possible to delete"check = TrueExit SubElsecheck = False

DBMS Lab Mannual 67

Page 68: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

End IfEnd Sub

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

DBMS Lab Mannual 68

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

Page 69: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

BOOK DEALER DATABASE

DBMS Lab Mannual 69

Page 70: Dbms Lab Manual (06 Csl 57)

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 keys2) enter atleast five tuples for each relation3) find the author of the book which has maximium sales4) demonstrate how you increase the price of books published by a specific publisher

by 10%5) generation of suitable reports6) 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, Description varchar(20),

DBMS Lab Mannual 70

Page 71: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

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

Page 72: Dbms Lab Manual (06 Csl 57)

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

Page 73: Dbms Lab Manual (06 Csl 57)

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 3 Hardware

DBMS Lab Mannual 73

Page 74: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

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 365

DBMS Lab Mannual 74

Page 75: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

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 195SQL> 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---------- ---------- ---------- 112 123 100

DBMS Lab Mannual 75

Page 76: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

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

Page 77: Dbms Lab Manual (06 Csl 57)

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

789 VB6 2000 11 2 2000

DBMS Lab Mannual 77

Page 78: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

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 BUTTONPrivate Sub cmdexit_Click()Unload MeEnd Sub

NEW BUTTON

DBMS Lab Mannual 78

Page 79: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

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

SAVE BUTTONPrivate Sub cmdsave_Click()checkdataIf check = False Then

db.BeginTranssql = "insert into author values(" & txtauthorid & ",'" & txtename "','" & txtcity,”’ &txtcountry"')"db.Execute sqldb.CommitTransclearrefreshgridMsgBox "record successfully saved"

End IfEnd Sub

DELETE BUTTONPrivate Sub cmddelete_Click()checkdata1If check = False ThencheckchildIf check = False Thendb.BeginTranssql = "delete from author where authorid='" & txtauthorid & "'"db.Execute sqldb.CommitTransclearrefreshgridMsgBox "record successfully deleted"End IfElseExit SubEnd IfEnd Sub

Private Sub checkchild()Dim rec As New ADODB.Recordsetsql = "select * from author where authorid=" & txtauthorid & ""rec.Open sql, db, adOpenStatic, adLockReadOnlyIf Not rec.EOF ThenMsgBox "child record found not possible to delete"check = TrueExit Sub

DBMS Lab Mannual 79

Page 80: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

Elsecheck = FalseEnd IfEnd SubCANCEL BUTTONPrivate Sub cmdcancel_Click()txtauthorid=””txtename = ""txtcity = ""txtcountry=””End Sub

AUTHOR REPORT

100 JD CA USA

200 FO MA USA

300 EC NJ USA

400 MOF NY USA

500 COL MA USA

DBMS Lab Mannual 80

Author ID NAME CITY COUNTRY

Page 81: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

BANKING DATABASE

DBMS Lab Mannual 81

Page 82: Dbms Lab Manual (06 Csl 57)

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 keys2) enter 5 tuples for each relation3) find all the customers who have atleast two accounts at the main branch4) find all the customers who have an account at all the branches located in a

specified city5) demonstrate how you delete all account tuples at every branch located in a

specified city6) genetration of suitable reports7) 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

Page 83: Dbms Lab Manual (06 Csl 57)

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');

1 row created.

DBMS Lab Mannual 83

Page 84: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

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 15000000Basavanagudi Bangalore 25000000Noida NewDelhi 50000000Marinedrive Mumbai 40000000GreenPark 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

Page 85: Dbms Lab Manual (06 Csl 57)

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

Page 86: Dbms Lab Manual (06 Csl 57)

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 BangaloreKumar Basavanagudi BangaloreJohn Noida NewdelhiMike Marinedrive MumbaiSachin 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.

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

DBMS Lab Mannual 86

Page 87: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

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 123Ramu 156Ramu 189Kumar 456John 789Mike 478Sachin 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

Page 88: Dbms Lab Manual (06 Csl 57)

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

Page 89: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

Ramu 1111Kumar 2222John 3333Mike 4444Sachin 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 ACCOUNTwhere BNAME in ( select BNAME

from BRANCH where BCITY = '&CITY' ) ;

DBMS Lab Mannual 89

Page 90: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

BRANCH FORM

Dim con As New ADODB.Connection

DELETE

DBMS Lab Mannual 90

Page 91: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

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

INSERTPrivate Sub cmdinsert_Click()con.BeginTranscon.Execute "insert into branch values('" & txtbr_name & "','" & txtbr_city & "'," & txtassets & ")"con.CommitTranstxtbr_name = ""txtbr_city = ""txtassets = ""MsgBox "record successfully inserted"End Sub

QUITPrivate Sub cmdquit_Click()MsgBox "end"End Sub

DBMS Lab Mannual 91

Page 92: Dbms Lab Manual (06 Csl 57)

Dept of ISE SaIT

BRANCH REPORT

DBMS Lab Mannual 92