Concepts and Terminology Introduction to Database.

download Concepts and Terminology Introduction to Database.

of 96

  • date post

    29-Dec-2015
  • Category

    Documents

  • view

    220
  • download

    4

Embed Size (px)

Transcript of Concepts and Terminology Introduction to Database.

  • Concepts and TerminologyIntroduction to Database

    Copyright 2005 Radian Publishing Co.

  • Concepts and TerminologyA Database is an organised collection of logically related data. A Database may be of any size and complexity.

    Copyright 2005 Radian Publishing Co.

  • Concept of DataData are raw facts that could be recorded and stored on computer media.

    Information is data that have been converted into a context meaningful to some end-users.

    Copyright 2005 Radian Publishing Co.

  • Data ProcessingData processing involves calculating, comparing, sorting, classifying and, converting data into information.

    Copyright 2005 Radian Publishing Co.

  • Concept of Logical Data: Entity and Attribute (1/3)An entity is a person, place, device, event, or concept.

    An entity class (or entity type) is a collection of entities with common properties.

    An entity instance is a single occurrence of an entity class.

    An attribute is a property of an entity class.

    Copyright 2005 Radian Publishing Co.

  • 2.1 D. Concept of Logical Data: Entity and Attribute (2/3)Fig.2.4 Examples of entity classes and entity instances

    Copyright 2005 Radian Publishing Co.

  • 2.1 D. Concept of Logical Data: Entity and Attribute (3/3)Fig.2.5 An entity class with two entity instances

    Copyright 2005 Radian Publishing Co.

  • 2.2 Structure of Data in a DatabaseIn a database, data are logically organised into characters, fields, records, tables and databases.

    Copyright 2005 Radian Publishing Co.

  • 2.2 A. Hierarchical Structure of Data (1/3)The most basic logical data element is character, which consists of a single letter, digit or special symbol.

    A field represents an attribute of a certain entity. It consists of a group of characters.

    A record is a set of related fields.

    Fig.2.6 A student record

    Copyright 2005 Radian Publishing Co.

  • 2.2 A. Hierarchical Structure of Data (2/3)A table (or file) is a group of related records, representing an entity class. It is made up of rows and columns.

    Fig.2.7 A student table. (The underlined item is the primary key.)

    Copyright 2005 Radian Publishing Co.

  • 2.2 A. Hierarchical Structure of Data (3/3)A database is an organised collection of logically related tables.

    In a relational database, tables are also called relations. A relationship is the link between two relations.

    Fig.2.8 Some entities and relationshipsin a school database

    Copyright 2005 Radian Publishing Co.

  • 2.2 B. Keys (1/4)Keys are used to organize, access and maintain database. There are three types of keys:

    primary keysforeign keyscandidate keys

    Copyright 2005 Radian Publishing Co.

  • 2.2 B. Keys (2/4)A primary key is a field or combination of fields that uniquely and minimally identify a particular record in a table. The key value must be unique and non-empty.

    Fig.2.9 Examples of tables with a primary key

    Copyright 2005 Radian Publishing Co.

  • 2.2 B. Keys (3/4)A foreign key is a field in one table that matches a primary key value in another table.

    Tables are linked by relationships which are set up by designing tables with foreign keys and primary keys. Fig.2.10 Examples of foreign keys

    Copyright 2005 Radian Publishing Co.

  • 2.2 B. Keys (4/4)A Candidate key is any field that could serve as a primary key.Fig.2.11 Examples of candidate keysNon-key Field

    Any field which is not a primary key or a candidate key is called a non-key field.Therefore, Name, Address, Phone_Num are non-key fields.

    Copyright 2005 Radian Publishing Co.

  • 2.3 Common Data Types (1/2)The most commonly used data types used in databases are:

    Character / stringnumber date/time

    Copyright 2005 Radian Publishing Co.

  • 2.3 B. Numbers (2/3)Table 2.2 Types of number used in a standard database

    Copyright 2005 Radian Publishing Co.

  • 2.3 C. Data-and-TimeDate-and-time are stored internally as real numbers and displayed according to specified formats.

    Copyright 2005 Radian Publishing Co.

  • Relational DatabasePart A. Introduction to Database

    Copyright 2005 Radian Publishing Co.

  • 4.1 A. File-Processing in SchoolFile-processing approach often focuses on the data processing needs of individual departments, instead of evaluating the overall needs.

    Fig.4.1 Two file-processing systems used in the same school

    Copyright 2005 Radian Publishing Co.

  • 4.1 B. Disadvantages of File-Processing SystemDisadvantages of File-Processing System:

    1. Program-data Dependency

    2. Duplication of Data (Data Redundancy)

    3. Limited Data Sharing

    4. Files are often incompatible with one another

    5. Excessive Programming Effort

    Copyright 2005 Radian Publishing Co.

  • 4.2 The Database ApproachDatabase technology, to be more accurate, relational database technology, addresses to the problems associated with traditional file-processing approach.Fig.4.2 A single database is used by users in the same school

    Copyright 2005 Radian Publishing Co.

  • 4.2 A. Data Model (1/2)The first step in converting to a database approach Is to develop a list of high-level entities that support the operation of the school.Fig.4.3 Entities in the school

    Copyright 2005 Radian Publishing Co.

  • 4.2 A. Data Model (2/2)The second step is to develop a data model. A data model is a detailed specification of the overall structure of data, showing how the entities are related. Entity-relationship (E-R) diagram is a common tool.Fig.4.3 E-R-diagram

    Copyright 2005 Radian Publishing Co.

  • 4.2 B. Relational Database (1/6)The characteristics of a relational database are as follows:

    Data structureData are organised in the form of rows and columns, i.e. tables, each representing an entity class.

    2. Data manipulationSQL commands are used to manipulate data stored in the tables.

    3. Data integrityConstraints are included to ensure that there is no loss of data integrity.

    Copyright 2005 Radian Publishing Co.

  • 4.2 B. Relational Database (2/6)The characteristics of tables in a relational database are as follows:

    1. Every table must have a primary key, which is unique and non-empty

    2. Attribute values are taken from a well-defined domain

    3. A foreign key must match with a primary key in another table

    4. Each table of a database must have a unique name

    5. Each field of a table must have a unique name

    Copyright 2005 Radian Publishing Co.

  • 4.2 B. Relational Database (3/6)The characteristics of tables in a relational database (continue):

    6. Multi-valued attributes are not allowed

    7. Each row is unique

    8. The sequence of fields is insignificant.

    9. The sequence of records is insignificant.

    Copyright 2005 Radian Publishing Co.

  • 4.2 B. Relational Database (4/6)Fig.4.4 Tables designed for the school

    Copyright 2005 Radian Publishing Co.

  • 4.2 B. Relational Database (5/6)Fig.4.5 Sample of the database (a) Relationships between tables

    Copyright 2005 Radian Publishing Co.

  • 4.2 B. Relational Database (6/6)Fig.4.5 Sample of the database (b) Tables in the database

    Copyright 2005 Radian Publishing Co.

  • 4.2 C. Integrity Constraints (2/5)A domain is a set of values that may be assigned to an attribute.

    A domain constraint defines the followings:

    data typesize (or length)

    Copyright 2005 Radian Publishing Co.

  • 4.2 C. Integrity Constraints (3/5)Entity integrity constraints require that every table has a primary key, which is unique and non-empty.

    Copyright 2005 Radian Publishing Co.

  • 4.2 C. Integrity Constraints (4/5)Referential integrity constraints require that if there is a foreign key in one table either each foreign key value match a primary key value in another table or the foreign key value is null.

    Fig.4.8 Specifying foreign keys in a SQL statement

    Copyright 2005 Radian Publishing Co.

  • 4.2 D. Advantages of Database Approach (1/2)Advantages of Database Approach:

    1. Program-Data independency

    2. Reduced Data Duplication

    3. Improved Data Sharing

    4. Improved Data Accessibility

    Copyright 2005 Radian Publishing Co.

  • 4.2 D. Advantages of Database Approach (2/2)Example for Advantage 4. Improved Data AccessibilityFig.4.9 Retrieving student records of class 6AFig.4.10 Retrieving student records without club enrollment

    Copyright 2005 Radian Publishing Co.

  • E-R DiagramsPart B. Database Design

    Copyright 2005 Radian Publishing Co.

  • Chapter 6 E-R DiagramsAn entity-relationship (E-R) diagram is a graphical representation of data for an organisation at conceptual level.

    Fig.6.1 Symbols used in E-R diagrams

    Copyright 2005 Radian Publishing Co.

  • 6.1 RelationshipsThe requirements for an entity are:

    1. one or more attributes 2. many possible distinct instances.

    A relationship is an association between two entities based on a key attribute. Do not confuse relationship with relation: A relation is a table. A relationship links up two tables.

    Copyright 2005 Radian Publishing Co.

  • 6.1 A. Identifying Entities and Relationships (2/2)Fig.6.2 Some daily-life examples of entities and relationship

    Copyright 2005 Radian Publishing Co.

  • 6.1 B. Relationship Cardinality (2/7)Fig.6.3 Symbols for maximum cardinality

    Copyright 2005 Radian Publishing Co.

  • 6.1 B. Relationship Cardinality (3/7)Fig.6.4 Examples