Sie sind auf Seite 1von 9

1.

INTRODUCTION TO DATABASES
CRUD: Create, read, update, delete
SQL gives us the ability to do this with our relational database. It is an international
standard language for creating, processing, and querying databases and their tables
Vast majority of data driven applications and websites use SQL
When we store data in a list (redundancy + common themes issues), we introduce
the possibility of data anomalies:

Deletion problems (When you try to delete a row of data, not only do you
lose the students info but you lose the advisor info)
Update anomaly (when you want to update something in the database, but
need to simultaneously update multiple fields as a row eg changing the
advisor for a student and simultaneously needing to change the advisor email
address, dpt, etc)
Insertion (want to create a new bio dpt, create a new row but no info would
be there for student etc)

Relational databases store data in a table. Data for each of the business concepts is
stored in its own table and you then create relationships btw those tables.
May be necessary for reporting purposes, to reassemble all the data back together to
form a list type thing again. Called a join operation.
We link all the records in a database by matched pair of values. Allows to associate a
row in one table with one or more rows in another table. Eg using a customer Id to
uniquely identify each customer and then placing it in the project table to link
related rows together
Relational databases have the following advantages
Minimize data redundancy
Model the natural relationships that exist
Providing a solid basis to generate reports, build user interface forms
Table = 2 dimensional grid of data with columns (represent dif attributes of an
entity) and rows (represent an instance of an entity)
Database system has four compoenents:
Users (human or computer)
Database applications (eg a website talks to the DBMS)
Database management System (DBMS) (acts as a gatekeeper/intermediary,
all the info flowing in and out of the database must travel through the DBMS.

Critical for maintaining the quality of the dtaabase. do not allow the users or
database applications to access the data directly.)
Database (store raw data in separate tables)

