Presentation is loading. Please wait.

Presentation is loading. Please wait.

Database Management Systems (DBMS)

Similar presentations


Presentation on theme: "Database Management Systems (DBMS)"— Presentation transcript:

1 Database Management Systems (DBMS)
Certificate Course in Information Technology Anil Luvishewa Dept of Computer Science University of Ruhuna, Sri Lanka

2 Learning Outcomes Understand the need for database management as opposed to the traditional stand - alone applications approach. Learn the major factors involved in proper database design including the use of entity-relationship diagrams and normalization. Learn to use SQL for data definition and data manipulation. Dept of Computer Science University of Ruhuna, Sri Lanka

3 Topics Introduction to DBMS The Database Architecture
Database Design Process Conceptual Data modeling – (Entity-Relationship approach) The logical Database Model – (The Relational Model) Logical Database Design – (Normalization) Data Manipulation using SQL Dept of Computer Science University of Ruhuna, Sri Lanka

4 Introduction to Database Concepts
Why use a Database? Why Database Technology? ? Dept of Computer Science University of Ruhuna, Sri Lanka

5 ATM users Bank ATM users Branch Branch Mobile Banking System
Dept of Computer Science University of Ruhuna, Sri Lanka

6 Data and Information Data Information Raw facts Processed data
Less meaningful Not processed Eg: Date of birth Information Processed data Meaningful Organized Eg: Processed DOB: Age Dept of Computer Science University of Ruhuna, Sri Lanka

7 File Processing System
Individual applications maintain own private data files. Leads to data duplicate (redundancy). Inconsistency Management is very difficult Data is in different formats. Inflexible Dept of Computer Science University of Ruhuna, Sri Lanka

8 What is a database? A database is an organized collection of data that are related in a meaningful way and stored in a common pool which can be accessed by one or many persons for many purposes. A database is a group of related files Student database Eg: Course file Student name file Marks file File 1 File 2 File 3 Database Dept of Computer Science University of Ruhuna, Sri Lanka

9 What is a Database? Data collection may be . . .
Electronically Collected Manually Collected Dept of Computer Science University of Ruhuna, Sri Lanka

10 Key Features of a database
The data is input (stored) only once Organized accessible effectively and efficiently Dept of Computer Science University of Ruhuna, Sri Lanka

11 Database Building Blocks
File/Table A collection of related records. Record A record is a group of related fields. Field Field represents an attribute, or a characteristic or a piece of information Dept of Computer Science University of Ruhuna, Sri Lanka

12 Database Building Blocks..
Table a Field a Record Dept of Computer Science University of Ruhuna, Sri Lanka

13 Database Management System (DBMS)
The DBMS is a software package which allows a user to define, create, and maintain the database and provides controlled access to this database. The interface between users and data is provided by a database management system. Eg: Oracle, MS SQL-Server, MS Access MySQL, PostgreSQL Dept of Computer Science University of Ruhuna, Sri Lanka

14 Overview of a DBMS Admin DBMS Data-bases Users Results Modify/
Retrieval (Command) Results Admin Users Dept of Computer Science University of Ruhuna, Sri Lanka

15 Characteristics of Modern DBMS
Query processing Transaction management Concurrency control Database recovery Database security and authorization Distributed databases Dept of Computer Science University of Ruhuna, Sri Lanka

16 Advantages of using DBMS
Data duplication and storage space wasting can be avoided Inconsistency can be avoided Data can be shared Unauthorized access can be restricted Recovery from failures Dept of Computer Science University of Ruhuna, Sri Lanka

17 Disadvantages of using DBMS
cost of extra hardware cost of entering data cost of training people to use DBMS cost of maintaining DBMS complex Dept of Computer Science University of Ruhuna, Sri Lanka

18 Components of a Database System
The data in the database integrated and shared. Hardware Physically stores data, it can be secondary storage on which the database physically resides together with associated I/O devices. Software Between the physical database & the users is a layer of software which is known as the DBMS. Procedures Refer to the instructions & rules that governs the design & use of the database. Users Application Programmers. End-users Dept of Computer Science University of Ruhuna, Sri Lanka

19 Controlling & Maintaining a Database
Database Administrator (DBA) Database Dept of Computer Science University of Ruhuna, Sri Lanka

20 Duties of the Database Administrator
Installing and upgrades of database software Performance tuning Backup and recovery strategies Start the database & shutdown the database Monitoring the database Give and drop database access to the users Consultation with developers Dept of Computer Science University of Ruhuna, Sri Lanka

21 Database Architecture
Data-bases Dept of Computer Science University of Ruhuna, Sri Lanka

