0% found this document useful (0 votes)
10 views

Dbms Lab Manual

Uploaded by

varvind2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Dbms Lab Manual

Uploaded by

varvind2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 62

CS4451-DBMS Lab Department of CSE 2020-21

Ex.No.1 CREATION OF A DATABASE AND WRITING SQL QUERIES TO RETRIEVE


INFORMATION FROM THE DATABASE.

AIM:

To design and implement a database in Oracle using Structured Query Language commands

SYNTAX:

CREATE:

Create table <table name> (column name1 datatype1 constraints, column2 datatype2 . . .);

PROBLEM STATEMENT:

 A branch contain many account holder

 A branch provide more than one Loan

 A Loan can be availed by more than customer.

 A customer can get more than one Loan.

 A customer can have more than one account

 A account can have more than one customer

TABLE FROM THE PROBLEM STATEMENT

1) Branch

2) Account

3) Loan

4) Customer

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

Table name: Branch

Create table branch(branch_name varchar2(30) primary key, branch_city varchar2(20), assets number);

Table created.

desc branch;

Name Null? Type

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

BRANCH_NAME NOT NULL VARCHAR2(30)

BRANCH_CITY VARCHAR2(20)

ASSETS NUMBER

=============================================================================

Table name: Customer

create table customer(customer_id varchar2(10) primary key, customer_name varchar2(20), customer_Street


varchar2(15), customer_City varchar2(15));

Table created.

desc customer;

Name Null? Type

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

CUSTOMER_ID NOT NULL VARCHAR2(10)

CUSTOMER_NAME VARCHAR2(20)

CUSTOMER_STREET VARCHAR2(15)

CUSTOMER_CITY VARCHAR2(15)

=============================================================================

Table name: Account

create table account(account_no varchar2(10) primary key, branch_name varchar2(30), balance number);

Table created.

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

desc account;

Name Null? Type

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

ACCOUNT_NO NOT NULL VARCHAR2(10)

BRANCH_NAME VARCHAR2(30)

BALANCE NUMBER

=============================================================================

Table name: Loan

create table loan(loan_no varchar2(20) primary key, branch_name varchar2(20), amount number);

Table created.

desc loan_ma;

Name Null? Type

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

LOAN_NO NOT NULL VARCHAR2(4)

BRANCH_NAME VARCHAR2(20)

AMOUNT NUMBER

=============================================================================

RESULT:

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

Ex.No.2 PERFORMING INSERTION, DELETION, MODIFYING, ALTERING, UPDATING AND


VIEWING RECORDS BASED ON CONDITIONS.

AIM:

To implement and execute a query for manipulating & storing data items in a Oracle database using
Structured Query Language commands

DDL COMMANDS:
 Create
 Alter
 Add
 Modify
 Drop
 Rename
 Drop
ALTER:
ADD:
Alter table <table name> add(column name1 datatype1);
MODIFY:
Alter table <table name> modify(column name1 datatype1);
DROP:
Alter table <table name> drop (column name);
RENAME:
Rename <old table name> to <new table name>;
DROP:
Drop table <table name>;
DML Commands:
 Insert
 Select
 Update
 Delete
INSERT:
Insert into <table name> values (‘attributes1’, ’attributes2’……);
SELECT:
Select <column name> from <table name>;
UPDATE:
Update <table name> set <column name>=’values’;
DELETE:
Delete from <table name>;

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

1. Alter the table branch by increasing the field width of branch city to 25.

Alter table branch modify(branch_city varchar2(25));

Table altered.

desc branch;

Name Null? Type

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

BRANCH_NAME NOT NULL VARCHAR2(30)

BRANCH_CITY VARCHAR2(25)

ASSETS NUMBER

=============================================================================

2. Drop the primary key from loan table

alter table loan drop primary key;

Table altered.

=============================================================================

3. Add the primary key to loan table

alter table loan add(primary key(loan_no));

Table altered.

4. Add new column to loan table

alter table loan add(roi number);

Table altered.

=============================================================================

5. Drop the column from loan table

alter table loan drop(roi);

Table altered.

=============================================================================

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

6. Rename the customer table as customer1 table.

rename customer to customer1;

Table renamed.

desc customer1

Name Null? Type

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

CUSTOMER_ID NOT NULL VARCHAR2(10)

CUSTOMER_NAME VARCHAR2(20)

CUSTOMER_STREET VARCHAR2(15)

CUSTOMER_CITY VARCHAR2(15)

=============================================================================

7. Drop customer1 table.

drop table customer1;

Table dropped.

============================================================================
8. INSERTING RECORDS IN ALL THE FOUR CREATED TABLES:

SQL> insert into branch values('&branch_name','&branch_city',&assets);

Enter value for branch_name: tambaram


Enter value for branch_city: chennai-45
Enter value for assets: 50000

old 1 : insert into branch values('&branch_name','&branch_city',&assets)


new 1: insert into branch values('tambaram','chennai-45',50000)
1 row created.

insert into branch values('tambaram','chennai-45',50000)

insert into customer values('cus_109','mohammed','southeast_masi','chennai-32')

insert into account values('735_105','chrompet',5000)

insert into loan values('ln_106','saidapet',2000)

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

SQL> select * from branch;

BRANCH_NAME BRANCH_CITY ASSETS


--------------- -------------------- ---------------------------------------------------------
tambaram chennai-45 50000
adayar chennai-20 100000
tnagar chennai-17 250000
saidapet chennai-15 150000
chrompet chennai-43 450000
guindy chennai-32 150000
=============================================================================
9. Find the names of all branches in loan relation.

SQL> select branch_name from loan;

BRANCH_NAME
--------------------
guindy
adayar
tambaram
tambaram
adayar
saidapet
chrompet
7 rows selected.
=============================================================================
10. Find the names of all branches in loan relation eliminate duplicate.

SQL> select distinct branch_name from loan;

BRANCH_NAME
--------------------
adayar
chrompet
guindy
saidapet
tambaram
=============================================================================
11.Display the loan relation with attributes amount multiplied by 100.

SQL> select AMOUNT*100 from loan;

AMOUNT*100
--------------------
90000

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

150000
150000
130000
100000
200000
6 rows selected.
=============================================================================
12. Find all loan numbers for loan made at tambaram branch with loan amount greater than 1400.

SQL> select LOAN_NO from loan where BRANCH_NAME='tambaram' and AMOUNT>1400;

LOAN_NO
--------------------
ln_103
=============================================================================
13. Find all loan numbers for loan’s with loan amount between 900 and 1500.

SQL> select LOAN_NO from loan where amount between 900 and 1500;

LOAN_NO
--------------------
ln_101
ln_102
ln_103
ln_104
ln_105
=============================================================================
14. Find the names of customer whose street name includes the character r in the third position.

SQL> select customer_name from customer where customer_street like'__r%';