What do users of a database system do? Use a database application to keep track of
info, use different user interface forms to enter/read/delete/query data, and
produce reports
Database is a self describing collection of related records.Doesnt only contain its
own data, but descriptions of the structure of the data in the database.
Eg Employee ID value is an integer
Tables within a database are related to each other according to the relationships we
establish
Database also contains
User data (what we put in)
Metadata
Indexes and other overhead data (eg tables of data used to improve
performance, track status of database, how users are interacting with db,
indexes
Application metadata (data balues that are used by the applications which
rely on the db, may store user preferances)
DBMS = intermediary
Manages and controls database activities. Creates, processes, and administrators it
controls. It is a type of application program which intrearcts the database but is not
the database itself. You can do the following the DBMS:
Create databases
Create tables
Create supporting structures
Read database data
Modify database data (insert, update, delete)
Maintain database structures
Enforce rules
Control concurrency
Provide security
Perform database lookup
DBMS an enforce constraints too which businesses may work within. Referential
integrity constraint ensures that the values we are entering in one table, have
matching values in another table. Eg customer and project table exist. Trying to
entry info about a new project. When typing in a new project name, put in customer
ID too. Will check in the customer table if that customer ID exists.

Database applications = need to use or work with data in the datbases. Eg data
driven websites, mobile or desktop apps, productivity software
Personal database systems
support one application,
have only a few tables,
simple in design,
involve only one computer,
support one user at a time
Eg Microsoft access. Convenient, easy to use, but no very powerful. Contain the
capability to build the database application within the DBMS. Eg in Microsoft access,
can create data entry forms/generate forms with
Enterprise level database systems typically:
Support several users simultaneously
Support more than one application
Involve multiple computers
Are complex in design
Have many tables
Have many databases
2. THE RELATIONAL MODEL
An entity is something important, represents a single theme or business concept
about which you might want to track info of particular attributes
Eg an employee, dpt, project
Relation is a two dimensional table that has specific characteristics. Must contain:
Rows contain specific instances of instances of an entity
Columns contain data about the attributes
Cells of the table hold a single value
All values in a column are of the same kind, data type
Each column in same table has a unique name (so DBMS know which we are
referring to)
No two rows in the table can be identical
The order of the rows and columns are unimportant
Column = field = attribute
Row = record
Table = relation = file
Key is one or more columns of a relation whose values are used to identify a row
Unique key is a data value is unique for each row. Key will uniquely identify a row

Nonunique key, data value may be shared among several rows. Consequently, the
key will identify a set of rows (foreign) usually used to categorized rows in a table as
a group
Unique
Candidate has a potential to become a primary key
Composite unique key that is composed of two or more attributes. Combine the
values of two or more columns to get uniqueness. Eg flight number for a flight taking
off one a day + the date = unique. Each of the columns may reoccur with the
Primary main identifier for a relation. Able to use it to locate a single specific row
in the table
Surrogate unique, numeric value tht is added to a relation to serve as the primary
key. Used when we do not have a column in the table that would naturally serve as
the primary key. Would have no REAL meaning outside the database. Often used to
avoid using a composite key.
Non-unique
Foreign key a primary key from one table that is placed in another table, with the
purpose of linking the rows together. It is given the name foreign key in the table
that receives the column
A table may be related to other tables. For examples, an employee works in a dpt. A
manager controls a project.
Establish relationships btw the tables in our databse using matched pairs of values
(?)
Referential integrity states that every value of a foreign key MUST match a value of
an existing primary key
Null value can indicate
Colum value is not appropriate for the specific row
Column value has not been decided or is uknown
Functional dependency relationship btw attributes in which one attribute (or a
group of attributes) determines the value of another attribute in the same table
Eg Box price determined by cookie price & quantity. Written: Box price (cookie
price, qnty)
Can use the primary key to find the other values in the row. Eg if we know
employee ID, can find employee last name and phone number. Employee ID is a
determinant. (EmployeeID) (EmpLastName, EmpPhone)
Normalization a process to determine whether a relation is well formed one that
is not susceptible to the three type of the anomalies (insertion, deletion, update)

Attempting to create relations in which we can insert new data, elete existing data,
or modifying it without creating one of these alumni
Two design principles associated with normalized relations:
To be a well formed relation, every determinant must be a candidate key
If we encounter relation not well formed, should be broken in two or more
smaller relation and make them well formed
A well formed relation will not encompass more than one business concept
To get it to be well formed, can go through the following process:

First normal form a relation is in first normal if it does not contain any
multivalued attributes. Every attribute value is atomic, not more than one value in a
cell of the table. All relations are by definition in first normal form (one of the
characteristic all relations are tables but not all tables are relations).
Second normal form must be fully functional dependent on the ENTIRE primary
key. Value of the primary keys must be able to fully functionally determine all the
other non key of the attributes of the table. No partial dependences within the
attributes of the table
Third normal form must meet criteria of the above two + have no transitive
dependency. A functional dependency on an attribute that Is not the primary key.
Transitive because primary key is determinant for another non-key attribute, which
is in turn determinant for a third.
The solution is that the non key determinant with transitive dependences goes into
a new table; non key determinant becomes primary key in the tnew table and
remains as a foreign key in the old table

Each relation should contain attributes to relate one business concept.


4. DATA MODELING AND THE ER MODEL
Three stages of database development
1. Requirements analysis stage process of gathering info to understand data
problem for which we are attempting to design a solution.
2. Component design stage create data models which are graphical
representation of database solution which you ultimately plan to ipmlement
3. Implementation stage implementing database designs. Real world,
functioning database which can be used by a
Requirement analysis stage
Many dif possible sources of information: user interviews, forms/reports/queries
that are used with a current system, use cases, business rules, observation, JAD
sessions (Joint app development)
Data model (or ER diagram) graphical representation of the database we iwish to
implement
ER models consist of
Entities
Attributes (identifiers + non key attributes)
Relationships
An entity class is a description of the structure and format of the occurrences of the
entity. Similar to a recipe or architectural blueprints.
Entity instance is a specific occurrence of an entity class. (The real world cake/real
world house)
If we have an employee entity class, define attributes we want to track for all
employees name, address. When you add a new row and specify specific values is
an entity instance.

Entities have attributes that together describe the entity.


Examples: projectName, startDate, projectType, projectDescription
Each attribute has a data type and other properties
Entities instances have identifiers (keys), keys are special type of attribute. Key will
identify a specific instance in the entity class: socialSecurityNumber, studentId,
employeeId, emailAddress etc
If a key is unique, every instance of the entity/row in the table, will have a unique
value for that attribute.
Relationships naturally emerge from the business concepts. The degree of the
relationship defines the number of entity classes that participate in the relationship
Degree 1 = unary // an entity is related to itself, recursive relationship
Degree 2 = binary // one entity is related to another entity
Degree 3 = ternary // three entities involved in the relationship

One-to-one binary an instance of one entity class related to a single entity instance
in another entity class
One-to-many single entity instance in one entity class is related to many entity
instances in another entity class.
Many-to-many many instance of one entity, can be related to many instances of
another entity
An in ER modeling, two dif types of cardinalities: maximum and minimum. all
Maximum allow us to specify the maximum number of entity instances that can
participate in a relationship instance. one, many, or some positive fixed number
Minimum minimum number of entity instances that can participate in a
relationship instance. Typical zero (optional relationship) or one (mandatory)

The symbol that appears closest to the entity is the maximum cardinality while the
adjacent cardinality is the minimum.
Relationships can be read in two different ways

A customer can place one to many orders.


An order can place by one and only one customer
HAS-A relationships term used when an entity has a relationship to a second
entity. Eg an employee has a locker, a locker has an employee
But there are also IS-A relationships and are discussed later
A weak entity is an entity whose instances cannot exist in the database without the
existence of an instance of another entity. There are two dif type of weak entities
ID-dependent weak entities is a weak entity cannot exist without it parent
entity. Will have as part of primary key, the primary key of its parent entity.
The databse will enforce the constraint that the ID-dependent weak entity
cannot exist w/o its parent tity. Represented by a solid line.
Non-ID-dependent The relationship btw a strong and weak entity.
Represented by a dashed line.
A strong entity is an entity whose instances can exist independently, do not rely on
the existence of any other entities.
An entity can have a unary relationship to itself known as a recursive relationship
Recursion can be used to implement hierarchical relationships
Associative Entities
There are instances where you have entities in a binary relationship, many to many
Need to create an associative entity, can have attribute in itself. Has a unique
identifier. May participate in other relationships other than the associative one.
It can be looked at as a zipper there are teeth, pull up identifiers from two dif
entities and bringing it into one entity to relate to one entities instance to another
entities instance
Should have associative entities: many to many binary relationships, ternary
relationships, Could use them in a unary relationship

Das könnte Ihnen auch gefallen