22 The Need of a Database Architecture
Users need to access same data but in different customized views. User views can be changed without affecting data or other user views. Users are not deal directly with physical data storage Database administrator should be able to change the database storage without affecting the user’s views. Dept of Computer Science University of Ruhuna, Sri Lanka

23 Database Architecture
An architecture for a database system is useful for explaining the structure of a specific database system The database architecture is a three level architecture which reflects the underlying database system Dept of Computer Science University of Ruhuna, Sri Lanka

24 Schemas and Instances Database schema Instance
The description of a database called database schema The logical structure of the database Schema is defined during the database designing and is not frequently changed Instance Data (the actual content) in the database at a particular moment in time is called database state. It is also called the instances or current set of occurrences Dept of Computer Science University of Ruhuna, Sri Lanka

25 Three Schema Architecture
End users External Level External View 1 View n Conceptual Schema Internal DB External / Conceptual mapping Conceptual Level Conceptual / Internal mapping The goal of the three-schema architecture, is to separate the user applications and the physical database. Internal Level Dept of Computer Science University of Ruhuna, Sri Lanka

26 Three Schema Architecture..
Internal (Physical) Schema Defines the physical view of data (as seen by a DBMS) Describe the physical storage of the database Describe how the data is stored in the database Concern with storage space allocation, record description, data compression and encryption techniques. Dept of Computer Science University of Ruhuna, Sri Lanka

27 Internal (Physical) Level
Struct Employee { Char Emp_no[5], Char Name[25], Date Date_joined, Boolean Pay_Tax, Int OT_Hours, Char Des_Code[3] } ; Dept of Computer Science University of Ruhuna, Sri Lanka

28 Three Schema Architecture..
Conceptual Schema Defines the logical view of data (as seen by programs) Describe the structure of the whole database for a community of users. Hides the details of physical storage structure. Describe entities, data types, relationships, user operations and constraints. Dept of Computer Science University of Ruhuna, Sri Lanka

29 Conceptual Level Employee Table Base Table
Dept of Computer Science University of Ruhuna, Sri Lanka

30 Three Schema Architecture..
External Schema Defines the external view of data (as seen by a user) The users view of the database Describe the part of the database that a particular user group is interested. Hides the other details of the database. Dept of Computer Science University of Ruhuna, Sri Lanka

31 External Level Base Table (Conceptual View)
The data what user wants (Only selected parts of selected records from base table) Dept of Computer Science University of Ruhuna, Sri Lanka View Table (External View)

32 Mapping External/Conceptual mapping Conceptual/Internal mapping
Define the correspondence between a particular external view and conceptual view. This specified how a particular external schema is derived from conceptual schema Conceptual/Internal mapping Define the correspondence between the conceptual view and stored database. This specifies how the conceptual schema is represented at the internal level. If the structure of the stored database is changed, the conceptual internal mapping must also be changed accordingly. Dept of Computer Science University of Ruhuna, Sri Lanka

33 Staff_No FName LName DOB Batch_no
Mapping.. External view 1 External view 2 Sno FName LName Staff_No LName Bno External Level Conceptual Level Staff_No FName LName DOB Batch_no Struct STAFF { int Staff_No; int Branch_No; char FName[15]; char LName[15]; date date_of_birth}; Internal (Physical) Level Dept of Computer Science University of Ruhuna, Sri Lanka

34 Data Independence The major objective for the three-level architecture is to provide data independence Logical Data Independence Capacity to change the conceptual schema without having to change external schemas or application program. Physical Data Independence The ability to modify the physical schema without changing the conceptual (or external ) schema Dept of Computer Science University of Ruhuna, Sri Lanka

35 Database Design Dept of Computer Science University of Ruhuna, Sri Lanka

36 Database Design The database design process can be broken down into four phases. Requirements collection and analysis phase Conceptual Design Logical Design Physical Design Dept of Computer Science University of Ruhuna, Sri Lanka

37 Requirements collection and analysis phase
Prospective database users are interviewed to understand and document their data requirements Dept of Computer Science University of Ruhuna, Sri Lanka

38 Conceptual Design This is a high level description of the structure of a database Eg: E-R Diagram Concise description of the data requirements of the users and includes detailed description of the data, relationship and constraints. Dept of Computer Science University of Ruhuna, Sri Lanka

39 Logical Design This is the process of mapping the database structure developed in the previous phase to a particular database model. Eg: Map E-R model to relational Dept of Computer Science University of Ruhuna, Sri Lanka

40 Physical Design This is the process of defining structure that enables the database to be queried in an efficient manner Eg: index and hash file design Dept of Computer Science University of Ruhuna, Sri Lanka