CUSTOMER_NAME
--------------------
suresh
gopal
Krishnan
=============================================================================
15. Find the names of customer whose street name starts with substring ‘so’.

SQL> select customer_name from customer where customer_street like'so%';

CUSTOMER_NAME
--------------------
selva
raja
mohammed
=============================================================================
16.Display the entire loan relation in descending order of amount.

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

SQL> Select * from loan order by amount desc;

LOAN_NO BRANCH_NAME AMOUNT


-------------------- -------------------- ----------------------------------------
ln_106 saidapet 2000
ln_102 adayar 1500
ln_103 tambaram 1500
ln_104 tambaram 1300
ln_105 adayar 1000
ln_101 guindy 900
ln_107 chrompet 500
=============================================================================
17. Find total number of customer.

SQL> select count(customer_id) from customer;

COUNT(CUSTOMER_ID)

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

=============================================================================

18. Find all the loan number that appears in the loan relation with NULL values for amount.

SQL> select LOAN_NO from loan where amount is null;

LOAN_NO

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

ln_108

=============================================================================

19. Update the branch city as Chennai-20 from Chennai-45 in the branch relation

SQL> update branch set BRANCH_CITY='chennai-20' where BRANCH_CITY='chennai-45';

1 row updated.

SQL> select * from branch;


BRANCH_NAME BRANCH_CITY ASSETS
--------------- -------------------- -------------------------------------------
tambaram chennai-20 50000
adayar chennai-20 100000
tnagar chennai-17 250000
saidapet chennai-15 150000
chrompet chennai-43 450000

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

guindy chennai-32 150000


=============================================================================

20. Show the effect of rollback command with an example.

SQL> delete from branch;

6 rows deleted.

SQL> select * from branch;

no rows selected

SQL> rollback;

Rollback complete.

SQL> select * from branch;

BRANCH_NAME BRANCH_CITY ASSETS


--------------- -------------------- -------------------------------------------
tambaram chennai-20 50000
adayar chennai-20 100000
tnagar chennai-17 250000
saidapet chennai-15 150000
chrompet chennai-43 450000
guindy chennai-32 150000

6 rows selected.

RESULT:

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

Ex.No.3 CREATION OF VIEWS, SYNONYMS, SEQUENCE, INDEXES, SAVE POINT.

AIM:

To implement and execute view, synonyms, sequence, indexes, savepoint in Oracle using Structured
Query Language commands

SYNTAX:

VIEWS:

CREATE VIEW <VIEWNAME> AS SELECT * FROM <TABLENAME> WHERE <CONDITION>;

SYNONYMS

CREATE SYNONYM <SYNONYMS NAME> FOR <TABLENAME>;

SEQUENCE

CREATE SEQUENCE<SEQUENCENAME> START WITH <VALUE> MINVALUE <VALUE>


INCREMENT BY <VALUE>;

INDEXES

CREATE [UNIQUE] INDEX INDEX_NAME ONTABLE_NAME(COLUMN_NAME[, COLUMN_NAM


E...]) TABLESPACE TABLE_SPACE;

SAVE POINT

SAVEPOINT <SAVEPOINT NAME>;

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

1) VIEWS:

Create a view using aggregate functions to calculate the age of the customer

SQL> create view cust_age as select CUSTOMER_ID,CUSTOMER_NAME,round((sysdate-


CUSTOMER_DOB)/365.25) as age from customer;

View created.

SQL> select * from cust_age;

CUSTOMER_ID CUSTOMER_NAME AGE


---------- -------------------- ---------------------------------------------
cus_101 suresh 28
cus_102 selva 26
cus_103 prem 26
cus_104 javid 36
cus_105 pradeep 26
cus_106 gopal 29
cus_107 raja 27
cus_108 krishnan 13
cus_109 mohammed 15

9 rows selected.
2) SYNONYMS

CREATING A SYNONYM FOR A TABLE

CREATE TABLE product (product_name VARCHAR2(25) PRIMARY KEY,


product_price NUMBER(4,2), quantity_on_hand NUMBER(5,0), last_stock_date DATE);

Table created.

AFTER INSERTING THE RECORDS TO PRODUCT TABLE

SQL> SELECT * FROM product;

PRODUCT_NAME PRODUCT_PRICE QUANTITY_ON_HAND LAST_STOC


------------------------- -------------------------- ------------------------------ ------------------
Product 1 99 1 15-JAN-03
Product 2 75 1000 15-JAN-02
Product 3 50 100 15-JAN-03
Product 4 25 10000 14-JAN-03
Product 5 9.95 1234 15-JAN-04

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

Product 6 45 1 31-DEC-08

6 rows selected.

SQL> SELECT * FROM prod;


SELECT * FROM prod
*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> CREATE SYNONYM prod FOR product;

Synonym created.

SQL> SELECT * FROM prod;


PRODUCT_NAME PRODUCT_PRICE QUANTITY_ON_HAND LAST_STOC
------------------------- -------------------------- ------------------------------ ------------------
Product 1 99 1 15-JAN-03
Product 2 75 1000 15-JAN-02
Product 3 50 100 15-JAN-03
Product 4 25 10000 14-JAN-03
Product 5 9.95 1234 15-JAN-04
Product 6 45 1 31-DEC-08

SQL> drop SYNONYM prod;

Synonym dropped.

SQL> drop table product;


Table dropped.
=======================================================================

3) SEQUENCE

create a sequence and design the student table with the given attributes.
SQL> create table student(student_id number, name varchar2(10),result varchar2(10));
SQL> desc student;
Name Null? Type
----------------------------------------- -------- -------------
STUDENT_ID NUMBER
NAME VARCHAR2(10)

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

RESULT VARCHAR2(10)
Sequence Creation
SQL> create sequence student_seq start with 100 minvalue 100 increment by 1;
Sequence created.
SQL> insert into student values(student_seq.nextval,'raja','pass');
1 row created.
SQL> insert into student values(student_seq.nextval,'ravi','pass');
1 row created.
SQL> select * from student;
STUDENT_ID NAME
---------- ---------- ----------
100 raja pass
101 ravi pass
4) INDEXES

To create an index on the Last Name column of the Employee table

SQL> create table Employee(ID VARCHAR2(4 BYTE) NOT NULL,


First_Name VARCHAR2(10 BYTE), Last_Name VARCHAR2(10 BYTE),
Start_Date DATE, End_Date DATE, Salary Number(8,2));

Table created.
SQL> select * from Employee

ID FIRST_NAME LAST_NAME START_DAT END_DATE SALARY


----- ----------------- ------------------ ----------------- --------------- -------------------
01 Jason Martin 25-JUL-96 25-JUL-06 1234.56
02 Alison Mathews 21-MAR-76 21-FEB-86 6661.78
03 James Smith 12-DEC-78 15-MAR-90 6544.78
04 Celia Rice 24-OCT-82 21-APR-99 2344.78
05 Robert Black 15-JAN-84 08-AUG-98 2334.78
6 rows selected.

