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

Databases

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Databases

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 30

DATABASES

Hansika Mannapperuma
0768961322
B.Sc. ICT(@RUSL)
What is a database?
 Database is a collection of data stored in an organized manner, so that it can easily be
accessed, managed and updated.
 A database can be a computerized database or manual database
 In everyday life most of was get involved in database was
Banking- for customer information, accounts, and loans, and banking transactions.
Supermarket - to keep the stock, transactions, staff information
Airlines - for reservation and schedule information
universities - for student information, course registration and marks
telecommunication - for keeping records of calls made, generating monthly bills,
maintaining balances on prepaid calling cards.
 Types of databases
 multimedia database
 geographic information systems
 data warehousing and online transaction processing
 real time and active database Technology

Database systems
Flat File System
Data is stored in plain text files(Eg.txt files)
Usually contains one record per line.
Data is separated with commas, hyphens and blanks.
Advantages- cheap and simple
Disadvantages-Relatively slow for data reading and writing
Very less security

Hierarchical Model
Hierarchical representation of data.
Data is organized into a tree like structure.
The structure allows representation information using parent/child relationships.
Each parent can have many children. But a child can have only one parent.
Ex- Directory structure in the windows operating system.
Efficient
Network model
Similar to hierarchical model but it can be expressed many to many relational model.
Each record can have multiple parents.
Structure is complex.
This method can be used to handle more relationship types.
Relational Database Model
Relational databases are the most common database system.
They include databases like SQL server, Oracle Database, Sybase, Informix, MS Access
and MYSQL.
Database server

Databases

Tables

Rows(Tuple) and Columns


Collection of tables for data storage
 Basic data structure: tables
 Three basic rules:
The order of columns doesn’t matter
Identical rows are not allowed in the table
Each row has a single value for each of its column
 Keys, relational operations, normal forms
What are the components of a relational database?
Tables
Records/rows/tuples
Fields/attributes/columns
What is a Database Management System?
DBMS is a collection of programs for database definition, database creation, updating,
querying and administration of databases.
Components of DBMS
o Data Definition Language(DDL)
o Data Manipulating Language(DML)
Facilities:
o Defining: Specifying data types, structures and constraints for the data to be stored
o Constructing: Storing data on some storage media
o Manipulating: Retrieve specific data, update the data and generate reports
o Sharing: Allow access database for multiple users concurrently
o Protection: System protection among hardware/software malfunction and security
protection against unauthorized access
o Maintaining: Change the system as requirements change overtime

Table
It is a component of a database.
Actually, data are stored in tables in a database.
In a school database, data can be organized into several tables such as students, marks,
subjects, sports, etc..
St index Name Address Class
1051 Sagara Colombo 05 11B
1078 Thusitha Kelaniya 12C

Fields/Attributes are the data need to keep in an entity.


Fields are attributes in a table.
Each field/column has same type of data.

Row/Record/Tuple
One record of the student table represents the data about one student.

Entity
• Entity could be a person place event or object that is relevant to a given system.
• Provides data to a system, entities are data sources.
• Entities are different from each other but presented by a rectangle in the ERD
• example of school system may include student, teacher, course, subject, fees etc.

Attributes
• Attribute is a property of an entity, relationship or another attribute.
• An attribute can have their own sub attributes.
• Attribute are used to describe an object entity.
• Represented by an oval shape.
Types of attributes
Simple and Composite attributes
 An composite attribute can have their own specific attributes/sub attributes.
 An attribute can be broken down into several attributes.
 Non composite attributes are simple attributes.
Student(stno, address,fname,lname)

fname

stno
student name

lname

address
Single valued and Multivalued attributes
 Single valued attribute has a single value.
 Multivalued attribute can have more than one value.

phoneNo

Stored and Derived attributes


 An attribute based on another attribute is a derived attribute.
 Example the area of a circle is derived from the radius.
 Non derived attributes are stored attributes.
