Lab Manual 01
Lab Manual 01
Class: BSAI
Semester: II-A
Session: Spring, 2024
Lab Instructor: Asra Masood
Instructions
Submission: Use proper naming convention for your submission file. Name the submission
file as Lab_NO_DEGREE_ROLLNUM (e.g. Lab_01_BSAI_00000). Submit the file on Google
Classroom within the deadline. Failure to submit according to the above format would result in
deduction of 10% marks. Submissions on the email will not be accepted.
Plagiarism: Plagiarism cases will be dealt with strictly. If found plagiarized, both the involved
parties will be awarded zero marks in the assignment, all of the remaining assignments, or even
an F grade in the course. Copying from the internet is the easiest way to get caught!
Deadline: The deadlines to submit the assignment are hard. Late submission with marks
deduction will be accepted according to the course policy shared by the instructor. Correct and
timely submission of the assignment is the responsibility of every student; hence no relaxation
will be given to anyone.
Comments: Comment your code properly. Write your name and roll number (as a block
comment) at the beginning of the solution to each problem.
Objectives
InTip
this: lab,
For you
timely
willcompletion
learn: of the assignment, start as early as possible. Furthermore, work
smartly - as some of the problems can be solved using smarter logic.
o1. About
Note: Structure
Follow theADT.
given instructions to the letter, failing to do so will result in a zero.
o How to define a Structure, initialize and refer to individual members of a Structure.
Objectives
In this lab, you will learn:
DBMS, RDBMS, ORDBMS with advantages and disadvantage
E-R Model: Analyze the problem with the entities which identify data persisted in the
database which contains entities, attributes.
Concepts
DBMS (Database Management System)
A DBMS is software that allows creation, definition and manipulation of database, allowing
users to store, process and analyze data easily. DBMS provides us with an interface or a tool, to
perform various operations like creating database, storing data in it, updating data, creating
tables in the database and a lot more.
DBMS also provides protection and security to the databases. It also maintains data consistency
in case of multiple users.
Here are some examples of popular DBMS used these days:
• MySql
• Oracle
• SQL Server
• IBM DB2
• PostgreSQL
• Amazon SimpleDB (cloud based) etc.
Advantages of DBMS:
Segregation of application program.
Minimal data duplicity or data redundancy.
Easy retrieval of data using the Query Language.
Reduced development time and maintenance need.
With Cloud Datacenters, we now have Database Management Systems capable of storing
almost infinite data.
Seamless integration into the application programming languages which makes it very
easier to add a database to almost any application or website.
Disadvantages of DBMS:
It's Complexity.
Except MySQL, which is open source, licensed DBMSs are generally costly.
They are large in size.
1 Adam 34 13000
2 Alex 28 15000
3 Stuart 20 18000
4 Ross 42 19020
Tuple
A single entry in a table is called a Tuple or Record or Row. A tuple in a table represents a set of
related data. For example, the above Employee table has 4 tuples/records/rows.
Following is an example of single record or tuple.
1 Adam 34 13000
Attribute
A table consists of several records (row), each record can be broken down into several smaller
parts of data known as Attributes. The above Employee table consists of four
attributes, ID, Name, Age and Salary.
Attribute Domain
When an attribute is defined in a relation (table), it is defined to hold only a certain type of
values, which is known as Attribute Domain. Hence, the attribute Name will hold the name of
employee for every tuple. If we save employee's address there, it will be violation of the
Relational database model.
Name
Adam
Alex
Advantages of RDBMS
It is easy to use.
It is secured in nature.
The data manipulation can be done.
It limits redundancy and replication of the data.
It offers better data integrity.
It provides better physical data independence.
It offers logical database independence i.e. data can be viewed in different ways by the
different users.
It provides better backup and recovery procedures.
It provides multiple interfaces.
Multiple users can access the database which is not possible in DBMS.
Disadvantages of RDBMS
Software is expensive.
Complex software refers to expensive hardware and hence increases overall cost to
avail the RDBMS service.
It requires skilled human resources to implement.
Certain applications are slow in processing.
It is difficult to recover the lost data.
ORDBMS Examples
Examples of ORDBMSs include:
PostgreSQL. Open source ORDBMS developed by the PostgreSQL Global Development
Group.
Oracle Database by Oracle Corporation.
Informix by IBM
SQL Server by Microsoft
Greenplum Database by Pivotal Software
Advantages of ORDBMS
Reusable and Sharable – able to reuse the hard-coded components. Through database
servers those components can be shared among available resources.
Ability of applying Objects with existing RDBMS models as it is – That is, RDBMS can be
extended with Object concepts without changing the underlying models. This leads the
organizations to switch over to ORDBMS concepts easily without performing bigger
migration or major changes.
It allows users and programmers to start using object-oriented systems in parallel.
Object Relational Database Management Systems ensures large storage capacity.
Supports rich data types by adding a new object-oriented layer.
Scalability
Relationships are represented explicitly, often supporting both navigational and
associative access to information.
Improved concurrency - concurrent users can safely query the same data.
Support for Composite data types - data is bundled with its metadata.
Improved integrity - ability to reject bad data before it is stored in an ORDBMS.
Database extensibility - easy addition of data types and operations.
Uniform treatment of data items - the SQL interface can perform complex queries based
on any of these data items, e.g., metadata as well as data; hence there is less need for
custom programming by users.
Custom data access methods - e.g., R-tree indexes.
Point-in-time recovery of data is possible.
Built-in complex SQL functions can be provided for data operations - e.g., aggregating,
slicing, subsetting, reprojecting, etc.
Disadvantages of ORDBMS
Complexity
Increased cost
Unclear if the ORDBMS will actually combine relationships and encapsulated objects to
correctly and completely mirror the ‘real world’.
Relations in RDBMS:
The Relational model allows data to be represented in a simple row- column. Each data field is
considered as a column and each record is considered as a row. Relational Database is more or
less similar to Database Management System. In relational model there is relation between
their data elements. Data is stored in tables. Tables have columns, rows and names. Tables can
be related to each other if each has a column with a common type of information.
Degree of Relationship
The Degree of Relationship indicates the link between two entities for a specified occurrence of
each.
One to One Relationship: (1:1)
Student Has Roll No.
One student has only one Rollno. For one occurrence of the first entity, there can be, at the
most one related occurrence of the second entity, and vice-versa.
Air University Islamabad
FACULTY OF COMPUTING & ARTIFICAL INTELLIGENCE
Department of Creative Technologies
CS130L – Database Systems Lab Manual
Case Study: (Analyze the data required. Create the logical data model using E-R diagrams)
AIM: A database is to be designed for a Car Rental Co. (CRC). The information required includes
a description of cars, subcontractors (i.e. garages), company expenditures, company revenues
and customers. Cars are to be described by such data as: make, model, year of production,
engine size, and fuel type, number of passengers, registration number, purchase price,
purchase date, rent price and insurance details. It is the company policy not to keep any car for
a period exceeding one year.
All major repairs and maintenance are done by subcontractors (i.e. franchised garages), with
whom CRC has long-term agreements. Therefore the data about garages to be kept in the
database includes garage names, addresses, range of services and the like. Some garages
require payments immediately after a repair has been made; with others CRC has made
arrangements for credit facilities. Company expenditures are to be registered for all outgoings
connected with purchases, repairs, maintenance, insurance etc.
Similarly the cash inflow coming from all sources - car hire, car sales, insurance claims - must be
kept in file. CRC maintains a reasonably stable client base. For this privileged category of
customers special credit card facilities are provided. These customers may also book in advance
a particular car. These reservations can be made for any period of time up to one month. Casual
customers must pay a deposit for an estimated time of rental, unless they wish to pay by credit
card. All major credit cards are accepted. Personal details (such as name, address, telephone
number, driving license, number) about each customer are kept in the database.