SQL> CREATE INDEX LastNameIndex ON Employee (Last_Name);

Index created.

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

SQL> drop index LastNameIndex;

Index dropped.

5) SAVE POINT

SQL> select * from employees;

DEPARTMENT_ID DEPARTMENT_NAME
------------- ---------------
101 it
102 cse
103 mech
104 chemical
105 biotech
106 eee
6 rows selected.

SQL> savepoint s1;

Savepoint created.

SQL> insert into employees values(107,'ice');

1 row created.

SQL> savepoint s2;

Savepoint created.

SQL> select * from employees;

DEPARTMENT_ID DEPARTMENT_NAME
------------- ---------------
101 it
102 cse
103 mech

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

104 chemical
105 biotech
106 eee
107 ice

7 rows selected.

SQL> ROLLBACK TO SAVEPOINT s1;

Rollback complete.
SQL> select * from employees;

DEPARTMENT_ID DEPARTMENT_NAME
------------- ---------------
101 it
102 cse
103 mech
104 chemical
105 biotech
106 eee
6 rows selected.

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

RESULT:

Ex.No.4 CREATING A STUDENT DATABASE TO SET VARIOUS CONSTRAINTS.

AIM:

To Creating a Student database to set various constraints in Oracle using Structured Query Language
commands

VARIOUS CONSTRAINTS

Constraint
Constraint Meaning
Type
CHECK C Specifies a certain condition for a column, or group of columns.
NOT NULL C Not null column
PRIMARY KEY P primary key
FOREIGN KEY R foreign key
UNIQUE U unique
CHECK Specifies that DML operations on a view must satisfy the sub
V
OPTION query.
READ ONLY O Specifies that a view may only be read from.

TABLE NAME: STDUDENTDB

Column name Data Type Constraint


STUDENT_NO NUMBER PRIMARY KEY
STUDENT_NAME VARCHAR2(30) NOT NULL
STUDENT_EMAIL VARCHAR2(30) UNIQUE
STUDENT_PERCENTAGE NUMBER CHECK

STUDENT DATABASE

create table studentdb(student_no number primary key,student_name varchar2(30) not null,student_email


varchar2(20) unique,student_percentage number check(student_percentage<=100))

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

Table Created

SQL> desc studentdb;


Name Null? Type
----------------------------------------- -------- ----------------------------
STUDENT_NO NOT NULL NUMBER
STUDENT_NAME NOT NULL VARCHAR2(30)
STUDENT_EMAIL VARCHAR2(20)
STUDENT_PERCENTAGE NUMBER

1) PRIMARY KEY

CASE 1: (Redundant value cannot be accepted by the column)

SQL> insert into studentdb values(3123101,'rajan','rajan@gmail.com',76);

1 row created.

SQL> insert into studentdb values(3123101,'rajan','rajan@gmail.com',76);


insert into studentdb values(3123101,'rajan','rajan@gmail.com',76)
*
ERROR at line 1:

ORA-00001: unique constraint (SCOTT.SYS_C006201) violated

CASE 2: (Null value cannot be accepted by the column)

SQL> insert into studentdb values(null,'rajan','rajan@gmail.com',76);


insert into studentdb values(null,'rajan','rajan@gmail.com',76)
*
ERROR at line 1:

ORA-01400: cannot insert NULL into ("SCOTT"."STUDENTDB"."STUDENT_NO")

2) NOT NULL(Null value cannot be accepted by the column)

SQL> insert into studentdb values(3123102,'ravi','ravi@gmail.com',80);

1 row created.

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

SQL> insert into studentdb values(3123103,null,'hai@gmail.com',80);


insert into studentdb values(3123103,null,'hai@gmail.com',80)
*
ERROR at line 1:

ORA-01400: cannot insert NULL into ("SCOTT"."STUDENTDB"."STUDENT_NAME")

3) UNIQUE

CASE 1: (Redundant value cannot be accepted by the column)

SQL> insert into studentdb values(3123103,'ragu','ragu@gmail.com',90);

1 row created.

SQL> insert into studentdb values(3123104,'ragu1','ragu@gmail.com',45);


insert into studentdb values(3123104,'ragu1','ragu@gmail.com',45)
*
ERROR at line 1:
ORA-00001: unique constraint (SCOTT.SYS_C006202) violated

CASE 2: (More than one null value can be accepted by the column)

SQL> insert into studentdb values(3123104,'ragu1',null,67);

1 row created.

SQL> insert into studentdb values(3123105,'ragu2',null,98);

1 row created.

4)CHECK (User defined condition)

SQL> insert into studentdb values(3123106,'ragu3','ragu3@gmail.com',101);


insert into studentdb values(3123106,'ragu3','ragu3@gmail.com',101)
*
ERROR at line 1:
ORA-02290: check constraint (SCOTT.SYS_C006200) violated

SQL> insert into studentdb values(3123106,'ragu3','ragu3@gmail.com',100);

1 row created.

TABLE NAME: COURSEDB

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

Data
Column name Constraint
Type
COURSE_ID NUMBER PRIMARY KEY
STUDENT_NO NUMBER FOREIGN KEY

create table coursedb(course_id number primary key,STUDENT_NO NUMBER references


studentdb(STUDENT_NO))

Table Created

SQL> desc coursedb;


Name Null? Type
----------------------------------------- -------- ----------------------------
COURSE_ID NOT NULL NUMBER
STUDENT_NO NUMBER

5) FOREIGN KEY

SQL> insert into coursedb values(201,3123101);

1 row created.

SQL> insert into coursedb values(202,3123100);


insert into coursedb values(202,3123100)
*
ERROR at line 1:
ORA-02291: integrity constraint (SCOTT.SYS_C006204) violated - parent key not Found

6) READ ONLY

Create a view with read only permission.

SQL> create view cust_read as select


CUSTOMER_ID,CUSTOMER_NAME,CUSTOMER_STREET,CUSTOMER_CITY from customer WITH
READ ONLY CONSTRAINT ro;

View created.

SQL> select * from cust_read;


CUSTOMER_ID CUSTOMER_NAME CUSTOMER_STREET CUSTOMER_CITY
---------- -------------------- --------------- ---------------------------------------------------------------------------
cus_101 suresh north_masi chennai-45
cus_102 selva south_masi chennai-20
cus_103 prem east_masi chennai-17
cus_104 javid west_masi chennai-45
cus_105 pradeep central_masi chennai-15
cus_106 gopal northwest_masi chennai-43
cus_107 raja southwest_masi chennai-43

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

cus_108 krishnan northeast_masi chennai-15


cus_109 mohammed southeast_masi chennai-32

9 rows selected.

SQL> insert into cust_read values('cus_110','sachin','northcar','chennai-48');


