Database Management System Incourse Note
Set A:
1.What do you mean by DBMS? Discuss the difference between a typical file-processing system and DBMS.
Ans:
The full form of DBMS is data base management system. A data base management system is a system
software for creating and managing databases. A DBMS makes it possible for users to create, protect, read,
update and delete data in a database. DBMS are software systems used to store, retrieve and run queries on
data.
The difference between a typical file processing system and DBMS are as follows:
DBMS Typical file processing system
1.A software to store and retrieve the users data. 1.Used to manage and organize the files stored in
the hard disk of the computer.
2.Query processing is efficient. 2.Query processing is not so efficient.
3.Supports more security mechanisms. 3.Less security mechanisms.
4.Crash recovery mechanism is highly supported. 4.Does not support crash recovery.
5.It is higher in cost than a file system. 5.It is less expensive than DBMS.
2.Write down the difference between E-R model and Relational model. Write the symbols of E-R diagram
with an example.
Ans:
The difference between E-R model and Relational model are as follows:
The symbols of E-R diagram are:
Database Management System Incourse Note
3.What is Data Abstraction? Discuss the different levels of data abstraction.
Ans:
Data abstraction in the context of database management systems (DBMS) refers to the process of hiding
complex implementation details and presenting only the essential features of data. It allows developers to
simplify database design by concealing irrelevant details from users. Let’s delve into the different levels of
data abstraction:
1. Physical or Internal Level:
o This is the lowest level of data abstraction.
o It deals with how data is actually stored in memory.
o Details such as storage blocks, memory usage, and access methods (like sequential or
random access) are considered.
Database Management System Incourse Note
o For example, when storing employee details, the specifics of memory blocks are hidden
from users.
2. Logical or Conceptual Level:
o At this level, data is organized into tables and relationships among data entities are
defined.
o It represents the information stored in the database.
o Users interact with data in a structured format, such as tabular data.
o Attributes of entities (e.g., employee details) and relationships (e.g., manager-employee)
are stored.
3. View or External Level:
o This is the highest level of abstraction.
o Users see only a subset of the actual database.
o Data is presented in the form of rows and columns.
o Multiple views of the same database can exist.
o Implementation details (storage, memory) are hidden from users.
4.What do you mean by DBA?
Ans:
A Database Administrator (DBA) is an individual responsible for managing, maintaining,
and securing databases. DBAs ensure that data is correctly stored, retrieved, and available for analysis in
business operations.
Set B:
1.Write down the main functions of DBA.
Ans:
The main functions of a database administrator includes:
a. The DBA creates the original database schema by executing a set of data definition statements in
the DDL.
b. Storage structure and access method definition: File organization, organization of record in a file,
index definition.
c. Schema and physical-organization modification: The DBA carries out changes to the schema and
physical organization to reflect the charging needs of the organization, or to alter the physical
organization to improve the performance.
d. Granting of authorization for data access: By granting different types of authorization, the DBA can
regulate which parts of the database various users can access.
e. Specifying integrity constraints: The DBA implements key declaration, trigger, assertion, business
rules of the organization.
f. Routine maintenance: Periodically backing up the database, either onto tapes or remote servers, to
prevent loss of data in case of disasters.
2.Define view of data. Discuss different types of data abstraction.
Ans:
View of data: A database system is a collection of interrelated data and set of programs that allow users to
access and modify these data. A major purpose of a database system is to provide users an abstract view of
the data.
To achieve data abstraction, we often use a Three-Schema Architecture, which abstracts the database at
three distinct levels:
Database Management System Incourse Note
1. Physical Level (Internal Level):
o At this level, we describe how data is stored in hardware. It reveals the low-level details of
data storage and access paths.
o Complex data structures are used here, but only database administrators typically operate
at this level.
2. Logical Level (Conceptual Level):
o Above the physical level, we find the logical level.
o Here, data is represented in terms of entity sets, entities, data types, relationships,
and constraints.
o Constraints enhance security by restricting user access to specific parts of the database.
o Developers and database administrators work at this level.
3. View Level (User Level or External Level):
o The highest level of data abstraction is the view level.
o It presents only a subset of the entire database that users are interested in.
o Different views of the same data can coexist.
o Users retrieve information using various applications that interact with the database.
3. Draw and explain the overall system structure of DBMS.
Ans:
A DBMS is a software tool that facilitates the creation, management, and manipulation of databases. It
provides an organized way to store, retrieve, and protect data. Here are the key components of a DBMS:
1. Query Processor:
o The query processor interprets user requests (queries) received from application
programs.
o It translates these queries into low-level instructions (machine language) that can be
executed.
o Components within the query processor include:
▪ DML Compiler: Processes Data Manipulation Language (DML) statements into
executable instructions.
▪ DDL Interpreter: Processes Data Definition Language (DDL) statements, creating
metadata about database objects.
▪ Embedded DML Pre-compiler: Converts DML statements embedded in
application programs into procedural calls.
▪ Query Optimizer: Executes instructions generated by the DML Compiler.
2. Storage Manager:
o The storage manager acts as an interface between the data stored in the database and
incoming queries.
o It ensures consistency, integrity, and security of the database.
o Key components within the storage manager include:
▪ Authorization Manager: Enforces role-based access control, determining user
privileges.
▪ Integrity Manager: Validates integrity constraints when modifying the database.
▪ Transaction Manager: Controls concurrent access, ensuring consistent states
before and after transactions.
▪ File Manager: Manages file space and data structures representing information.
▪ Buffer Manager: Handles cache memory and data transfer between secondary
storage and main memory.
Database Management System Incourse Note
3. Disk Storage:
o The disk storage component includes:
▪ Data Files: Store actual data records.
▪ Data Dictionary: Contains metadata about the structure of database objects.
▪ Indices: Facilitate faster retrieval of data items.
4.What is mapping cardinality? Describe mapping cardinality with example.
Ans:Mapping cardinalities or cardinality ratios express the number of entities to which another entity can be
associated via a relationship set.
There are 4 types of mapping cardinality.
a.One to one: An entity in A is associated with at most one entity in B, and an entity in B is associated with at
most one entity in A.
b.One to many: An entity in A is associated with any number of entities in B. An entity in B, however, can be
associated with at most one entity in A.
Database Management System Incourse Note
c.Many to one: An entity in A is associated with at most one entity in B. An entity in B, however, can be
associated with any number of entities in A.
d.Many to many: An entity in A is associated with any number of entities in A.
5.Construct an E-R diagram for a car-insurance company whose customers own one or more car each. Each
car has associated with it zero to any number of recorded accidents.
Ans:
Set C:
1.Define strong and weak entity set.
Ans:
1. Strong Entity Set:
o A strong entity stands independently within the schema and is not dependent on any
other entity.
o It always possesses a primary key that uniquely identifies its records.
o In an ER diagram, a strong entity is represented by a single rectangle.
o The relationship between two strong entities is depicted by a single diamond.
o When multiple strong entities are combined, they form a strong entity set.
2. Weak Entity Set:
o A weak entity relies on a strong entity for its existence. It cannot stand alone.
o Unlike a strong entity, it lacks a primary key. Instead, it has a partial discriminator key.
o In an ER diagram, a weak entity is symbolized by a double rectangle.
o The relationship between a strong entity and a weak entity is represented by a double
diamond. This relationship is also known as an identifying relationship.
Database Management System Incourse Note
o Weak entities always exhibit total participation (meaning they are fully dependent on the
strong entity).
In summary:
• Strong Entity: Independent, has a primary key, single rectangle.
• Weak Entity: Dependent, lacks a primary key, double rectangle.
2.Define attributes. Describe different types of attributes.
Ans:
Attributes play a crucial role in defining the structure of a database and organizing data efficiently. Here’s
what you need to know:
1. Simple Attributes:
o Also known as atomic attributes, these cannot be further divided into sub-attributes.
o For instance, consider a student’s roll number or an employee’s identification number.
These attributes are assigned by an organization and uniquely identify individuals within
that organization.
2. Composite Attributes:
o Composite attributes are formed by combining more than one attribute.
o For example, in a student table, the student name can be broken down into first
name, middle name, and last name. Thus, the student name becomes a composite
attribute.
o Similarly, an address can be divided into street, area, district, and state.
3. Single-Valued Attributes:
o These attributes can have exactly one value.
o Examples include the date of birth (DOB) of a student or an individual’s gender (since each
person has only one gender).
4. Multi-Valued Attributes:
o These attributes can have multiple entries or contain more than one value.
o In an Entity-Relationship (ER) diagram, we represent multi-valued attributes with a double
oval.
o For instance, a person can have multiple phone numbers, making it a multi-valued
attribute.
5. Derived Attributes:
o Also known as stored attributes, these are derived from other attributes.
o We perform calculations on existing attributes to create derived attributes.
o Examples include a student’s age (derived from their DOB) or an employee’s working
experience (based on their date of joining).
6. Complex Attributes:
o Complex attributes combine the properties of multi-values and composite attributes.
o If an attribute is made up of more than one attribute, and each of those attributes can have
multiple values, it’s considered complex.
o Imagine an attribute that captures both the composition and multiple values—that’s a
complex attribute.
3.Define Key. Describe different types of Key.
Ans:
Database Management System Incourse Note
a key is an attribute or a set of attributes that uniquely identifies a tuple (or row) within a relation (or table).
Keys play a crucial role in ensuring data integrity, establishing relationships between tables, and facilitating
efficient data retrieval. Let’s explore the different types of keys:
1. Primary Key:
o The primary key is the first key used to uniquely identify one and only one instance of an
entity.
o Each entity can have multiple keys, but the one most suitable becomes the primary key.
o For example, in an EMPLOYEE table, the Employee ID can serve as the primary key since it
uniquely identifies each employee.
2. Candidate Key:
o A candidate key is an attribute or set of attributes that can uniquely identify a tuple.
o All candidate keys are as strong as the primary key.
o In the same EMPLOYEE table, attributes like SSN, Passport Number, and License
Number can be considered candidate keys.
3. Super Key:
o A super key is an attribute set that can uniquely identify a tuple.
o It is a superset of a candidate key.
o For example, in the EMPLOYEE table, the combination of Employee ID and Employee
Name forms a super key.
4. Foreign Key:
o A foreign key is a column in one table that points to the primary key of another table.
o It establishes relationships between tables.
o For instance, in an EMPLOYEE table, the Department ID (which is the primary key in
the DEPARTMENT table) serves as a foreign key.
4.What do you mean by Relational Model?
Ans:
The Relational Model is a fundamental concept in database management systems (DBMS). It provides a
structured way to organize and store data in a two-dimensional table format. Let’s explore the key aspects
of the relational model:
1. Tables (Relations):
o A relational database consists of a collection of tables (also known as relations).
o Each table represents a specific entity or concept, such as students, employees,
or products.
o Tables are assigned unique names and contain rows (called tuples) and columns
(called attributes).
2. Attributes:
o Attributes define the properties of an entity.
o Examples of attributes include roll number, name, address, and phone number.
o Each attribute corresponds to a column in the table.
3. Tuples (Rows):
o A tuple represents a single record or instance within a table.
o Each row contains values for each attribute.
o For instance, a student’s information (roll number, name, etc.) forms a tuple.
4. Keys:
o Keys play a crucial role in the relational model.
Database Management System Incourse Note
o The primary key uniquely identifies each tuple within a table.
o Other types of keys include candidate keys, super keys, and foreign keys.
5. Schema:
o The schema defines the structure of a relation.
o It specifies the relation name and the attributes along with their data types.
o For example, the schema for a student table could be: STUDENT (ROLL_NO, NAME,
ADDRESS, PHONE, and AGE).
6. Constraints:
o Constraints ensure data integrity and consistency.
o Examples include domain constraints (valid attribute values) and key
constraints (uniqueness of keys).
7. Degree and Cardinality:
o The degree of a relation is the number of attributes it contains.
o The cardinality is the number of tuples (rows) in a relation.
Set D:
1.Define Relational Algebra. Write down the fundamental operations of relational algebra with examples.
Ans:
Relational Algebra: It’s a procedural query language used in database management systems (DBMS) to
manipulate and retrieve data from relational databases. Relational algebra operates on relations (tables)
and provides a set of fundamental operations. Here are the key operations along with examples:
1. SELECT (σ):
o The SELECT operation filters rows based on a given condition (predicate).
o Symbol: σ
o Example 1: Select tuples from the “Tutorials” table where the topic is ‘Database’:
o σ topic = "Database" (Tutorials)
o Example 2: Select tuples from “Tutorials” where the topic is ‘Database’ and the author is
‘guru99’:
o σ topic = "Database" and author = "guru99" (Tutorials)
o Example 3: Select tuples from “Customers” where sales are greater than 50,000:
o σ sales > 50,000 (Customers)
2. PROJECTION (π):
o The PROJECTION operation selects specific columns (attributes) from a relation.
o Symbol: π
o Example: From the “Customers” table, project the “CustomerName” and “Status”:
o Π CustomerName, Status (Customers)
3. RENAME (ρ):
o The RENAME operation changes the name of a relation or its attributes.
o Example: Rename the attribute ‘b’ of relation R to ‘a’:
o ρ (a/b)R
4. UNION (∪):
o The UNION operation combines tuples from two relations (A and B) without duplicates.
o Example: Combine all tuples from tables A and B:
o A∪B
5. INTERSECTION (∩):
o The INTERSECTION operation returns common tuples from both relations (A and B).
o Example: Find tuples common to tables A and B:
Database Management System Incourse Note
o A∩B
6. DIFFERENCE (-):
o The DIFFERENCE operation returns tuples present in A but not in B.
o Example: Find tuples in table A that are not in table B:
A-B
2.For Customer ( customer_name, customer_street, customer_city) and Loan (loan_no, branch_name,
amount) relation, give relational algebra expression for the following queries:
i)Find out those tuples who have loans of more than $3250 at Perryridge branch.
ii)Find out those customers who live in Harison city.
Ans:
i) To find out those tuples who have loans of more than $3250 at Perryridge branch, you can use the
selection operation in relational algebra:
σ_amount > 3250 ∧ branch_name = 'Perryridge' (loan)
Here, σ is the selection operation, amount > 3250 and branch_name = 'Perryridge' are the conditions, and
loan is the name of the table.
ii) To find out those customers who live in Harison city, you can use the selection operation in relational
algebra:
σ_customer_city = 'Harison' (customer)
Here, σ is the selection operation, customer_city = 'Harison' is the condition, and customer is the name of
the table.
Set E:
1.Define E-R model. Draw an E-R diagram for the following schemas:
person(driver_id, name, address)
car(license, model, year)
accident(report_no, date, location)
owns(driver_id, license)
participated(driver_id, license, report_no, damage_amount)
Ans:
An Entity-Relationship (E-R) Diagram is a type of flowchart that illustrates how “entities” such as people,
objects, or concepts relate to each other within a system. E-R diagrams are most commonly used to design
or debug relational databases in fields such as software engineering, business information systems,
education, and research.
Database Management System Incourse Note
2. For branch (branch_name, branch_city, assets)
Database Management System Incourse Note
customer (customer_name, customer_street, customer_city)
account (account_number, branch_name, balance)
loan (loan_number, branch_name, amount)
depositor (customer_name, account_number) and
borrower (customer_name, loan_number) relation,
give relational—algebra expression for the following queries:
i. Find the loan number for each loan of an amount greater than $ 4200.
ii.Find the names of all customers who have a loan at the perryridge branch but do
not have an account at any branch of the bank.
iii.Find out the customer's names that have an account but not loan?
Ans:
E-R diagram:
i. Find the loan number for each loan of an amount greater than $ 4200. Ans: σ_amount > 4200
(loan)
Database Management System Incourse Note
ii. ii.Find the names of all customers who have a loan at the perryridge branch but do not have an
account at any branch of the bank. Ans: π_customer_name (σ_branch_name = 'Perryridge'
(loan)) - π_customer_name (depositor)
iii. iii.Find out the customer's names that have an account but not loan? Ans: π_customer_name
(depositor) - π_customer_name (borrower)
Set F:
1.Write short notes with (any two):
a)ACID properties
Ans:
Database Management Systems (DBMS), the ACID properties play a crucial role in ensuring the reliability
and consistency of transactions. Let’s delve into each of these properties:
1. Atomicity:
o Definition: Atomicity ensures that a transaction either fully completes or doesn’t happen
at all. There is no midway; transactions do not occur partially.
o Example: Imagine a transaction involving transferring $100 from account X to account Y. If
the transaction fails after completion of the first step (debiting X) but before the second
step (crediting Y), it would result in an inconsistent database state. Therefore, atomicity
ensures that the entire transaction runs to completion or remains unexecuted.
2. Consistency:
o Definition: Consistency refers to maintaining integrity constraints so that the database
remains consistent before and after a transaction.
o Example: Consider the total amount in accounts X and Y before and after the transaction. If
the total remains the same, the database is consistent. Inconsistency occurs if one part of
the transaction completes (e.g., T1) but another part fails (e.g., T2).
3. Isolation:
o Definition: Isolation ensures that multiple transactions can occur concurrently without
affecting the database’s consistency.
o Example: Transactions occur independently, and changes made in one transaction are not
visible to others until committed. Proper isolation prevents inconsistencies due to
interleaved operations.
4. Durability:
o Definition: Durability guarantees that once a transaction completes execution, the
updates and modifications to the database are persistently stored, even in the event of
system failures.
o Example: Even if the system crashes, the changes made by committed transactions
remain intact.
b)Generalization and Specialization
Ans:
1. Generalization:
o Definition: Generalization is a process that abstracts common properties from multiple
entities, creating a single generalized entity.
o Approach: It follows a bottom-up approach.
Database Management System Incourse Note
o How It Works:
▪ Lower-level entities are combined to form higher-level entities.
▪ Properties are drawn from specific entities to create a more generalized entity.
▪ This process can be repeated to create advanced-level entities.
o Example:
▪ Consider two entities: Student and Patient.
▪ Both have their own characteristics (e.g., Roll_No, Name, Mob_No for Student; PId,
Name, Mob_No for Patient).
▪ By combining the common properties (Name and Mob_No), we can create a
higher-level entity called Person through generalization.
o Summary: Generalization combines subclasses to form a superclass.
2. Specialization:
o Definition: Specialization is the opposite of generalization. It involves breaking down a
general entity into distinct sub-entities.
o Approach: It follows a top-down approach.
o How It Works:
▪ A particular entity is divided into sub-entities based on specific characteristics.
▪ Inheritance occurs, where specialized entities inherit characteristics from the
higher-level entity.
o Example:
▪ Consider an entity called Account.
▪ It has attributes like Acc_No and Balance.
▪ We further specialize it into Current_Acc (with additional attributes
like Transactions) and Savings_Acc (with Interest_Rate).
o Summary: Specialization creates sub-entities within an entity set.
In summary:
• Generalization reduces the size of the schema by creating groupings from various entity sets.
• Specialization increases the size of the schema by dividing a single entity into sub-entities based
on characteristics.
• Both processes contribute to data organization and inheritance in database modeling.
c)Aggregate function
Ans:
In the context of Database Management Systems (DBMS), aggregate functions are used to perform
calculations on sets of data. These functions take a set of values as input and return a single value as
output. They are often used to generate summary statistics on large datasets. Let’s explore some common
aggregate functions:
1. COUNT Function:
o Definition: The COUNT function calculates the number of rows in a database table. It can
work on both numeric and non-numeric data types.
o Syntax:
▪ COUNT(*) returns the count of all rows in a specified table, considering duplicates
and null values.
▪ COUNT(expression) returns the count of non-null values for the specified
expression.
Database Management System Incourse Note
o Example:
▪ To count the total number of rows in the PRODUCT_MAST table: SELECT COUNT(*)
FROM PRODUCT_MAST;
▪ To count the number of rows where the RATE is greater than or equal to 20: SELECT
COUNT(*) FROM PRODUCT_MAST WHERE RATE >= 20;
▪ To count the distinct company names in the PRODUCT_MAST table: SELECT
COUNT(DISTINCT COMPANY) FROM PRODUCT_MAST;
▪ To count the number of products per company: SELECT COMPANY, COUNT(*)
FROM PRODUCT_MAST GROUP BY COMPANY;
▪ To filter companies with more than 2 products: SELECT COMPANY, COUNT(*)
FROM PRODUCT_MAST GROUP BY COMPANY HAVING COUNT(*) > 2;
2. SUM Function:
o Definition: The SUM function calculates the sum of all selected numeric columns.
o Syntax:
▪ SUM(expression) calculates the sum of the specified expression.
o Example:
▪ To find the total cost of all products: SELECT SUM(COST) FROM PRODUCT_MAST;
▪ To find the total cost of products where the quantity is greater than 3: SELECT
SUM(COST) FROM PRODUCT_MAST WHERE QTY > 3;
▪ To find the total cost per company for products with quantity greater than
3: SELECT SUM(COST) FROM PRODUCT_MAST WHERE QTY > 3 GROUP BY
COMPANY;
▪ To filter companies with a total cost of at least 170: SELECT COMPANY,
SUM(COST) FROM PRODUCT_MAST GROUP BY COMPANY HAVING SUM(COST) >=
170;
3. AVG Function:
o Definition: The AVG function calculates the average value of numeric data.
o Syntax:
▪ AVG(expression) returns the average of all non-null values for the specified
expression.
o Example:
▪ To find the average cost of products: SELECT AVG(COST) FROM PRODUCT_MAST;
4. MAX Function:
o Definition: The MAX function finds the maximum value of a certain column.
o Syntax:
▪ MAX(expression) determines the largest value of all selected values of a column.
o Example:
▪ To find the maximum cost among all products: SELECT MAX(COST) FROM
PRODUCT_MAST;
2.Define candidate Key, Primary Key, composite Key.
Ans:
1. Candidate Key:
o A candidate key is a set of one or more columns in a database table that can uniquely
identify each row.
o It is a potential primary key because it satisfies the uniqueness requirement.
o A table can have multiple candidate keys.
Database Management System Incourse Note
o Example:
▪ Consider a table of students with attributes like StudentID, RollNumber,
and Email.
▪ Both StudentID and RollNumber can individually serve as candidate keys.
▪ If we choose StudentID as the primary key, RollNumber becomes an alternate
candidate key.
2. Primary Key:
o The primary key is a specific candidate key chosen to uniquely identify each row in a table.
o It is mandatory for every table.
o Only one primary key can exist per table.
o Example:
▪ In the student table, if we select StudentID as the primary key, it ensures
uniqueness and efficient data retrieval.
3. Composite Key:
o A composite key is a key formed by combining two or more columns.
o It uniquely identifies rows when considered together.
o Composite keys are often used when no single column can uniquely identify a row.
o Example:
▪ Imagine an appointment system where appointments are scheduled
by ClientID, CounselorID, and AppointmentTime.
▪ The combination of these three columns forms a composite key.
▪ Any of these combinations can uniquely identify an appointment.
In summary:
• Candidate keys are potential primary keys.
• The primary key is the chosen candidate key for uniqueness.
• A composite key consists of multiple columns working together to uniquely identify rows.
3.Define tuple and domain relational calculus.
Ans:
1. Tuple Relational Calculus (TRC):
o Definition:
▪ TRC is a non-procedural query language used to specify queries in terms of logical
formulas.
▪ It selects tuples (rows) from a relation based on certain conditions.
o Variables:
▪ In TRC, variables represent tuples from specified relations.
o Notation:
▪ {T | P(T)} or {T | Condition(T)} where:
▪ T represents the resulting tuples.
▪ P(T) is a condition used to fetch T.
o Example:
▪ {T | EMPLOYEE(T) AND T.DEPT_ID = 10} selects all the tuples of employee names
who work for Department 10.
2. Domain Relational Calculus (DRC):
o Definition:
Database Management System Incourse Note
▪ DRC is similar to TRC but differs in that it selects attributes (columns) rather than
entire tuples.
▪ It uses domain variables and quantifiers to specify constraints on the attributes to
be returned.
o Variables:
▪ In DRC, variables represent values drawn from a specified domain (equivalent to
column data types).
o Notation:
▪ { a1, a2, ..., an | P(a1, a2, ..., an) } where:
▪ a1, a2, ..., an are attributes of the relation.
▪ P is the condition.
o Example:
▪ { | <EMPLOYEE> DEPT_ID = 10 } selects EMP_ID and EMP_NAME of employees who
work for department 10.
Key Differences:
• TRC selects entire tuples, while DRC selects attributes.
• TRC variables represent tuples, while DRC variables represent domain elements (values).
• TRC reflects traditional pre-relational file structures, while DRC is more similar to logic as a
modeling language.