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

Assignments(1,2,3)-1

The document provides definitions and explanations of key database concepts such as schema, DBMS, data independence, and data abstraction. It outlines the roles and tasks of a Database Administrator, types of database users, and advantages of DBMS over traditional file processing systems. Additionally, it includes instructions for creating E-R diagrams for various systems, details on database keys, relational algebra operations, and integrity constraints.

Uploaded by

xbu029
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Assignments(1,2,3)-1

The document provides definitions and explanations of key database concepts such as schema, DBMS, data independence, and data abstraction. It outlines the roles and tasks of a Database Administrator, types of database users, and advantages of DBMS over traditional file processing systems. Additionally, it includes instructions for creating E-R diagrams for various systems, details on database keys, relational algebra operations, and integrity constraints.

Uploaded by

xbu029
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Assignment-1

1) Define following terms.


a. Schema
b. Database Management System
c. Physical Data Independence
d. Data Abstraction
e. Instance
a. Schema:
A schema is the structure of a database. It defines how data is organized, including tables,
fields, and relationships between them.
b. Database Management System (DBMS):
A DBMS is software that manages databases. It allows users to store, modify, and retrieve
data efficiently while ensuring security and integrity.
c. Physical Data Independence:
Physical data independence means changes in the way data is stored (like moving data to a
different location) do not affect how the data is accessed or used by applications.
d. Data Abstraction:
Data abstraction hides the complex details of how data is stored, allowing users to interact
with the data more easily. It involves three levels: physical (how data is stored), logical
(what data is stored), and view (how users see the data).
e. Instance:
An instance is the actual data in a database at a specific point in time. It is like a snapshot of
the database content at that moment.

2) Describe tasks performed by the Database Administrator


• Database Design: Creating the structure of the database.
• User Management: Controlling who can access the database and what they can do.
• Performance Tuning: Ensuring the database runs efficiently.
• Backup and Recovery: Making sure data is saved regularly and can be restored in
case of a problem.
• Security Management: Protecting the database against unauthorized access.
• Software Maintenance: Installing updates and patches for the database software.
• Monitoring and Maintenance: Regularly checking the health and performance of the
database.

3) List the type of database users. Explain their characteristics in brief, how they
interact with DBMS?
• End Users: People who use applications to interact with the database, often without
directly knowing the database itself.
• Application Programmers: Developers who write software that interacts with the
database.
• DBAs (Database Administrators): People responsible for managing the database.
• System Analysts: Professionals who analyze user needs and help design databases to
meet those needs.
• Sophisticated Users: Users who write complex queries and interact directly with the
database.
• Database Designers: People who define the structure of the database.

4) State the advantages of Database management systems over file processing system
• Less Data Redundancy: Less duplicate data.
• Better Data Integrity: Ensures data is accurate and consistent.
• Improved Data Security: Better control over who can see or change data.
• Data Independence: Changes to data storage do not affect how data is used.
• Efficient Data Access: Faster and more efficient data retrieval.
• Backup and Recovery: Easier to back up and restore data.
• Concurrent Access: Supports multiple users accessing data at the same time without
conflict.
5) Explain database system 3 tier architecture with clear diagram in detail.
+------------------+
| Presentation Tier|
| (User Interface) |
+------------------+
|
|
+------------------+
| Application Tier |
| (Logic & Process)|
+------------------+
|
|
+------------------+
| Data Tier |
| (Data Storage) |
+------------------+

The 3-tier architecture of a database system includes:


1. Presentation Tier:
The top layer where users interact with the application, like a web browser or mobile
app.
2. Application Tier:
The middle layer where the business logic is processed. It acts as a bridge between
the user interface and the database, processing requests and sending data back and
forth.
3. Data Tier:
The bottom layer where the actual data is stored in the database.
Assignment 2

1. Draw E-R diagram for Bank Management System.