insert into cust_read values('cus_110','sachin','northcar','chennai-48')
*
ERROR at line 1:
ORA-01733: virtual column not allowed here
7) CHECK OPTION

Create a view with constraints preventing updation in view and table.

create view cust_constraint1 as select


CUSTOMER_ID,CUSTOMER_NAME,CUSTOMER_STREET,CUSTOMER_CITY from customer where
CUSTOMER_CITY like'chennai%' WITH CHECK OPTION CONSTRAINT myv

View created.

SQL> select * from cust_constraint1;

CUSTOMER_ID CUSTOMER_NAME CUSTOMER_STREET CUSTOMER_CITY


---------- -------------------- --------------- --------------------------------------------------------------
cus_101 suresh north_masi chennai-45
cus_102 selva south_masi chennai-20
cus_103 prem east_masi chennai-17
cus_104 javid west_masi chennai-45
cus_105 pradeep central_masi chennai-15
cus_106 gopal northwest_masi chennai-43
cus_107 raja southwest_masi chennai-43
cus_108 krishnan northeast_masi chennai-15
cus_109 mohammed southeast_masi chennai-32

9 rows selected.

SQL> insert into cust_constraint1 values('cus_110','sachin','northcar','bangalore-43');


insert into cust_constraint1 values('cus_110','sachin','northcar','bangalore-43')
*
ERROR at line 1:
ORA-01402: view WITH CHECK OPTION where-clause violation

SQL> insert into cust_constraint1 values('cus_111','sachin','northcar','chennai-55');

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

1 row created.

RESULT:

Ex.No.5 CREATING RELATIONSHIP BETWEEN THE DATABASES.

AIM:

To Creating relationship between the databases in Oracle using Structured Query Language
commands
RULES FOR CREATING RELATIONSHIP BETWEEN THE DATABASES

BINARY 1:N & N:1

TERNARY

BINARY N:M

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

UNARY 1:1 UNARY 1:N &N:1 UNARY N:M

PROBLEM STATEMENT:

 A branch contain many account holder

 A branch provide more than one Loan

 A Loan can be availed by more than customer.

 A customer can get more than one Loan.

 A customer can have more than one account

 A account can have more than one customer

Table name: Branch

Create table branch(branch_name varchar2(30) primary key, branch_city varchar2(20), assets number);

Table created.

desc branch;

Name Null? Type

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

BRANCH_NAME NOT NULL VARCHAR2(30)

BRANCH_CITY VARCHAR2(20)

ASSETS NUMBER

=============================================================================
Table name: Customer
create table customer(customer_id varchar2(10) primary key, customer_name varchar2(20), customer_Street
varchar2(15), customer_City varchar2(15));
Table created.

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

desc customer;

Name Null? Type

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

CUSTOMER_ID NOT NULL VARCHAR2(10)

CUSTOMER_NAME VARCHAR2(20)

CUSTOMER_STREET VARCHAR2(15)

CUSTOMER_CITY VARCHAR2(15)

=============================================================================

Table name: Account

create table account(account_no varchar2(10) primary key, branch_name varchar2(30) REFERENCES


BRANCH(BRANCH_NAME), balance number);

Table created.

desc account;

Name Null? Type

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

ACCOUNT_NO NOT NULL VARCHAR2(10)

BRANCH_NAME VARCHAR2(30)

BALANCE NUMBER

=============================================================================

Table name: Loan

create table loan(loan_no varchar2(20) primary key, branch_name varchar2(20) REFERENCES


BRANCH(BRANCH_NAME), amount number);

Table created.

desc loan_ma;

Name Null? Type

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

LOAN_NO NOT NULL VARCHAR2(4)

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

BRANCH_NAME VARCHAR2(20)

AMOUNT NUMBER

=============================================================================

Table name: borrower

create table borrower(customer_id varchar2(11) references customer(customer_id),loan_no varchar2(4)


references loan(loan_no))

SQL> desc borrower;

Name Null? Type

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

CUSTOMER_ID VARCHAR2(11)

LOAN_NO VARCHAR2(4)

Table name: depositor

create table depositor(customer_id varchar2(11) references customer(customer_id), account_no


varchar2(11) references account(account_no))

SQL> desc depositor;

Name Null? Type

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

CUSTOMER_ID VARCHAR2(11)

ACCOUNT_NO VARCHAR2(11)

INSERTING RECORDS IN ALL THE SIX CREATED TABLES:

SQL> insert into branch values('&branch_name','&branch_city',&assets);

Enter value for branch_name: tambaram


Enter value for branch_city: chennai-45
Enter value for assets: 50000

old 1 : insert into branch values('&branch_name','&branch_city',&assets)


new 1: insert into branch values('tambaram','chennai-45',50000)
1 row created.

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

insert into branch values('tambaram','chennai-45',50000)

insert into customer values('cus_109','mohammed','southeast_masi','chennai-32')

insert into account values('735_105','chrompet',5000)

insert into loan values('ln_106','saidapet',2000)

insert into borrower values('cus_101','ln_101')

insert into depositor values('cus_108','735_102')

1. For all customer who have loan from the bank find their ID’s , loan number and loan amount.(Join)

SQL> select borrower.CUSTOMER_ID,loan.LOAN_NO,loan.AMOUNT from loan,borrower where


loan.LOAN_NO=borrower.LOAN_NO

CUSTOMER_ID LOAN_NO AMOUNT


----------- -------------------- -----------------------------------------------
cus_101 ln_101 900
cus_101 ln_106 2000
cus_103 ln_107 500
cus_105 ln_105 1000
cus_103 ln_104 1300
cus_105 ln_102 1500
6 rows selected.

2. For all customers who have loan at tambaram branch find their ID’s,loan ID,loan amount.(Join)

SQL> select borrower.CUSTOMER_ID,loan.LOAN_NO,loan.AMOUNT from loan,borrower where


loan.LOAN_NO=borrower.LOAN_NO and loan.BRANCH_NAME='tambaram'

CUSTOMER_ID LOAN_NO AMOUNT

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

cus_103 ln_104 1300

3. Find the number of depositor at each branch.(Join)

SQL> select account.BRANCH_NAME,count(account.BRANCH_NAME) as No_of_Depositor from


account,depositor where account.ACCOUNT_NO=depositor.ACCOUNT_NO group by
account.BRANCH_NAME

BRANCH_NAME NO_OF_DEPOSITOR
------------------------------ -----------------------------------------------
adayar 1
chrompet 2

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

guindy 1
saidapet 1
tnagar 1

RESULT:

Ex.No.6 STUDY OF PL/SQL BLOCK

AIM:

TO STUDY THE WORKING PRINCIPLES OF PL/SQL BLOCK


PL/SQL Block consists of three sections:

 The Declaration section (optional).


 The Execution section (mandatory).
 The Exception (or Error) Handling section (optional).

