DBMS 1: Introduction + ER Diagram + Functional Dependency
DBMS 1: Introduction + ER Diagram + Functional Dependency
Restaurant Case Study: Let’s say we own a restaurant and we receive orders from
multiple customers every day that we can deliver to the customer using the information
of their name, contact number, and address. Also, we plan to send their bills to their
email address for customer reference.
We plan to store this data of the customer so that every time we receive the data from
the same customer we don’t ask for the same information.
In past (when technology was not used much) this data was stored in
registers/notebooks which involved some inconveniences like:
1. Data is stored in an unorganized way so searching for the customer data was a
manual process.
2. If the number of customers is high then maintaining multiple records was a pain.
3. If any customer changes his/her address of delivery then updating that in the
record was a task that might not be possible due to less space in the page
containing the data. Creating new data and deleting old records could be an
option. And so on…
Database: The database is a systematic collection of interrelated data which is used to:
a. Retrieve the data,
b. Insert the data, and
c. Delete the data efficiently.
Let’s understand Entity, Attributes & Relationships using the Uber System:
1. Entity: Core identities wrt which the data needs to be stored. Eg (In Uber): users,
drivers, trips, etc.
2. Attributes: Data of each of the entities. Eg (In Uber):
a. Name, contact number, email id, etc. - of Users
b. Name, contact number, vehicle number, etc. - of Drivers
c. Start time, End Time, Start Location, Drop Location, etc. - of Trips and …
3. Relationship between the entities. Eg (In Uber): Driver drives a Cab. Here drives
is a relationship between Driver and Cab.
Types of Attributes
Simple Attribute: Attributes that are Composite Attribute: Attributes that are
atomic in nature and cannot be divided not atomic and can be divided. Eg: Name
any further. Eg: Contact Number, Age, of a person can be divided into First
etc. Name, Middle Name & Last Name, etc.
Derived Attribute: Attributes that are not Multivalued Attribute: Attributes that
stored in the database but their value can have more than one value. Eg: a user can
be derived from the other attributes that have more than one contact number or
are stored in the database. Eg: The age email id, therefore contact number &
of a person can be derived from the DOB. email id are multivalued attributes.
Each entity can be stored like a table where each row will be one unique entity and
columns will be attributes of that entity. Eg; User Table can have each row storing the
data of a user and columns can be user name, contact number, email id, etc.
Keys
Super Key: An attribute or set of Candidate Key: A super key such that no
attributes that uniquely identifies a proper subset is a super key within the
tuple/row within a table. Eg: relation. Eg:
a. Name & vehicle number can be c. Only vehicle numbers can be used
used to uniquely identify a Driver. to uniquely identify a Driver.
b. User name, contact number, and d. Only contact numbers can be used
DOB can be used to uniquely to uniquely identify a User.
identify a User. e. User contact number and vehicle
number can be used to uniquely
identify a Trip.
Primary Key: A candidate key that will be Foreign Key: Attributes of one table that
used as a standard to uniquely identify a are used to point Primary Key of another
tuple/row within a relation. The table.
unselected candidate keys are known as Eg: Trip booking contact number can be a
Alternate Keys. Foreign key in the Trips table but can be
Eg: Let’s say a user contact number is Primary Key in the User table. (the user
selected as a standard in the Uber who booked the trip can be uniquely
system to identify the user, then the identified with the contact number from
contact number is the primary key. But which the trip was booked.)
user email id can also be used to identify
a user uniquely therefore email id is an
alternate Key.
Eg of Foreign Key:
Cardinality of a Relationship:
1. One - to - One:
Eg: Driver - to - Cab → one driver can only drive one cab (i.e. registered to
this driver) and one cab can only be driven by one driver.
2. One - to - Many:
Eg: Driver - to - Trip → one driver can take multiple trips but one trip can
only be driven by one driver.
3. Many - to - One:
Eg: Trip - to - Driver → One trip can only be driven by one driver but one
driver can take multiple trips.
4. Many - to - Many:
Eg: User - to - Driver → Multiple users can ride with multiple drivers and
multiple drivers can give rides to multiple users.
1. Before storing any data one should have a clear picture of what needs to be
stored and how to organize it well for faster retrieval and update.
2. ER Diagram is the first step of designing any database.
3. It’s a diagram that shows all the entities with their attributes and the relationship
between the entities.
Symbols in ER Diagram:
1. Rectangle - Entity
2. Ellipse - Attribute
3. Double Ellipse - Multivalued Attribute
4. Underlined Ellipse - Primary Key Attribute
5. Diamond - Relationship
6. Lines - Link between: entities & attributes, entities & relationships, and
relationship & attributes.
Steps to create ER Diagram:
Mapping Attributes:
1. Mapping on Entities:
2. Mapping on Relationships:
Functional Dependency
Eg:
1. Contact_Number → User_Name, if we know the contact number of a user than
we can uniquely identify the user name.
2. User_Id → User_Name, Contact_Number, Email_Id - if we know the user id of
a user than we can uniquely identify the user name, contact number & email id.
3. Pincode → City, etc.
Eg: F: X → Y, X → Z, Z → A