Professional Documents
Culture Documents
Application
program End-user
DBMS
1-2
What is DBMS
A database management system (DBMS) is a software
package designed to define, manipulate, retrieve and
manage data in a database.
DBMS =
Collection of interrelated data plus Set of programs to
access the data
This is an extension of the Hierarchical model. In this model data is organized more
like a graph, and are allowed to have more than one parent node.
❑ In object oriented data model (OODM), both data and their relationships are contained
in a single structure known as an object.
❑ OODM is the basis for the object-oriented database management system (OODBMS).
Example of an XML Document
<?xml version=“1.0”/>
<address>
<name>Alice Lee</name>
<email>alee@aol.com</email>
<phone>212-346-1234</phone>
<birthday>1985-03-22</birthday>
</address>
XML Files are Trees
address
Student table
Stu_Name Stu_Age
Steve 23
John 24
Robert 28
Steve 29
Carl 29
Super Key
Super keys: All of the following sets of super key are able to uniquely identify a row
of the employee table. The above table has following super keys.
{Emp_SSN}
{Emp_Number}
{Emp_SSN, Emp_Number}
{Emp_SSN, Emp_Name}
{Emp_SSN, Emp_Number, Emp_Name}
{Emp_SSN}
{Emp_Number}
Only these two sets are candidate keys as all other sets are having redundant
attributes that are not necessary for unique identification.
Course_enrollment table Course_Id is primary key and Stu_Id is non primary key.
However Stu_Id is primary key of Student table.
In the below example the Stu_Id column in Course_enrollment table is a foreign key
as it points to the primary key of the Student table.
Course_Id Stu_Id
C01 101 Stu_Id Stu_Name Stu_Age
C02 102 101 Chaitanya 22
C03 101 102 Arya 26
C05 102 103 Bran 25
C06 103 104 Jon 21
C07 102
Composite key /Compound Key
Definition of Composite key: A key that has more than one attributes is known as
composite key. It is also known as compound key.
Table – Sales
None of these columns alone can play a role of key in this table. Based on this, it
is safe to assume that the key should be having more than one attributes:
• Column cust_Id alone cannot become a key as a same customer can place
multiple orders, thus the same customer can have multiple entires.
• Column order_Id alone cannot be a primary key as a same order can contain
the order of multiple products, thus same order_Id can be present multiple
times.
• Column product_count alone cannot be a primary key because two orders can
be placed for the same product count.
Database Languages: SQL Commands/Queries
1. DDL – Data Definition Language
2. DML – Data Manipulation Language
3. TCL – Transaction Control Language
4. DQL – Data Query Language
5. DCL – Data Control Language
Types of Users in database system
❑ Naïve Users (Web users/ User of ATM machine)
❑ Application Programmers
❑ Sophisticated Users(analyst)
❑ Database Administrators
Database System Architecture/ Components
❖ Types of Users:
❑ Naïve Users (Web users/ User of ATM machine)
❑ Application Programmers
❑ Sophisticated Users(analyst)
❑ Database Administrators
❖ Query Processor
❑ Data Definition Language (DDL)
❑ Data Manipulation Language (DML)
❖ Storage Manager
❑ Buffer Manager
❑ File Manager
❑ Authentication and integrity Manager
❑ Transaction Manager
❖ Disk Manager
❑ Data
❑ Indices
❑ Data dictionary
❑ Statistical Data
Database System
Architecture
Constraints in DBMS
Constraints enforce limits to the data or type of data that can be
inserted/updated/deleted from a table. The whole purpose of
constraints is to maintain the data integrity during an
update/delete/insert into a table. In this tutorial we will learn
several types of constraints that can be created in RDBMS.
• Types of constraints
• NOT NULL
• UNIQUE
• DEFAULT
• CHECK
Example Constraints in DBMS
Example:
CREATE TABLE STUDENT( ROLL INT NOT NULL,
NAME VARCHAR (35) NOT NULL UNIQUE,
FEE INT DEFAULT 10000,
AGE INT NOT NULL CHECK(AGE > 17) ,
PRIMARY KEY (ROLL));
Entity, Attributes and Relationship
A sample Entity-Relationship(ER)Diagram
Components of a ER Diagram
Entity
An entity is an object or component of data. An entity is represented as rectangle in an ER
diagram.
For example: In the following ER diagram we have two entities Student and College and
these two entities have many to one relationship as many students study in a single college.
We will read more about relationships later, for now focus on entities.
Weak Entity
An entity that cannot be uniquely identified by its own attributes and relies on the
relationship with other entity is called weak entity. The weak entity is represented by
a double rectangle. For example – a bank account cannot be uniquely identified
without knowing the bank to which the account belongs, so bank account is a weak
entity.
Attributes
An attribute describes the property of an entity. An attribute is represented as Oval
in an ER diagram. There are four types of attributes:
Key attribute
A key attribute can uniquely identify an entity from an entity set. For example,
student roll number can uniquely identify a student from a set of students. Key
attribute is represented by oval same as other attributes however the text of key
attribute is underlined.
Composite attribute
An attribute that is a combination of other attributes is known as composite attribute.
For example, In student entity, the student address is a composite attribute as an
address is composed of other attributes such as pin code, state, country.
Multivalued and Derived attributes:
Relationship
A relationship is represented by diamond shape in ER diagram, it
shows the relationship among entities. There are four types of
relationships:
1. One to One
2. One to Many
3. Many to One
4. Many to Many
Total Participation of an Entity set
Total participation of an entity set represents that each entity in entity set must
have at least one relationship in a relationship set. For example: In the below
diagram each college must have at-least one associated Student.
ER Diagrams
❖ Rectangle: Represents Entity sets.
❖ Ellipses: Attributes
❖ Diamonds: Relationship Set
❖ Lines: They link attributes to Entity Sets and
Entity sets to Relationship Set
❖ Double Ellipses: Multivalued Attributes
❖ Dashed Ellipses: Derived Attributes
❖ Double Rectangles: Weak Entity Sets
❖ Double Lines: Total participation of an entity
in a relationship set
E-R Diagram for Banking Enterprise
Extended ER(EER) Diagram
• Specialization
• Generalization
• Aggregation
Specialization
It is opposite to Generalization. It is a top-down approach in which one
higher level entity can be broken down into two lower level entity.
Generalization
It is a bottom-up approach in which two lower level entities combine
to form a higher level entity.
Aggregation
It is a process when relation between two entities is treated
as a single entity.
Database Terminologies
• Domain
• Entity
• Attributes
• Tuples
• Database schema
• Instance
Domain, Attributes, Tuples
Definition of schema: Design of a database is called the schema
Instance: The actual data stored in a database at a particular moment
in time.
Offline
• Goto terminal
• $sudo mysql
• Mysql> create database d1;
• Mysql> show databases;
• Mysql> use d1;