An Entity-Relationship (E-R) diagram visually represents the entities (like customers,
accounts) in a system and their relationships (like "owns," "has") to each other.
Entities and Attributes for a Bank Management System:
• Customer:
o Attributes: Customer_ID (Primary Key), Name, Address, Phone_Number
• Account:
o Attributes: Account_Number (Primary Key), Account_Type, Balance
• Transaction:
o Attributes: Transaction_ID (Primary Key), Date, Amount, Transaction_Type
• Loan:
o Attributes: Loan_ID (Primary Key), Loan_Type, Loan_Amount, Interest_Rate
• Branch:
o Attributes: Branch_ID (Primary Key), Branch_Name, Location
Relationships:
• Customer - Account: A customer can have multiple accounts (1
relationship).
• Account - Transaction: An account can have multiple transactions (1
relationship).
• Customer - Loan: A customer can take multiple loans (1
relationship).
• Branch - Account: A branch can have multiple accounts (1
relationship).
• Branch - Customer: A branch can have multiple customers, and a customer can be
associated with one or more branches (M
relationship).
2. Define E-R diagram. Draw an E-R diagram for Library Management
System. Assume relevant entities and attributes for the given system.
2. Define E-R Diagram and E-R Diagram for Library Management System
An E-R diagram is a visual representation used to model data or database structure. It
illustrates entities, their attributes, and relationships.
Entities and Attributes for a Library Management System:
• Book:
o Attributes: Book_ID (Primary Key), Title, Author, ISBN, Publisher, Year
• Member:
o Attributes: Member_ID (Primary Key), Name, Address, Phone_Number,
Membership_Type
• Loan:
o Attributes: Loan_ID (Primary Key), Loan_Date, Return_Date
• Staff:
o Attributes: Staff_ID (Primary Key), Name, Position, Hire_Date
Relationships:
• Member - Loan: A member can have multiple loans (1
relationship).
• Book - Loan: A book can be loaned out multiple times (1
relationship).
• Staff - Loan: Staff is responsible for issuing or returning books (1
relationship).

3. Construct an E-R diagram for a car-insurance company whose customers


own one or more cars each. Each car has associated with it zero to any
number of recorded accidents.
Entities and Attributes:
• Customer:
o Attributes: Customer_ID (Primary Key), Name, Address, Phone_Number
• Car:
o Attributes: Car_ID (Primary Key), Model, Year, License_Plate
• Accident:
o Attributes: Accident_ID (Primary Key), Date, Description, Location
Relationships:
• Customer - Car: A customer can own multiple cars, but each car is owned by one
customer (1
relationship).
• Car - Accident: A car can have multiple accidents, but each accident is associated
with one car (1
relationship).

4. Design a database for an airline. The database must keep track of