41 Phases of Database Design
Problem Requirements collection & analysis Database Requirements Conceptual Design Conceptual Data Model Logical Design Logical Data Model Physical Design Physical Data Model Dept of Computer Science University of Ruhuna, Sri Lanka Database Implementation

42 Entity – Relationship Modeling
ER model is high level conceptual data model Dept of Computer Science University of Ruhuna, Sri Lanka

43 The Concepts of the ER Model
Entity An entity is a thing in the real world with an independent existence . As entity may be an object with a physical existence . e.g. : a person , a student , a house, etc. An entity is any object that is relevant to the organization. Tangible object Intangible objects Events Dept of Computer Science University of Ruhuna, Sri Lanka

44 Conceptual Design Entities Department Employee Project Dependent
Dept of Computer Science University of Ruhuna, Sri Lanka

45 The Concepts of the ER Model
Attribute Each entity has particular properties or features (characteristics ) called attributes . e.g. student entity(student no, name, address, dob) Dept of Computer Science University of Ruhuna, Sri Lanka

46 Simple (atomic) attribute
Type of attributes Simple (atomic) attribute Attributes that are not divisible are called simple or atomic attribute. Eg: Emp_No Composite attribute Can be divided in a smaller part which represent more basic attributes with independent meaning of their own. Eg: Name (First Name, Mid Name, Last Name) Dept of Computer Science University of Ruhuna, Sri Lanka

47 Multi-valued attribute
Type of attributes Multi-valued attribute In some case an attribute can have a set of values for the same entity such attributes are called multi-valued attributes. Eg. Degree of a person , Qualification Derived attribute An attribute whose value can be calculated from related attribute values Eg: Age (Using Date of Birth) . Years Employed (Using Employed Date) . Dept of Computer Science University of Ruhuna, Sri Lanka

48 Relationship Relationship A meaningful association between entities.
Eg: Student follows courses Employee works for department Dept of Computer Science University of Ruhuna, Sri Lanka

49 Relationship Degree of a Relationship Unary Relationship
The degree of the relationship type is no. of participating entity types . Unary Relationship Relationship between the instances of a single entity type. E.g.: person is married to a person (1:1) Employee manages Employees (1:M) Binary Relationship Relationship between the instances of two entity types. Degree = 2; Manages Employee Student Courses follows Dept of Computer Science University of Ruhuna, Sri Lanka

50 Relationship Degree of a Relationship Ternary Relationship
A simultaneous relationship among the instances of three entity type. Degree = 3 ,Ternary Relationship Supplier Project supplies Part Dept of Computer Science University of Ruhuna, Sri Lanka

51 Constraints on Relationship Types
One To One ( 1: 1) .m1 .m2 .m3 . .mn .e1 .e2 .e3 .en . d1 . d2 . d3 .dn Employee entity Manages relationship Department entity EMPLOYEE DEPATMENT manages 1 1 An employee can manage one department and a department is managed by only one employee. Dept of Computer Science University of Ruhuna, Sri Lanka

52 Constraints on Relationship Types..
One To Many (1:N) Eg: An employee works for one department and a department has many employees. .w1 .w2 .w3 . .wn .e1 .e2 .e3 . .en . d1 . d2 . d3 .dn Employee entity Works for relationship Department entity M 1 EMPLOYEE DEPATMENT Works for Dept of Computer Science University of Ruhuna, Sri Lanka

53 Constraints on Relationship Types..
Many – To – Many (M:N) Eg: Consider two entities employee and the project. An employee can work on several projects and a project has many employees. .w1 .w2 .w3 . .wn .e1 .e2 .e3 .en . P1 . P2 . P3 .Pn Employee entity Works for relationship Project entity M N EMPLOYEE PROJECT Works Dept of Computer Science University of Ruhuna, Sri Lanka

54 Participation Constraint (Membership class)
Participation constraint specifies the existence of an entity depends upon it being related to another entity through the relationship. There are two types of participation constraints. Total ( obligatory) Each and every entity in the entity set MUST BE related to the other entity set via the relationship. Partial (non–obligator, optional) Some or parts of the entity set are related to the other entity set but not necessarily all. Dept of Computer Science University of Ruhuna, Sri Lanka

55 Participation Constraint Examples
Total participation Every employee must work for a department Works for EMPLOYEE DEPATMENT .w1 .w2 .w3 . .e1 .e2 .e3 . d1 . d2 . d3 Dept of Computer Science University of Ruhuna, Sri Lanka

56 Participation Constraint Examples
Partial participation Some employees manage a department but not all. EMPLOYEE DEPATMENT manages .w1 .w2 . .e1 .e2 .e3 . d1 . d2 . d3 Dept of Computer Science University of Ruhuna, Sri Lanka

