DBMS Lab - Mca

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

END TERM PRACTICAL EXAMINATION

MASTER OF COMPUTER APPLICATIONS


DBMS LAB(OMC 321)

Max Marks : 70
Choose any two questions to answer. (35x2)
1. Consider the insurance database given below. The primary keys are made bold and the data
types are specified.
PERSON( driver_id:string , name:string , address:string )
CAR( regno:string , model:string , year:int )
ACCIDENT( report_number:int , accd_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 foreign keys.
2)Enter at least five tuples for each relation.
3)Demonstrate how you
a.Update the damage amount for the car with specific regno in the 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 the year
2008.
5)Find the number of accidents in which cars belonging to a specific model were involved.

2.
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 , customer_city:string )
LOAN( loan_number:int , branch_name:string , amount:real )
BORROWER( customer_name:string , loan_number:int )

1)Create the above tables by properly specifying the primary keys and foreign keys.
2)Enter at least five tuples for each relation.

3)Find all the customers who have at least two accounts at the main branch.

4)Find all the customers who have an account at all the branches located in a specific city.

5)Demonstrate how you delete all account tuples at every branch located in a specific city.

• A university registrar’s office maintains data about the following entities:

• courses, including number, title, credits, syllabus, and prerequisites;


• course offerings, including course number, year, semester, section number,
instructor(s), timings, and classroom;
• students, including student-id, name, and program;
• instructors, including identication number, name, department, and title.
Further, the enrollment of students in courses and grades awarded to students in each
course they are enrolled for must be appropriately modeled. Construct an E-R diagram
for the registrar’s office. Document all assumptions that you make about the mapping
constraints.

Viva Question: All questions are compulsory (10 x 3)


• What is DBMS?

• What is DDL and DML?

• Why is the use of DBMS recommended?

Ans:-1) :- INSURANCE DATABASE


1.SQL> create table person(driver_id varchar(10),name varchar(10),address
varchar(10),primary key(driver_id));
SQL> create table car(regno varchar(10),model varchar(10),year int,primary
key(regno));
SQL> create table accident(report_number int,accd_date date,location
varchar(10),primary key(report_number));
SQL> create table owns(driver_id varchar(10), regno varchar(10),primary
key(driver_id,regno),foreign key(driver_id) references person(driver_id),foreign
key(regno) references car(regno));
SQL> create table participated(driver_id varchar(10),regno
varchar(10),report_number int,damage_amount int,primary
key(driver_id,regno,report_number),foreign key(driver_id) references
person(driver_id),foreign key(regno) references car(regno),foreign
key(report_number) references accident(report_number));

2.SQL> insert into person values('&driver_id','&name','&address');


SQL> insert into car values('&regno','&model',&year);
SQL> insert into accident values(&report_number,'&accd_date','&location');
SQL> insert into owns values('&driver_id','&regno');
SQL> insert into participated
values('&driver_id','&regno',&report_number,&damage_amount);
3a. SQL> update participated set damage_amount=25000 where
report_number=12 and regno='5';
3b. SQL> insert into accident values(&report_number,'&accd_date','&location');
SQL> insert into participated
values('&driver_id','&regno',&report_number,&damage_amount);
4. SQL> select count(distinct o.driver_id) as People from owns o,participated
p,accident a where a.accd_date like
'%08' and o.regno=p.regno and p.report_number=a.report_number;
5. SQL> select count(*) as Totalcars from car c,participated p where
c.regno=p.regno and c.model='Alto';
ANS:-2) BANKING ENTERPRISE
1. SQL> create table branch(branch_name varchar(10),branch_city
varchar(10),assets int,primary key(branch_name));
SQL> create table account(accno int,branch_name varchar(10),balance int,primary
key(accno));
SQL> create table customer(customer_name varchar(10),customer_street
varchar(10),customer_city varchar(10),primary key(customer_name));
SQL> create table depositor(customer_name varchar(10),accno int,primary
key(customer_name,accno),foreign key(customer_name) references
customer(customer_name),foreign key(accno) references account(accno) on delete
cascade);
SQL> create table loan(loan_number int,branch_name varchar(10),amount
int,primary key(loan_number),foreign key(branch_name) references
branch(branch_name));
SQL> create table borrower(customer_name varchar(10),loan_number int,primary
key(customer_name,loan_number),foreign key(customer_name) references
customer(customer_name),foreign key(loan_number) references
loan(loan_number));
2. SQL> insert into branch values('&branch_name','&branch_city',&assets);
SQL> insert into account values(&accno,'&branch_name',&balance);
SQL> insert into customer
values('&customer_name','&customer_street','&customer_city');
SQL> insert into depositor values('&customer_name',&accno);
SQL> insert into loan values(&loan_number,'&branch_name',&amount);
SQL> insert into borrower values('&customer_name',&loan_number);
3. SQL> select d.customer_name from depositor d,account a where
a.accno=d.accno and a.branch_name='KRMarket' group by d.customer_name
having count(*)>=2;
4. SQL> select c.customer_name from customer c where exists(select
branch_name from branch where branch_city='Bangalore') and not exists ((select
branch_name from branch where branch_city='Bangalore') minus (select
b.branch_name from branch b,account a,depositor d where
d.customer_name=c.customer_name and d.accno=a.accno and
a.branch_name=b.branch_name));
5. SQL> delete from account where accno in (select a.accno from account
a,branch b where a.branch_name=b.branch_name and b.branch_city='Bangalore');

