You are on page 1of 66

Unit-I Syllabus

UNIT – I INTRODUCTION TO DBMS

Introduction: Basic concepts, Advantages of DBMS over file


processing systems, Data abstraction, Database languages, Data
models, Data independence, Components of a DBMS, Overall
structure of DBMS, Multi-user DBMS architecture, System
catalogs, Data Modeling: Basic concepts, Entity, attributes,
relationships, constraints, keys

Case Study: MySQL Database


Introduction to DBMS
(Database Management Systems)

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

❑ DBMS contains information about a particular


enterprise
❑ DBMS provides an environment that is both convenient
and efficient to use.
A Sample Relational Database
Applications of Databases
Database Applications:
❖ Banking: all transactions
❖ Airlines: reservations, schedules
❖ Universities: registration, grades
❖ Sales: customers, products, purchases
❖ Manufacturing: production, inventory, orders, supply
chain
❖ Human resources: employee records, salaries, tax
deductions
Databases touch all aspects of our lives
Example of Databases
Example of Databases
❖ Oracle Database
❖ Microsoft SQL Server
❖ File Maker
❖ NoSQL: MongoDB, CouchDB, Cassendra
❖ Postgresql
❖ MS Fox Pro
❖ Red Brick
❖ Ingres
❖ Adabas
❖ Uni Data
❖ Informox Dynamic Server 2000
Example of Databases
❖ Point Base Network Server
❖ Versant
❖ Supra PDM
❖ IDMS
❖ DataCom
❖ Adaptive Server Enterprise
❖ Advantage Database Server
❖ Interbase
❖ Teradata Database
❖ Intersystems Cache
❖ Quadbase SQL Server
Advantages of Database Management
over File Handling
1. Data Redundancy is reduced
2. Data Sharing is achieved
3. Inconsistency can be avoided
4.Data Integrity is maintained
Data integrity means unification of so many files into a single file.
5. Data security is enforced
Data security means protecting data from unauthorized access.
6.Backup and Recovery can be easily achieved
7.Concurrency Control effectively done
8.Data Migration is easy
9. Data standards can be enforced
10. Centralized administration is easy with Database
Data Models
❑ A database model shows the logical structure of a database including
the relationships and constraints that determine how data can be
stored and accessed.
❑ Individual database models are designed based on the rules and
concepts of whichever broader data model the designers adopt.
❑ Most data models can be represented by an accompanying database
diagram.

❖ Entity Relationship Model


❖ Relational Model
❖ Hierarchical Model
❖ Network Model
❖ Object Oriented Model
❖ Semi structural Data Model
Entity Relationship Model
Relational Model
In hierarchical model, data is organized into a tree like structure with each record
is having one parent record and many children. The main drawback of this model is
that, it can have only one to many relationships between nodes.
Network Model

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

name email phone birthday

first last year month day


Expanded Example
<?xml version = “1.0” ?>
<address>
<name>
<first>Alice</first>
<last>Lee</last>
</name>
<email>alee@aol.com</email>
<phone>123-45-6789</phone>
<birthday>
<year>1983</year>
<month>07</month>
<day>15</day>
</birthday>
</address>
Database Keys
i)Primary Key
ii) Super Key
iii) Candidate Key
iv)Foreign Key
v)Composite Key
Primary Key
Definition:A primary key is that uniquely identifies tuple (rows) in that table.
Stud_Id is primary Key.

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 Emp_Name

123456789 226 Steve


999999321 227 Ajeet
888997212 228 Chaitanya
777778888 229 Robert
Candidate Key
Candidate Keys:The candidate key is a minimal super key with no redundant
attributes. The following two set of super keys are chosen from the above sets as
there are no redundant attributes in these sets.

{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.

Emp_SSN Emp_Number Emp_Name


123456789 226 Steve
999999321 227 Ajeet
888997212 228 Chaitanya
777778888 229 Robert
Foreign key
Definition: Foreign keys are the columns of a table that points to the primary key of
another table. They act as a cross-reference between tables.

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_enrollment table 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

cust_Id order_Id product_code product_count


C01 0001 P007 23
C02 0123 P007 19
C02 0123 P230 82
C01 0001 P890 42

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:

Key in above table: {cust_id, product_code}


Composite key
• None of these columns alone can play a role of key in this table.

• 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_code cannot be a primary key as more than one customers


can place order for the same product.

• 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.

Database schema: Product(Name, Price, Category, Manufacturer)


Instance:
Name Price Category Manufacturer

gizmo $19.99 gadgets GizmoWorks

Power gizmo $29.99 gadgets GizmoWorks

SingleTouch $149.99 photography Canon

MultiTouch $203.99 household Hitachi


52
Example of a Database Schema
Database Schema
Multi-user DBMS architecture
❑ A multiuser environment is one in which other users can
connect/access/make changes to the same database.

❑ As a result, several users might be working with the same


database objects at the same time

❑ Example:: University Online examination


Two-Tier Database Server Architecture
Three-Tier Database Server Architecture
1-Tier Architecture
2-Tier Architecture
3-Tier Architecture
System catalogs/ Data Dictionary

❑ The system catalog consists of group of tables and views that


describe the structure of the database.

❑ Sometimes called the data dictionary, these table objects contain


everything that the database knows about itself.

❑ Each system catalog table contains information about specific


elements in the database.
Example
Database Terminologies
MySQL queries
Online
• https://www.programiz.com/sql/online-compiler/
• Live SQL Oracle

Offline
• Goto terminal
• $sudo mysql
• Mysql> create database d1;
• Mysql> show databases;
• Mysql> use d1;

• Mysql> CREATE TABLE STUDENT (ID INT,NAME CHAR(20));


• Mysql> INSERT INTO STUDENT (ID,NAME)VALUES (1, 'Ramesh');
• Mysql> INSERT INTO STUDENT (ID,NAME)VALUES (2, 'Chaitali');
• Mysql> SELECT * FROM STUDENT;

You might also like