57 Attributes of relationship types
Relationship types can also have attributes similar to those of entity type. Eg: Employee works on project If we need to record the number of hours per week that an employee works on project we can include an attribute hours for the works on relationship type. EMPLOYEE PROJECT Works on hours Dept of Computer Science University of Ruhuna, Sri Lanka

58 Weak Entity Type Weak entity Identifying Owner
An entity type that is existence-dependent on some other entity type. Identifying Owner The entity type on which the weak entity type depends E.g. Employee is the Owner of Dependant. Identifying Relationship The relationship between a weak entity type and it’s owner Some entity types may not have any key attributes of their own. These are called weak entity types. Dept of Computer Science University of Ruhuna, Sri Lanka

59 Weak Entity Type Can not exist without it’s identifying owner
Weak entity always has total participation with it’s identifying owner. A B Total Weak entity Identifying relationship Identifying owner Dept of Computer Science University of Ruhuna, Sri Lanka

60 Strong Entity Type Strong entity Eg: employee works on project
An entity type that is not existence-dependent on some other entity type is called strong entity. Eg: employee works on project EMPLOYEE PROJECT Works on Some entity types may not have any key attributes of their own. These are called weak entity types. Dept of Computer Science University of Ruhuna, Sri Lanka

61 Conceptual Design – Notations
Entity Type Weak Entity Relationship Identifying Relationship Dept of Computer Science University of Ruhuna, Sri Lanka

62 Conceptual Design – Notations
Attribute Key Attribute Multi valued Attribute Derived Attribute Dept of Computer Science University of Ruhuna, Sri Lanka

63 Conceptual Design – Notations
Composite Attribute Total Participation of E2 in R Cardinality ratio 1:N for E 1: E 2 in R E2 E1 R 1 N R E2 E 1 Dept of Computer Science University of Ruhuna, Sri Lanka

64 Example - A company Database
A company database keeps track of a company’s employees, departments and projects. The requirements are as follows: The company is organized into departments. Each department has a unique name, a unique number and a particular employee who manages the department. A department may have several locations. Dept of Computer Science University of Ruhuna, Sri Lanka

65 Example - A company Database
A department controls a number of projects, each of which has a unique name, a unique number and a single location Dept of Computer Science University of Ruhuna, Sri Lanka

66 Example - A company Database..
We store each employee’s name, i.d. number , address, salary , sex, and birth date . An employee is assigned to one department but may work on several project, which are not necessarily controlled by the same department. Employee may or may not supervise another employee and we need to keep track of the direct supervisor of each employee. Dept of Computer Science University of Ruhuna, Sri Lanka

67 Example - A company Database..
We want to keep track of the dependants of each employee for insurance purposes. We keep each dependant’s name , sex, birth date and relationship to the employee. Dept of Computer Science University of Ruhuna, Sri Lanka

68 Solution - A company Database..
Step One Identify entity types, attribute on each entity. Step Two Identify relationship types Step Three ER Diagram for the company database Dept of Computer Science University of Ruhuna, Sri Lanka

69 Solution - A company Database..
Step One What are the entity type in your company database? What are the attributes belongs to each entity? Sketch Dept of Computer Science University of Ruhuna, Sri Lanka

70 Solution - A company Database..
Step Two Identify the relationship types in your company database? Sketch Write assumptions Dept of Computer Science University of Ruhuna, Sri Lanka

71 Solution - A company Database..
Step Three Draw the ER Diagram. Dept of Computer Science University of Ruhuna, Sri Lanka

72 Solution - A company Database Detailed Conceptual Design
Step One Identify entity types, attribute on each entity. Department Number Name Location DEPARTMENT Note : Name or number can be the key Dept of Computer Science University of Ruhuna, Sri Lanka

73 Step One - Identify entity types & attribute
Project Project Number Location Name 3. Employee Name surname FN Employee Address i.d# Salary Sex Dob Number street city Dept of Computer Science University of Ruhuna, Sri Lanka

74 Step One - Identify entity types & attribute..
Dependent Dependent Name Dob Sex Dept of Computer Science University of Ruhuna, Sri Lanka

75 Step Two - Identify relationship types
“A particular employee who manages the department” Assumptions: An employee can manage one department. A department is manage by only one employee. A department must have a manager at all times. (Total) 1 1 Employee Department Manages 1:1 Dept of Computer Science University of Ruhuna, Sri Lanka

76 Step Two - Identify relationship types..
“A department controls a number of projects.” Assumptions: A project is controlled by one department. A department controls number of projects. A project must be controlled by a department. (Total) M 1 Department Projects Controls 1:M Dept of Computer Science University of Ruhuna, Sri Lanka