DOB

Age
Middle_name Street_nu
Street_name
First_name mber
Last_name
Apartment
Name street _number

Address city

Customer Customer
_ID state

Phone_no
Zip_code
Date_of_birth
age
Simple/composite Single/multivalued Stored/derived
Age
Phone_no
Name
Last_name
street
Relationships
 Relationship describes how entities interact with each other. It represent an association
among one or more entities.
 Presented by a diamond in the real relationships are labelled using verbs.
Three Types of relationships between entities
one to one relationship
 one instance of an entity(A) is associated with one other instance of another entity (B).
example one teacher is assigned for one class.
one to many relationship
one instance of an entity (A) is associated with zero, one of many instance of another entity (B)
.But one instance of entity (B) always associated with only one instance of entity(A).
Example-All employees are working in one building.
Many to many relationship
 One instance of entity (A) is associated with one, zero or many instances of another entity
(B).
 One instance of entity (B) is associated with one, zero or many instances of entity(A).
Example employees work in multiple projects
Different types of DBMS keys
A DBMS key is an attribute or a group of attributes which help to identify each record
uniquely.
SID Sname Sbranch Semail
1 John CS [email protected]
2 Adam CS [email protected]
3 Adam IT [email protected]
4 Elly EC [email protected]

Why do we need DBMS Keys?


 For identifying any row of data in a table uniquely.
 We can force identity of data and ensure integrity of data is maintained.
 To establish relationship between tables and identifying relationship between tables.
Types of DBMS key
Super key Candidate key
Primary key Alternate key
Foreign key Composite key and Compound key
Super key
Any key used to identify a record uniquely.
From previous example
SID
Semail Can have more combinations
SID+Semail
SID+Sname
Candidate key
It is nothing but a minimal subset of a super key.
In this example SID, Semail are candidate keys.
If any proper subset of a super key is a super key then that key cannot be a candidate key.
This SID+Semail is a super key its proper subsets are SID and Semail.
Therefore SID+Semail is not a candidate key.
Primary key
The candidate key chosen to uniquely identify each row of data in a table.
No two rows can have the same primary key value, primary key value cannot be NULL and every
row must have a primary key. The remaining candidate keys are called Alternate keys.
Foreign key
It is an attribute in a table which is used to define its relationship with another table.
Using foreign key helps in maintaining data integrity for tables in relationships.

Branch_code Branch_name HOD


CS Computer science John Mayer
ME Mechanical Engineering Adam Lee
IT Information Technology Kim Lee
EC Electronics communication Alan Gilbert

Composite key
Any key with more than one attribute is called composite key.
Example (SID, Semail)
Compound key
If a composite key has at least one attribute which is a foreign key, then it is called as compound
key.
R.No Name Marks Dept. Course
1 A 78 CS C1
2 B 60 EE C1
3 A 78 CS C2
4 B 60 EE C3
5 C 80 IT C3
6 D 80 EC C2
ER diagrams(graphical representation of entities and their relationships)
 ER diagram for describing how data sources are related to each other.
 ERD's is used in design stage of system development process.
 Illustrates the logical structure of a database.
 There are three basic elements in an ERD- entity relationship attributes
 Useful for non technical staff/people.
 ERD is a communication tool for requirement analysis.
Functional dependency
 Value of one attribute is determined by value of another attribute.
If we know the ISBN and then we know the book title and author.
Partial dependency
An non key attribute is determined by a part of the whole of a composite primary key.

Transitive dependency
The value of an attribute is dependent on or determined by another value of an attribute which
is not a part of the primary key.
ER Diagrams
An Entity Relationship diagram shows the relationship between entities. These should be designed
in a way to reduce data redundancy.
ER Diagram has mainly 3 components:
 Entity- An individual component in a subsystem(Ex-Teacher, student etc.)
 Attributes- Attribute is a property of an entity, relationship or another attribute.
 Relationship- Relationship describes how entities interact with each other. It represent an
