database objects

Upload: yayette-barimbad

Post on 04-Apr-2018

225 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/29/2019 Database Objects

    1/19

    DATABASE OBJECTS

  • 7/29/2019 Database Objects

    2/19

    Primary keys and Foreign key

    attributes

    Primary keys

    First column

    Most designers follow this convention

    Unique for each row

    Principle: A row is unique if any one of its columns is

    unique.

  • 7/29/2019 Database Objects

    3/19

  • 7/29/2019 Database Objects

    4/19

  • 7/29/2019 Database Objects

    5/19

    Primary keys and Foreign key

    attributes

    Foreign Key

    An attribute in one table that matches a primary key of

    another table

    Many database designers use the same field name forrelated primary key and foreign key columns to

    indicate the two columns tie together two tables.

    Join

    Connecting to or more related tables based on their

    matching primary/foreign keys

  • 7/29/2019 Database Objects

    6/19

    Schema of a Relation

    Formal term: Relation

    Less formal term: Table

    Data processing term: File

    Schemaoutline

    The schema of a relation for a table is the relations

    name and its attributes

    Customer(CustomerID, CompanyName, Contact, Address, City, State)

  • 7/29/2019 Database Objects

    7/19

    Data dictionary

    A collection of tables containing the definition,

    characteristics, structure and description of all data

    maintained by the RDBMS.

    Accessed by the database administrator or theobjects owner

    Other information stored:

    View definitionsObject owner names

    Database login names and password

  • 7/29/2019 Database Objects

    8/19

    Data dictionary

    Fields in the data dictionary are automatically

    changed whenever an objects structure is changed

    Rename operation

    Delete operation

  • 7/29/2019 Database Objects

    9/19

    Normalization

    Past: data is stored on flat files

    Normalization

    The process of determining the correct location for each

    attribute

    Unnormalized databases can lead to redundant,

    inconsistent, and anomalous information being stored in

    tables

    Normal form

    A particular subset of ways that attributes can be organized

    into tables

  • 7/29/2019 Database Objects

    10/19

    Normal forms

    First normal form

    Remove repeating data groups

    Second normal form

    Remove functional dependencies

    Third normal form

    Remove transitive dependencies

    Boyce/Codd normal form

    Fourth normal form

    Fifth normal form

    Domain/Key normal form

    Goal:

    Start with a collection of tables (relations)

    Apply normalization

    Arrive at an equivalent collection of tables in a higher normal form

  • 7/29/2019 Database Objects

    11/19

    Table Relationships

    One-to-one

    Indicate unnecessary tables

    Exceptions to the rule

    One-to-many Databases often contain tables with one to may

    relationships

    Many-to-many

    Difficult to represent Most database designers create a new table to represent

    many-to-many relationship into one-to-many relationship

    Intermediate relationship

  • 7/29/2019 Database Objects

    12/19

    General rules on relationships

    1. Primary keys cannot be null.

    2. Create a foreign key from the primary key on the oneside if the one-to-many relationship

    3. Many-to-many relationships are handled by creatingan additional table that consists entirely of theparents tables primary keys.

    4. One-to-one relationships indicate unnecessary tables

    in the database. Normally, you should merge the twotables.

    Exceptions: if there are too many columns in one table

  • 7/29/2019 Database Objects

    13/19

    Fundamental Relational Database

    Operations

    SELECT

    PROJECT

    JOIN

  • 7/29/2019 Database Objects

    14/19

    SELECT

  • 7/29/2019 Database Objects

    15/19

    PROJECTION

  • 7/29/2019 Database Objects

    16/19

    JOIN

  • 7/29/2019 Database Objects

    17/19

    Database Design

    A well-designed database models an enterprisesoperations

    What happen if the business has a bad databasedesign?

    Modeling

    An important aspect of database design

    Carefully choosing rows and columns

    Methods Draw information from existing business documents

    Entity-relationship modeling

  • 7/29/2019 Database Objects

    18/19

    Creating user views and relations

    Listing potential attributes from an existing

    document

    Identify functional dependencies

    Selecting which attributes belongs to which table

    Revision (apply normalization)

  • 7/29/2019 Database Objects

    19/19

    Developing Entity-Relationship Models

    Introduced by P.P. Chen in 1976 (Chen Notation)

    Entities

    Attributes

    Relationships

    Crows Foot Notation