77 Step Two - Identify relationship types..
“An employee is assigned to one department but many worked on several project.” Assumptions: A department has many employee. An employee must belong to a department and department must have employees. (Total) A project may have employees An employee can work on a project and a project should have employee (Total) 1 M Assigned to Employee Department N M Works on Project M:1 Dept of Computer Science University of Ruhuna, Sri Lanka

78 Step Two - Identify relationship types..
“An employee may have dependents.” Has dependant 1 M Employee Dependent Dept of Computer Science University of Ruhuna, Sri Lanka

79 Step Two - Identify relationship types..
“An employee may or may not supervise another employee.” Assumptions: Supervision relationship is known as recursive relationship. Employee play two roles: Supervisor , Supervisee Employee 1 M supervisor supervisee supervision Dept of Computer Science University of Ruhuna, Sri Lanka

80 E-R Model (schema) Diagram for the company database
Assigned to EMPLOYEE N 1 DEPARTMENT 1 1 1 1 Manages N Controls Supervision 1 N Has dependant M Attributes of Relationship types Star – date - in manages relationship Hours – in work – on relationship Works on N Project N DEPARTMENT Dept of Computer Science University of Ruhuna, Sri Lanka

81 THE RELATIONAL DATA MODEL
Dept of Computer Science University of Ruhuna, Sri Lanka

82 Introduction This model was introduced by Ted Codd of IBM in the early 1970’s. Provide concepts which can be used to build a logical design. It is based on the concept of mathematical relations. DBMS which supports this model is said to be a Relational Database Management System (RDBMS) The RDB is a collection of relations. Dept of Computer Science University of Ruhuna, Sri Lanka

83 Terminology Relation Attribute Tuple
A relation is a table with columns and rows. Attribute An attribute is a named column of a relation. Tuple A tuple is a row of a relation. Dept of Computer Science University of Ruhuna, Sri Lanka

84 Terminology.. Degree Relation schema
The number of attributes of a relation. Relation schema A relation name followed by set of attributes A relation schema is denoted by R (A1, A2, A3,….,An) R – Relation name A1, A2, A3,….,An - – list of attributes Dept of Computer Science University of Ruhuna, Sri Lanka

85 Terminology.. Cardinality
The cardinality of the relation is the number of tuples present in the body, which varies with time. Dept of Computer Science University of Ruhuna, Sri Lanka

86 Example - Terminology St – No Name Address Dob S 1 Kamal Matara
Attribute STUDENT St – No Name Address Dob S 1 Kamal Matara S 2 Himali Kaluthara S 3 Renuka Galle Tuple R (Student) Degree of student – 4 Cardinality of student -3 Dept of Computer Science University of Ruhuna, Sri Lanka

87 Properties of Relation
The relation has a name that is distinct from all other relations Tuple of relation do not have any particular order. Each attribute has a distinct name Attributes are unordered. There are no duplicate tuple. All attribute values are atomic. i.e. Not divisible into components. Dept of Computer Science University of Ruhuna, Sri Lanka

88 Key Types of a Relation Candidate key
A candidate key is an attribute or set of attributes whose values uniquely identify a tuple of a relation. There may be more than one candidate keys for a relation. E.g. Consider the following relation schema Department (d#, dname, location ) Assumption : d# and dname are unique Candidate keys:{d#} and {dname} Dept of Computer Science University of Ruhuna, Sri Lanka

89 Key Types of a Relation.. Primary key
One of the relation candidate key is selected as primary key. The other candidate keys are called alternate keys. E.g.Consider the following relation schema Department (d#, dname, location ) Assumption : d# and dname are unique Primary key: d# Alternate key: dname Dept of Computer Science University of Ruhuna, Sri Lanka

90 Key Types of a Relation.. Foreign key
A foreign key is an attribute in one relation that matches the primary key attribute of another relation. E.g.Consider the following relation schemas Department (d#, dname, location ) Project (P#, desc, d#, Start_date) Foreign key: d# is foreign key in Project schema Dept of Computer Science University of Ruhuna, Sri Lanka

91 Eg: Foreign key... Department PK Project PK FK Dept_No Dept_Name Phone
Construction D02 Finance D03 Personal PK Prj_No Prj_Name Location Dept P01 ABC Auditing Matara D02 P02 TRC Budgeting Colombo P03 Ground Construction Galle D01 Project PK FK Dept of Computer Science University of Ruhuna, Sri Lanka


Download ppt "Database Management Systems (DBMS)"

Similar presentations


Ads by Google