You are on page 1of 19

DATABASE OBJECTS

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.

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 for related 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

Schema of a Relation

Formal term: Relation Less formal term: Table Data processing term: File Schema outline
The

schema of a relation for a table is the relations name and its attributes

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

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 the objects owner Other information stored:
View

definitions Object owner names Database login names and password

Data dictionary

Fields in the data dictionary are automatically changed whenever an objects structure is changed
Rename

operation Delete operation

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

Normal forms

First normal form

Remove repeating data groups Remove functional dependencies Remove transitive dependencies

Second normal form

Third normal form

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

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

General rules on relationships


1.

2.

3.

4.

Primary keys cannot be null. Create a foreign key from the primary key on the one side if the one-to-many relationship Many-to-many relationships are handled by creating an additional table that consists entirely of the parents tables primary keys. One-to-one relationships indicate unnecessary tables in the database. Normally, you should merge the two tables.
Exceptions: if there are too many columns in one table

Fundamental Relational Database Operations

SELECT PROJECT JOIN

SELECT

PROJECTION

JOIN

Database Design

A well-designed database models an enterprises operations


What

happen if the business has a bad database design?

Modeling
An

important aspect of database design Carefully choosing rows and columns

Methods
Draw

information from existing business documents Entity-relationship modeling

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)

Developing Entity-Relationship Models

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


Entities
Attributes Relationships

Crows Foot Notation

You might also like