Declaration Section:
The Declaration section of a PL/SQL Block starts with the reserved keyword DECLARE. This
section is optional and is used to declare any placeholders like variables, constants, records and cursors,
which are used to manipulate data in the execution section. Placeholders may be any of Variables, Constants
and Records, which stores data temporarily. Cursors are also declared in this section.

Execution Section:
The Execution section of a PL/SQL Block starts with the reserved keyword BEGIN and ends with
END. This is a mandatory section and is the section where the program logic is written to perform any task.
The programmatic constructs like loops, conditional statement and SQL statements form the part of
executionsection.

Exception Section:
The Exception section of a PL/SQL Block starts with the reserved keyword EXCEPTION. This
section is optional. Any errors in the program can be handled in this section, so that the PL/SQL Blocks
terminates gracefully. If the PL/SQL Block contains exceptions that cannot be handled, the Block terminates
abruptly with errors. Every statement in the above three sections must end with a semicolon; PL/SQL
blocks can be nested within other PL/SQL blocks. Comments can be used to document code.

Sample PL/SQL Block Looks

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

DECLARE
Variable declaration
BEGIN
Program Execution
EXCEPTION
Exception handling
END;

.RESULT:

Ex.No.7 WRITE A PL/SQL BLOCK TO SATISFY SOME CONDITIONS BY ACCEPTING


INPUT FROM THE USER.

AIM:

Write a PL/SQL block to satisfy some conditions by accepting input from the user using oracle

SYNTAX

DECLARE
Variable declaration
BEGIN
Program Execution
EXCEPTION
Exception handling
END;

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

FACTORIAL OF GIVEN NUMBER


1 declare
2 n number;
3 i number;
4 p number:=1;
5 begin
6 n:=&n;
7 for i in 1..n loop
8 p:=p*i;
9 end loop;
10 dbms_output.put_line(n ||' ! = '||p);
11* end;

Enter value for n: 5


old 6: n:=&n;
new 6: n:=5;
5 ! = 120

PL/SQL procedure successfully completed.

Enter value for n: 4


old 6: n:=&n;
new 6: n:=4;
4 ! = 24

PL/SQL procedure successfully completed.

FIND THE DEPARTMENT NAME FROM EMLOYEES TABLE USING PL/SQL BLOCK
1 declare
2 deptname varchar2(10);
3 begin
4 select department_name into deptname from employees where department_id=&departmentid;
5 dbms_output.put_line('The Department name is '||deptname);
6* end;

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

SQL> /
Enter value for departmentid: 101
old 4: select department_name into deptname from employees where
department_id=&departmentid;
new 4: select department_name into deptname from employees where department_id=101;

The Department name is IT

PL/SQL procedure successfully completed.


RESULT:

Ex.No.8 WRITE A PL/SQL BLOCK THAT HANDLES ALL TYPES OF EXCEPTIONS.

AIM:

To implement and execute PL/SQL Block that handles all types of exceptions in Oracle Database
using Procedural Language concepts.

EXCEPTIONS:

In PL/SQL, the user can catch certain runtime errors. Exceptions can be internally defined by Oracle
or the user. Exceptions are used to handle errors that occur in your PL/SQL code. A PL/SQL block contains
an EXCEPTION block to handle exception.

There are three types of exceptions:

1. Predefined Oracle errors


2. Undefined Oracle errors
3. User-defined errors

The different parts of the exception.

1. Declare the exception.


2. Raise an exception.
3. Handle the exception.

An exception has four attributes:

1. Name provides a short description of the problem.

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

2. Type identifies the area of the error.


3. Exception Code gives a numeric representation of the exception.
4. Error message provides additional information about the exception.

The predefined divide-by-zero exception has the following values for the attributes:

1. Name = ZERO_DIVIDE
2. Type = ORA (from the Oracle engine)
3. Exception Code = C01476

Error message = divisor is equal to zero

TYPES OF MORE COMMONLY USED EXCEPTIONS

NO_DATA_FOUND Singleton SELECT statement returned no data.


Singleton SELECT statement returned more than one row of
TOO_MANY_ROWS
data.
INVALID_CURSOR Illegal cursor operation occurred.
VALUE_ERROR Arithmetic, conversion, or truncation error occurred.
INVALID_NUMBER Conversion of a number to a character string failed.
ZERO_DIVIDE Attempted to divide by zero.
Attempted to insert a duplicate value into a column that has a
DUP_VAL_ON_INDEX
unique index.
CURSOR_ALREADY_OPEN Attempted to open a cursor that was previously opened.
NOT_LOGGED_ON A database call was made without being logged into Oracle.
Usually raised when a remote portion of a transaction is rolled
TRANSACTION_BACKED_OUT
back.
LOGIN_DENIED Login to Oracle failed.
PROGRAM_ERROR If PL/SQL encounters an internal problem.
STORAGE_ERROR If PL/SQL runs out of memory or if memory is corrupted.
TIMEOUT_ON_RESOURCE Timeout occurred while Oracle was waiting for a resource.
OTHERS For all of the rest.

ZERO_DIVIDE EXCEPTION

SQL> BEGIN
2 DBMS_OUTPUT.PUT_LINE(1 / 0);
3 END;
4 /
BEGIN
*
ERROR at line 1:

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

ORA-01476: divisor is equal to zero


ORA-06512: at line 2

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

BEGIN
2 DBMS_OUTPUT.PUT_LINE(1 / 0);
3 EXCEPTION
4 WHEN ZERO_DIVIDE THEN
5 DBMS_OUTPUT.PUT_LINE('Division by zero');
6 END;
7 /
Division by zero
PL/SQL procedure successfully completed.

INVALID_NUMBER EXCEPTION

1 BEGIN

2 INSERT INTO employees(DEPARTMENT_ID)VALUES('101x');

3 EXCEPTION

4 WHEN INVALID_NUMBER THEN

5 DBMS_OUTPUT.PUT_LINE('Conversion of string to number failed');

6* end;

SQL> /

Conversion of string to number failed

PL/SQL procedure successfully completed.

OTHERS EXCEPTION

1 BEGIN

2 DBMS_OUTPUT.PUT_LINE(1 / 0);

3 EXCEPTION

4 WHEN OTHERS THEN

5 DBMS_OUTPUT.PUT_LINE('An exception occurred');

6* END;

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

7 /

An exception occurred

PL/SQL procedure successfully completed.

RESULT:

Ex.No.9 CREATION OF PROCEDURES

AIM:

To implement and execute Procedures in Oracle Database using Procedural Language concepts.

PROCEDURES:
1) Procedure is a sub program used to perform an action.

2) Replace-recreates the procedure if it already exists.

3 MODES:
1) IN – Means you must specify a value for the argument at the time execution of the procedure.

2) OUT-passes back a value to its calling program.

3) INOUT – When calling the procedure, yu must specify the value and that procedures passes value
back to the calling procedure.

SYNTAX:

Create or replace procedure <procedure_name> (argument {in, out, in out} data type) {is, as}

Variable declaration

Begin

Pl/SQL Subprogram body.

Exception

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

Exception PL/SQL Block.

End;

Write a procedure to include phone number for the customers in the customer table.

create or replace procedure pro(phoneno in number,cust_id in varchar2) is


a varchar2(20);
b exception;
begin
select customer_name into a from customer where customer_id=cust_id;
if a is null then
raise b;
else
update customer set phone_no=phoneno where customer_id=cust_id;
end if;
exception
when no_data_found then
dbms_output.put_line('no such data');
when b then
dbms_output.put_line('customer name is null');
end;

SQL> /

Procedure created.

SQL> select * from customer;

CUSTOMER_ID CUSTOMER_NAME CUSTOMER_STREET CUSTOMER_CITY


CUSTOMER_DOB CUSTOMER_ PHONE_NO
---------- -------------------- --------------- --------------- --------- ----------------------------------------------------------
cus_101 suresh north_masi chennai-45 12-JAN-86 9941950434
cus_102 selva south_masi chennai-20 05-NOV-87

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

cus_103 prem east_masi chennai-17 09-JAN-88


cus_104 javid west_masi chennai-45 27-AUG-77
cus_105 pradeep central_masi chennai-15 08-MAR-88
cus_106 gopal northwest_masi chennai-43 06-MAY-84
cus_107 raja southwest_masi chennai-43 07-MAY-86
cus_108 krishnan northeast_masi chennai-15 05-SEP-00
cus_109 mohammed southeast_masi chennai-32 03-APR-99

9 rows selected.

SQL> execute pro(9940065845,'cus_102');

PL/SQL procedure successfully completed.

SQL> select * from customer;

CUSTOMER_ID CUSTOMER_NAME CUSTOMER_STREET CUSTOMER_CITY


CUSTOMER_DOB CUSTOMER_ PHONE_NO
---------- -------------------- --------------- --------------- --------- ----------------------------------------------------------
cus_101 suresh north_masi chennai-45 12-JAN-86 9941950434
cus_102 selva south_masi chennai-20 05-NOV-87 9940065845
cus_103 prem east_masi chennai-17 09-JAN-88
cus_104 javid west_masi chennai-45 27-AUG-77
cus_105 pradeep central_masi chennai-15 08-MAR-88
cus_106 gopal northwest_masi chennai-43 06-MAY-84
cus_107 raja southwest_masi chennai-43 07-MAY-86
cus_108 krishnan northeast_masi chennai-15 05-SEP-00
cus_109 mohammed southeast_masi chennai-32 03-APR-99

9 rows selected.

SQL> execute pro(9940065845,'cus_110');


no such data

PL/SQL procedure successfully completed.

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

RESULT:

Ex.No.10 CREATION OF DATABASE TRIGGERS AND FUNCTIONS

AIM:

To implement and execute triggers and functions in Oracle Database using Procedural Language
concepts.

TRIGGERS:
1) Trigger is a special type of procedure that the oracle executes when an insert, modify or
delete operation is performed against a given table.
2) It is a stored sub program associated with a table.
3) It is used to keep an audit trial of a table, to prevent invalid transaction, enforce complex
security authorization, to generate data automatically.

SYNTAX:

CREATE OR REPLACE TRIGGER <TRIGGER NAME>


{BEFORE/AFTER/INSTEAD OF}
{INSERT/UPDATE/DELETE}
ON <TABLENAME/VIEWNAME>
REFRENCECING {OLD AS OLD /NEW AS NEW}
[FOR EACH STATEMENT /FOR EACH ROW [WHEN <CONDITION>]]
DECLARE
Variable declaration
Constant declaration
BEGIN
PL/SQL Sub program body.
EXCEPTION
Exception PL/SQL Block (or) user defined exception.
END;

FUNCTION:

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

1) A function is a sub program that accepts argument and returns a unique value to the caller.

FUNTION SYNTAX:

Create or replace function <function_name> (parameter{in, out, in out}) return <data type> is
Variable declaration
Begin
Pl/SQL Subprogram body.
Exception
Exception PL/SQL Block.
Return statement
End;

Create a trigger to calculate the total and average of a student in the student table.

SQL> create table student(regno number primary key,name varchar2(20),tamil number,english


number,maths number,science number,social number,total number,average number);

Table Created

TRIGGER

CREATE OR REPLACE TRIGGER totavg BEFORE INSERT ON student


FOR EACH ROW
DECLARE
BEGIN
:new.total:=:new.tamil+:new.english+:new.maths+:new.science+:new.social;
:new.average:=round(:new.total/5);
END;

SQL> /

Trigger created.

SQL> desc student;


Name Null? Type
----------------------------------------------------- -------- -------------------------------------------------
REGNO NOT NULL NUMBER
NAME VARCHAR2(20)
TAMIL NUMBER
ENGLISH NUMBER
MATHS NUMBER
SCIENCE NUMBER
SOCIAL NUMBER
TOTAL NUMBER

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

AVERAGE NUMBER

SQL> insert into


student(REGNO,NAME,TAMIL,ENGLISH,MATHS,SCIENCE,SOCIAL)values(101,'sachin',70,65,80,
83,90);

1 row created.

SQL> select * from student;

REGNO NAME TAMIL ENGLISH MATHS SCIENCE SOCIAL TOTAL AVERAGE


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

101 sachin 70 65 80 83 90 388 78

Write a Function to check the status of phone number in the customer table.
-------------------------------------------------------------------------------------------

1 create or replace function check1(cust_id in varchar2) return varchar2 is


2 phoneno number;
3 begin
4 select phone_no into phoneno from customer where customer_id=cust_id;
5 if(phoneno is null) then
6 return('Enter phone number');
7 else
8 return('Phone number already exists');
9 end if;
10* end;

SQL> /

Function created.
SQL> select check1('cus_105') as status from dual;

STATUS
---------------------------------------------------------------------------------
Enter phone number

SQL> select check1('cus_101') as status from dual;

STATUS
---------------------------------------------------------------------------------
Phone number already exists

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

RESULT:

EX.NO.11 AIRLINE RESERVATION SYSTEM

PROBLEM STATEMENT

 Airlines have many flights.

 Airlines operates many number of routes.

 Airlines provides many number of tickets.

 A passenger can avail many tickets.

 Airlines adopt many passengers in a single flight.

 A passenger can travel in many flights.

 A ticket has information about a single filght.

 Reserved tickets can be cancelled by customers.

BACK END DESIGN

IDENTIFICATION OF ENTITY:

 PASSENGER
 FLIGHT_INFORMATION
 FLEET_INFORMATION
 TICKET_DETAILS

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

DESCRIPTION ABOUT ENTITY:

ATTRIBUTES:

PASSENGER
 Name
 P_id
 Age
 Sex
 Address
 Contact_no