Viva Question:
• What is DBMS?
Database Management System (DBMS) is a software for storing and retrieving
user's data while considering appropriate security measures. It consists of a group
of programs which manipulate the database. The DBMS accept the request for
data from an application and instructs the operating system to provide the specific
data. In large systems, DBMS helps users and other third party software to store
and retrieve data.
DBMS allows users to create their own databases as per their requirement. The
term DBMS includes the user of database and other application programs. It
provides an interface between the data and the software application.
Let us see a simple example of a university database. This database is maintaining
information concerning students, courses, and grades in a university environment.
The database is organized as five files:-
The STUDENT file store data of each student
The COURSE file store contain data on each course.
The SECTION store the information about sections in a particular course.
The GRADE file store the grades which students receive in the various sections .
The TUTOR file contains information about each professor.

• What is DDL and DML?


DML
DML is short name of Data Manipulation Language which deals with data
manipulation, and includes most common SQL statements such SELECT,
INSERT, UPDATE, DELETE etc, and it is used to store, modify, retrieve, delete
and update data in database.
SELECT – retrieve data from one or more tables.
INSERT – insert data into a table.
UPDATE – updates existing data within a table.
DELETE – delete all records from a table.
MERGE – UPSERT operation (insert or update)
CALL – call a PL/SQL or Java subprogram.
EXPLAIN PLAN – interpretation of the data access path.
LOCK TABLE – concurrency control.
DDL:- DDL is short name of Data Definition Language, which deals with
database schemas and descriptions, of how the data should reside in the database.
CREATE – to create database and its objects like (table, index, views, store
procedure, function and triggers).
ALTER – alters the structure of the existing database.
DROP – delete objects from the database.
TRUNCATE – remove all records from a table; also, all spaces allocated for the
records are removed.
COMMENT – add comments to the data dictionary.
RENAME – rename an object

• Why is the use of DBMS recommended?


Use of DBMS recommended because it is
i. Reducing Data Redundancy:-The file based data management systems
contained multiple files that were stored in many different locations in system or
even across multiple systems.
ii. Sharing of Data:-In a database the users of the database can share the data among
themselves. There are various levels of authorisation to access the data and
consequently the data can only be shared based on the correct authorisation
protocols being followed.
iii. Data Integrity:-Data integrity means that the data is accurate and consistent in
the database. Data Integrity is very important as there are multiple databases in a
DBMS.
iv. Data Security:-Data Security is vital concept in a database. Only authorised users
should be allowed to access the database and their identity should be
authenticated using a username and password.
v. Data Consistency:-Data consistency is ensured in a database because there is no
data redundancy.
vi. Backup and Recovery:-Database Management System automatically takes care
of backup and recovery. The users don't need to backup data periodically because
this is taken care of the DBMS.

You might also like