customers and their reservations, flights and their status, seat assignments
on individual flights, and the schedule and routing of future flights. Your
design should include an E-R diagram, a set of relational schemas, and a
list of constraints, including primary-key and foreign-key constraints.
Entities and Attributes:
• Customer:
o Attributes: Customer_ID (Primary Key), Name, Address, Phone_Number
• Reservation:
o Attributes: Reservation_ID (Primary Key), Date, Status
• Flight:
o Attributes: Flight_ID (Primary Key), Source, Destination, Status,
Departure_Time, Arrival_Time
• Seat:
o Attributes: Seat_ID (Primary Key), Seat_Number, Class
• Schedule:
o Attributes: Schedule_ID (Primary Key), Flight_Date, Flight_Time
Relationships:
• Customer - Reservation: A customer can make multiple reservations (1
relationship).
• Reservation - Flight: A reservation is linked to a specific flight (1
relationship).
• Flight - Seat: A flight has multiple seats assigned (1
relationship).
• Flight - Schedule: A flight can have multiple schedules (1
relationship).
Relational Schemas:
• Customer: Customer(Customer_ID, Name, Address, Phone_Number)
• Reservation: Reservation(Reservation_ID, Customer_ID, Flight_ID, Date, Status)
• Flight: Flight(Flight_ID, Source, Destination, Status, Departure_Time, Arrival_Time)
• Seat: Seat(Seat_ID, Flight_ID, Seat_Number, Class)
• Schedule: Schedule(Schedule_ID, Flight_ID, Flight_Date, Flight_Time)
5. Design a database for a hospital with a set of patients and a set of medical
doctors. Associate with each patient a log of the various tests and
examinations conducted. Your design should include an E-R diagram, a
set of relational schemas, and a list of constraints, including primary-key
and foreign-key constraints.
Entities and Attributes:
• Patient:
o Attributes: Patient_ID (Primary Key), Name, Age, Address, Phone_Number
• Doctor:
o Attributes: Doctor_ID (Primary Key), Name, Specialty, Contact_Number
• Test:
o Attributes: Test_ID (Primary Key), Test_Name, Test_Date, Results
• Examination:
o Attributes: Exam_ID (Primary Key), Exam_Date, Diagnosis
Relationships:
• Patient - Test: A patient can undergo multiple tests (1
relationship).
• Patient - Examination: A patient can have multiple examinations (1
relationship).
• Doctor - Examination: A doctor can conduct multiple examinations (1
relationship).
Relational Schemas:
• Patient: Patient(Patient_ID, Name, Age, Address, Phone_Number)
• Doctor: Doctor(Doctor_ID, Name, Specialty, Contact_Number)
• Test: Test(Test_ID, Patient_ID, Test_Name, Test_Date, Results)
• Examination: Examination(Exam_ID, Patient_ID, Doctor_ID, Exam_Date, Diagnosis)
Constraints:
• Primary Keys: Patient_ID, Doctor_ID, Test_ID, Exam_ID
• Foreign Keys: Patient_ID in Test and Examination references Patient, Doctor_ID in
Examination references Doctor
Assignment-3

1. Explain super key, candidate key, primary key and foreign key.
1. Keys in a Database
• Super Key:
A super key is any combination of attributes that uniquely identifies a row in a table.
A super key can have redundant attributes. For example, in a table Employee(eno,
ename, salary), both eno and (eno, ename) are super keys because they uniquely
identify a record.
• Candidate Key:
A candidate key is a minimal super key, meaning it has no redundant attributes. It
uniquely identifies a row in a table. In the example Employee(eno, ename, salary),
eno is a candidate key because it is minimal and uniquely identifies a row.
• Primary Key:
A primary key is a candidate key that is chosen by the database designer to uniquely
identify rows in a table. It cannot have NULL values. In Employee(eno, ename,
salary), eno can be chosen as the primary key.
• Foreign Key:
A foreign key is an attribute or a set of attributes in one table that references the
primary key of another table, establishing a relationship between the two tables. For
example, if there is another table Department(dno, dname, eno), eno in Department
could be a foreign key that references eno in Employee.

2. Which type of queries would be solved by Division operator? Explain with


examples.
The division operator is used to find rows in one relation (table) that are associated with all
rows in another relation. It's typically used for "for all" queries.
Example:
Consider two relations:
• Employee_Project(employee_id, project_id)
• Project(project_id)
To find employees who have worked on all projects:
• Employee_Project ÷ Project
The result will be the set of employee_ids who have worked on every project_id in the
Project relation.

3. List unary relational operators and explain with example


Unary relational operators operate on a single relation. The most common unary operators
are:
• Select (σ): Used to filter rows based on a condition.
o Example: σ salary < 20000 (Employee) retrieves employees with a salary less
than 20,000.
• Project (π): Used to select specific columns from a table.
o Example: π ename (Employee) retrieves only the employee names.
• Rename (ρ): Used to rename the relation or its attributes.
o Example: ρ EmployeeNewName (Employee) renames the relation to
EmployeeNewName.

4. Describe the Cartesian Product operation in relational algebra.


The Cartesian Product (also known as the cross-product) combines two relations into one. It
pairs every row in the first relation with every row in the second relation.
Example:
If A has 2 rows and B has 3 rows:
• A × B will have 2×3=62 \times 3 = 62×3=6 rows.

5. What is join? Explain various type of joins with example.