FLIGHT_INFORMN
 Flight_name
 Flight_no
 Class

FLEET_INFORMN
 Source
 Destination
 Arrival_time
 Departure_time

TICKET_DETAILS
 Class_name
 Ticket_no
 Status
 Fare
DESCRIPTION ABOUT ATTRIBUTES:

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

RELATIONSHIP:
 BINARY

 BOOKS
 SCHEDULES
 TRAVELS
 HAS

DESCRIPTION ABOUT RELATIONSHIP:

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

CARDINALITY AND RELATIONSHIP:


 ONE TO ONE(1:1)
 SCHEDULES
 HAS

 ONE TO MANY(1:N):
 BOOKS

 MANY TO MANY(N:N):
 TRAVELS
CARDINALITY ABOUT RELATIONSHIP:

 PASSENGER TRAVELS IN FLIGHTS

 PASSENGER BOOKS TICKETS

 FLEET_INFORMN SCHEDULES FLIGHTS

ER DIAGRAM:

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

ER MODELS TO TABLES:

RULES TO CONVERT ER DIAGRAM INTO TABLE:

 EACH ENTITY TYPES BECOME TABLE


 EACH SINGLE VALUED ATTRIBUTES BECOME A COLUMN
 DERIVED ATTRIBUTES ARE IGNORED
 COMPOSITE ATTRIBUTES ARE REPRESENTED BY COMPONENTS
 MULTI VALUED ATTRIBUTES ARE REPRESENTED BY SEPARATE TABLE
 THE KEY ATTRIBUTE OF THE ENTITY TYPE BECOMES PRIMARY KEY OF THE
TABLE
TABLE:

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

RELATIONSHIP RULE:

 The primary key of the partial participant will become the foreign key of the total participant in
binary 1:1 relationship.
 The primary key of the relation on the “1” side of the relationship becomes a foreign key in the
relation on the “N” side in binary 1:N relationship.
 A new table is created to represent the relationship in binary M:N relationship.
 Contains two foreign keys – one from each of the participants in the relationship in binary M:N
relationship.
 The primary key of the new table is the combination of the two foreign keys in binary M:N
relationship.
 The primary key field itself will become foreign key in the same table in unary 1:1 relationship.
 The primary key field itself will become foreign key in the same table in unary 1:1 relationship.
 There will be two resulting tables. One to represent the entity and another to represent the unary M:N
relationship.
 Represented by a new table. The new table contains three foreign keys – one from each of the
participating Entities in ternary relationship. The primary key of the new table is the combination of
all three foreign keys.

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

UPDATED TABLE:

CONSTRAINTS RELATED TO PROJECT:

 Primary Key

 Unique

 Not null

 Null

 Foreign key

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

TABLES:

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

DATA DEFINITION LANGUAGE:

COMMANDS:

 CREATE

 SYNTAX: create table tablename (attribute1 datatype1,.., attributen datatypen);

 DELETE

 SYNTAX: drop table tablename;

 ALTER

 SYNTAX: alter table tablename add(attribute datatype);


 SYNTAX: alter table tablename modify(attribute datatype);
 SYNTAX: alter table tablename drop(attribute);
 RENAME

 SYNTAX: rename table oldname to newname;

DDL QUERY:

 create table passenger(fname varchar2(30),lname varchar2(30),age number,sex varchar2(20),p_id


number,address varchar2(30),contact number);
 create table flightinfo(flightname varchar2(30),flight_no varchar2(30), class varchar2(20));
 create table fleetinfo(flight_no varchar2(30),source varchar2(30),destination varchar2(30),arrival
varchar2(30),departure varchar2(30));
 Create table ticket (T_no number primary key, P_id number references passenger(P_id), flight_no
varchar2(30) references Fleetinfo(flight_no),class varchar2(10),source varchar2(30), destination
varchar2(30), arrival varchar2(30), departure varchar2(30),fare number);

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

FRONT END DESIGN

FORM1:

CODE:
Private Sub Timer1_Timer()
Unload Me
Form7.Show
End Sub

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

FORM10:

CODE:
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Private Sub Command1_Click()
Form11.Show
Text1.Text = ""
Text2.Text = ""
End Sub
Private Sub Command2_Click()
Unload Me
Form7.Show
End Sub
Private Sub Form_Load()
conn.Open "Provider=OraOLEDB.Oracle.1;Password=tiger;Persist Security Info=True;User ID=scott"
End Sub
Private Sub Form_Unload(Cancel As Integer)

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

conn.Close
End Sub
FORM11:

CODE:

Dim conn As New ADODB.Connection


Dim rs As New ADODB.Recordset
Dim rs1 As New ADODB.Recordset
Private Sub Command1_Click()
Unload Me
Form10.Show
End Sub
Private Sub Form_Load()
conn.Open "Provider=OraOLEDB.Oracle.1;Password=28it218;Persist Security Info=True;User
ID=28it218;Data Source=oracle9i"
rs.Open "select * from ticket where t_no=" & Val(Form10.Text13.Text) & " and p_id=" &
Val(Form10.Text1.Text) & "", conn, adOpenDynamic, adLockOptimistic
rs1.Open "select * from passenger where p_id=" & Val(Form10.Text1.Text) & "", conn, adOpenDynamic,
adLockOptimistic

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

Text2.Text = rs1(0)
Text3.Text = rs1(1)
Text4.Text = rs(9)
Text5.Text = rs(2)
Text6.Text = rs(3)
Text7.Text = rs(4)
Text8.Text = rs(5)
Text9.Text = rs(6)
Text10.Text = rs(7)
Text11.Text = rs(8)
End Sub
FORM2:

CODE:

Dim conn As New ADODB.Connection


Dim rs As New ADODB.Recordset
Dim rs1 As New ADODB.Recordset
Private Sub Command1_Click()
Form3.Show
End Sub
Private Sub Command2_Click()
Text1.Text = ""

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Combo1.Text = ""
Unload Me
Form7.Show
End Sub

Private Sub Command4_Click()


Set rs1 = Nothing
rs.Open "insert into passenger(fname,lname,age,sex,address,contact,p_id)values('" & Trim(Text1.Text) &
"','" & Trim(Text2.Text) & "'," & Val(Text3.Text) & ",'" & Trim(Combo1.Text) & "','" & Trim(Text4.Text)
& "'," & Val(Text5.Text) & ",id.nextval) ", conn, adOpenDynamic, adLockOptimistic
rs1.Open "select * from passenger where fname='" & Trim(Text1.Text) & "' and lname='" &
Trim(Text2.Text) & "' and age=" & Val(Text3.Text) & " and sex='" & Trim(Combo1.Text) & "' and
address='" & Trim(Text4.Text) & "' and contact=" & Val(Text5.Text) & " ", conn, adOpenDynamic,
adLockOptimistic
Text6.Text = rs1(4)
MsgBox "Passenger Details Inserted Successfully and Your id is '" & Trim(Text6.Text) & "'"
End Sub
Private Sub Form_Load()
conn.Open "Provider=OraOLEDB.Oracle.1;Password=tiger;Persist Security Info=True;User ID=scott"
Text6.Enabled = False
End Sub
Private Sub Form_Unload(Cancel As Integer)
conn.Close
End Sub