association among one or more entities.
1)One to One
2)One to many
3)Many to many
School table Principal
Scl_ID Name Pri_ID Pri_ID Name
Scl_01 A College 6 5 Sirisena
Scl_02 B College 5 6 David
Scl_03 C College 8 7 Ranjith
Scl_04 D College 7 8 Susantha
StudentSubject table
Student table Subject table
SID Sub_ID Marks
SID Name Scl_ID Sub_ID Name
001 Sub_03 63
001 Sanath Scl_02 Sub_01 Maths
001 Sub_01 99
002 Anurada Scl_01 Sub_02 Science
002 Sub_03 78
003 Kamal Scl_01 Sub_03 ICT
005 Sub_04 44
004 Adeesha Scl_04 Sub_04 English
005 Adeesha Scl_03
Primary key
It is the used to identify a record uniquely.
Cannot be null.
The primary key cannot be repeated.
A table can have only a single primary key.
Ex- SID in student table
Candidate key
All the keys that can be used as a primary key are candidate keys.
Ex- In school system Admission number, NIC, passport number
Alternative key
After we choose a primary key the remaining keys are called alternative keys.
Composite key
The key made with the combination of two or more attributes.
Foreign key
The primary key of another table. Used to link tables.
Ex- Pri_ID is foreign key in school table.
Domain
CREATE TABLE Student(SID char(9), Name varchar(30), Address varchar(50));
The domain represent the type and quantity of the data that attribute can hold.

ER Diagram Symbols
Entity
An entity is an object that exists. It doesn't have to do anything. It just have to exist. In
database administration, an entity can be a single thing, person, place or an object.
Entity should be written in singular form.
Weak entity
A weak entity is an entity that cannot be uniquely identified by its attributes alone.
It is depending on another entity
Ex: in a school we have children(student table) and we also have a parent table. The parent
table will not exist if student doesn't exist.so the parent entity is a weak entity.
Attributes
Simple attribute: Simple attributes are atomic values that cannot be divided further
Composite attribute: composite attributes are made of more than one single attribute
Deviated attribute: they are the attributes that do not exist in the physical
database, but their values are derived from other attributes present in the
database.
Ex: age is derived from the date of birth
Stored attribute: they are such attributes which are already stored in the
database and from which the value of another attribute is derived
Ex: age is derived from the DOB
Normalization
What is normalization?
Normalization is a technique of organizing data into multiple related tables, to minimize data
redundancy.
What is data redundancy?
Repetition of similar data and this leads to:
1. Updation anomaly
2. Deletion anomaly
3. Insertion anomaly
How will normalization solve this?

Normalization is not about removing data redundancy it is about minimizing


1st Normal Form
Your database should at least use the 1st normal form always.

Rule1: All columns need to have atomic values.


Rule 2: A column should contain values of the same type.
Rule 3: Each column need to have a unique name.
Rule 4: The order which you save the data does not matter.
rollno name Subject
101 Akon OS
101 Akon CN
103 Ckon JAVA
102 Bkon C
102 Bkon C++
2nd Normal Form
For a table to convert into 2nd normal form
1)The table should be in 1st normal form
2)Should not have partial dependency
What is Dependency?
What is Partial Dependancy?

Student_id+subject_id

Subject_id Name Teacher_na


me Student_id Subject_id marks
1 Java Mr.J 1 1 82
2 C++ Mr.C++ 1 2 77
3 C# Mr.C# 2 1 85
4 Python Mr.P 2 2 82
2 4 95
3rd Normal Form
Prime attributes are attributes that contain in the primary key
For a table to be in 3rd normal form:
Student_id
1)It should be in 2nd normal form. Subject_id Non prime attributes
Marks
2)And should not have transitive dependency.(NPA depending on NPA)
Exam_name
Total_marks
Socre_id

You might also like