5. Join Operations in Relational Algebra
A join operation combines rows from two or more tables based on a related column
between them.
Types of Joins:
• Inner Join: Combines rows from both tables that have matching values.
• Example: Find all employees with job assignments.
SELECT Employee.employee_id, Employee.name, Works.job
FROM Employee
INNER JOIN Works ON Employee.employee_id = Works.employee_id;
• Left Outer Join (Left Join): Returns all rows from the left table and matching rows
from the right table. Non-matching rows in the right table are filled with NULLs.
• Example: Find all employees, including those without job assignments.
SELECT Employee.employee_id, Employee.name, Works.job
FROM Employee
LEFT JOIN Works ON Employee.employee_id = Works.employee_id;
• Right Outer Join (Right Join): Returns all rows from the right table and matching
rows from the left table. Non-matching rows in the left table are filled with NULLs.
• Example: Find all jobs, including those not assigned to any employee.
SELECT Employee.employee_id, Employee.name, Works.job
FROM Employee
RIGHT JOIN Works ON Employee.employee_id = Works.employee_id;
• Full Outer Join: Returns all rows when there is a match in either left or right table.
Non-matching rows in both tables are filled with NULLs.
• Example: Find all employees and all jobs, including unmatched ones.
SELECT Employee.employee_id, Employee.name, Works.job
FROM Employee
FULL OUTER JOIN Works ON Employee.employee_id = Works.employee_id;
• Natural Join: Automatically joins tables based on columns with the same name and
datatype.
• Example: Automatically join Employee and Works on employee_id.
SELECT Employee.employee_id, Employee.name, Works.job
FROM Employee
NATURAL JOIN Works;

6. What is integrity constraint?


Integrity constraints are rules that ensure the accuracy and consistency of data within a
database. Common types include:
• Primary Key Constraint: Ensures that each value in a primary key column is unique
and not NULL.
• Foreign Key Constraint: Ensures that a value in a foreign key column must match a
value in the referenced primary key column or be NULL.
• Unique Constraint: Ensures all values in a column are different.
• Check Constraint: Ensures the values in a column meet a specific condition.
• Not Null Constraint: Ensures that a column cannot have a NULL value.

7. Write Relational Algebra syntax for the following queries.


Employee(eno,ename,salary,designation)
Customer(cno,cname,address,city)
a. Find out name of employees who are ‘Manager’.
π ename (σ designation = 'Manager' (Employee))
b. Display name of customers.
π cname (Customer)
c. Retrieve Employee records whose salary is less than 20,000.
σ salary < 20000 (Employee)

8. Write Relational Algebra syntax for the given queries using the following database.
Employee(eno,ename,salary,designation)
Customer(cno,cname,address,city)
a. Find out name of employees who are also customers.
π ename (Employee) ∩ π cname (Customer)

b. Find out name of person who are employees but not customers.
π ename (Employee) - π cname (Customer)
c. Display all names who are either employees or customers.
π ename (Employee) ∪ π cname (Customer)
9. Consider the relational database given below. Give an expression in the relational
algebra to express each of the following queries:
Employee (person-name, street, city),
Works (person-name, company-name, salary),
Company (company-name, city),
Manages (person-name, manager-name)
a. Find name of all employees.
π person-name (Employee)

b. Find city of employee whose name is ‘jashu’.


π city (σ person-name = 'Jashu' (Employee))

c. Find name and city of all employees who are having salary>50000.
π person-name, city (σ salary > 50000 (Employee ⨝ Works))

d. Find total salary of all employees who are working for compa ny ‘HCL’.
SUM (π salary (σ company-name = 'HCL' (Works)))

10. Consider the following relational database schema consisting of thefour relation
schemas:
passenger ( pid, pname, pgender, pcity)
agency ( aid, aname, acity)
flight (fid, fdate, time, src, dest)
booking (pid, aid, fid, fdate)
Answer the following questions using relational algebra queries.
a. Get the details about all flights from Chennai to New Delhi.
σ src = 'Chennai' ∧ dest = 'New Delhi' (flight)

b. Get the complete details of all flights to New Delhi.


σ dest = 'New Delhi' (flight)
c. Find the passenger names for passengers who have bookings on at least one
flight.
π pname (passenger ⨝ booking)

You might also like