FORM3:

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

CODE:
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Private Sub Command1_Click()
If Combo1.Text = "" Or Combo2.Text = "" Or Combo3.Text = "" Then
MsgBox "SELECT VALUES"
Else
rs.Open "insert into flightinfo(flightname,flight_no,class)values('" & Trim(Combo1.Text) & "','" &
Trim(Combo2.Text) & "','" & Trim(Combo3.Text) & "')", conn, adOpenDynamic, adLockOptimistic
Form4.Show
Form4.Text1.Text = Combo2.Text
Me.Hide
End If
End Sub
Private Sub Command2_Click()
Unload Form2
Unload Me
Form7.Show
End Sub
Private Sub Command3_Click()
Form5.Show
End Sub
Private Sub Form_Load()
Set conn = Nothing
conn.Open "Provider=OraOLEDB.Oracle.1;Password=tiger;Persist Security Info=True;User ID=scott"
End Sub
FORM4:

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

CODE:
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Private Sub Command2_Click()
Form3.Show
Form3.Combo1.Text = ""
Form3.Combo2.Text = ""
Form3.Combo3.Text = ""
Unload Me
End Sub
Private Sub Command3_Click()
Form5.Show
End Sub
Private Sub Command4_Click()
Unload Form2
Unload Me
Form7.Show
End Sub
Private Sub Form_Load()
conn.Open "Provider=OraOLEDB.Oracle.1;Password=tiger;Persist Security Info=True;User ID=scott"
Set rs = Nothing
End Sub
Private Sub Form_Unload(Cancel As Integer)
conn.Close
End Sub
Private Sub Text1_Change()
rs.Open "select * from fleetinfo where flight_no='" & Trim(Text1.Text) & "'", conn, adOpenDynamic,
adLockOptimistic
Text2.Text = rs(1)
Text3.Text = rs(2)
Text4.Text = rs(3)
Text5.Text = rs(4)
End Sub
FORM5:

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

CODE:
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim rs1 As New ADODB.Recordset
Private Sub Command1_Click()
rs1.Open "select * from ticket where p_id=" & Val(Text1.Text) & " and flight_no='" & Trim(Text5.Text) &
"' ", conn, adOpenForwardOnly, adLockOptimistic
Text13.Text = rs1(0)
MsgBox "TICKET BOOKED SUCCESSFULLY "
Unload Me
Form9.Show
End Sub

Private Sub Command2_Click()


rs.Open " insert into
ticket(FLIGHT_NO,Class,Source,DESTINATION,ARRIVAL,DEPARTURE,FARE,FLIGHTNAME,p_id,t_
no)values('" & Trim(Text5.Text) & "','" & Trim(Text6.Text) & "','" & Trim(Text7.Text) & "','" &
Trim(Text8.Text) & "','" & Trim(Text9.Text) & "','" & Trim(Text10.Text) & "'," & Val(Text11.Text) & ",'"
& Trim(Text4.Text) & "'," & Val(Text1.Text) & ",tid.nextval)", conn, adOpenDynamic, adLockOptimistic
MsgBox "TICKET CONFIRMED"
End Sub

Private Sub Command3_Click()


Unload Me
Form7.Show
End Sub

Private Sub Form_Load()


Text13.Enabled = False
Text1.Text = Form2.Text6.Text
conn.Open "Provider=OraOLEDB.Oracle.1;Password=tiger;Persist Security Info=True;User ID=scott"

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

Text2.Text = Form2.Text1.Text
Text3.Text = Form2.Text2.Text
Text4.Text = Form3.Combo1.Text
Text5.Text = Form3.Combo2.Text
Text6.Text = Form3.Combo3.Text
Text7.Text = Form4.Text2.Text
Text8.Text = Form4.Text3.Text
Text9.Text = Form4.Text4.Text
Text10.Text = Form4.Text5.Text
End Sub

Private Sub Text5_Change()


Select Case Text5.Text
Case "IA747"
Text11.Text = 7000
Case "IA567"
Text11.Text = 15000
Case "AC333"
Text11.Text = 45000
Case "AC444"
Text11.Text = 57000
Case "AF876"
Text11.Text = 35000
Case "AF345"
Text11.Text = 75000
Case "BA458"
Text11.Text = 42000
Case "BA235"
Text11.Text = 85000
Case "LF787"
Text11.Text = 115000
Case "LF564"
Text11.Text = 125000
End Select
End Sub
FORM6:

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

CODE:
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim rs1 As New ADODB.Recordset
Private Sub Command1_Click()
rs1.Open "SELECT * FROM TICKET WHERE T_NO=" & Val(Text1.Text) & " ", conn, adOpenDynamic,
adLockOptimistic
If rs1(0).Value = Text1.Text And rs1(1).Value = Text2.Text Then
rs.Open "DELETE FROM TICKET WHERE T_NO=" & Val(Text1.Text) & " AND P_ID=" &
Val(Text2.Text) & "", conn, adOpenDynamic, adLockOptimistic
MsgBox " TICKET CANCELLED SUCCESSFULLY"
End If
If rs1.BOF = True Or rs1.EOF = True Then
MsgBox "TICKET NOT FOUND"

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

End If
Unload Me
Form8.Show
End Sub
Private Sub Command2_Click()
Unload Me
Form7.Show
End Sub
Private Sub Form_Load()
conn.Open "Provider=OraOLEDB.Oracle.1;Password=tiger;Persist Security Info=True;User ID=scott"
End Sub
Private Sub Form_Unload(Cancel As Integer)
conn.Close
End Sub
FORM7:

CODE:
Private Sub Command1_Click()
Unload Me
Form2.Show
End Sub
Private Sub Command2_Click()
Unload Me
Form6.Show
End Sub
Private Sub Command3_Click()
DataReport1.Show
End Sub

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

Private Sub Command4_Click()


Unload Me
Form1.Show
End Sub
Private Sub Command5_Click()
Unload Me
Form10.Show
End Sub

FORM8:

CODE:
Private Sub Form_Load()
Unload Form2
Unload Form3
Unload Form4
Unload Form5
Unload Form6
Unload Form7
End Sub
Private Sub Timer1_Timer()
Unload Form8
Form1.Show
End Sub
FORM9:

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008


CS4451-DBMS Lab Department of CSE 2020-21

CODE:
Private Sub Timer1_Timer()
Unload Me
Form8.Show
End Sub
RESULT:

St.Joseph’s College of Engineering / St.Joseph’s Institute of Technology ISO 9001:2008

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy