+ All Categories
Home > Documents > Review: Application of Database Systems Application of Database Systems ER-diagram Tables and their...

Review: Application of Database Systems Application of Database Systems ER-diagram Tables and their...

Date post: 12-Jan-2016
Category:
Upload: moris-horatio-cooper
View: 214 times
Download: 0 times
Share this document with a friend
Popular Tags:
31
Review: Application of Database Systems Application of Database Systems ER-diagram Tables and their relationships Queries Reports
Transcript
Page 1: Review: Application of Database Systems Application of Database Systems ER-diagram Tables and their relationships Queries Reports.

Review: Application of Database Systems

Application ofDatabase Systems

ER-diagram

Tables and their relationships

Queries

Reports

Page 2: Review: Application of Database Systems Application of Database Systems ER-diagram Tables and their relationships Queries Reports.

•ER-diagram

Entity typesStrong entity typeWeak entity type

RelationshipsCardinality constraintsParticipation constraints

Attributesatomic attributescomposite attributessingle-valued, multi-valued attributesderived attributeskey, partial key, surrogate key, non-key attribute

Page 3: Review: Application of Database Systems Application of Database Systems ER-diagram Tables and their relationships Queries Reports.

employee

department

project

dependent

works for

manages

works on

dependents of

controls

supervision

bdate

ssn

name

lnameminitfname

sex address salary

birthdatename sex relationship

name number location

name number

number ofemployeesstartdate

hours

1

1

1

N

supervisorsupervisee

M

N

11

NNdegree

location

Page 4: Review: Application of Database Systems Application of Database Systems ER-diagram Tables and their relationships Queries Reports.

Mapping from ER-diagrams onto relational schemas

1. Create a relation for each strong entity type

2. Create a relation for each weak entity type

3. For each binary 1:1 relationship choose an entity and include the

other’s PK in it as an FK

4. For each binary 1:n relationship, choose the n-side entity and include

an FK with respect to the other entity.

5. For each binary M:N relationship, create a relation for the relationship

6. For each multi-valued attribute create a new relation

7. For each n-ary relationship, create a relation for the relationship

Page 5: Review: Application of Database Systems Application of Database Systems ER-diagram Tables and their relationships Queries Reports.

fname, minit, lname, ssn, bdate, address, sex, salary, superssn, dno

Dname, dnumber, mgrssn, mgrstartdate

Dnumber, dlocation

Pname, pnumber, plocation, dnum

Essn, pno, hours

Essn, dependentname, sex, bdate, relationship

EMPLOYEE

DEPARTMENT

DEPT _LOCATIONS

WORKS_ON

PROJECT

DEPENDENT

Page 6: Review: Application of Database Systems Application of Database Systems ER-diagram Tables and their relationships Queries Reports.

About participation constraints

If a relationship is mandatory for an entity set, then

if the entity set is on the “many” side of the relationship, then a specification is required to ensure a foreign key has a value, and that it cannot be null

•setting the ‘required’ property for the FK in MS Access, or

•NOT NULL constraint in the DDL.

N

A

c d

B

x y

1

Page 7: Review: Application of Database Systems Application of Database Systems ER-diagram Tables and their relationships Queries Reports.

c d

A

x y c

B

The “required” property for attribute cis set “yes”.

Page 8: Review: Application of Database Systems Application of Database Systems ER-diagram Tables and their relationships Queries Reports.

Setting the required property to Yes

Page 9: Review: Application of Database Systems Application of Database Systems ER-diagram Tables and their relationships Queries Reports.

If the entity set is on the “one” side of a relationship, then a check constraint or database trigger can be specified to ensure compliance.

N

A

c d

B

x y

1

Page 10: Review: Application of Database Systems Application of Database Systems ER-diagram Tables and their relationships Queries Reports.

c d

A

x y c

B

A program should be produced to check that any valueappearing in c-column in table A must appear at leastonce in c-column in table B.

Page 11: Review: Application of Database Systems Application of Database Systems ER-diagram Tables and their relationships Queries Reports.

Creating a Table in Design View

If you want to create the basic table structure yourself and define all the field names and data types, you can create the table in Design view.

Page 12: Review: Application of Database Systems Application of Database Systems ER-diagram Tables and their relationships Queries Reports.
Page 13: Review: Application of Database Systems Application of Database Systems ER-diagram Tables and their relationships Queries Reports.

Data Types of Fields

• Attachment    Files, such as digital photos. Multiple files can be attached per record.

This data type is not available in earlier versions of Access.

• AutoNumber    Numbers that are automatically generated for each record.

• Currency    Monetary values.

• Date/Time    Dates and times.

• Hyperlink    Hyperlinks, such as e-mail addresses.

• Memo    Long blocks of text and text that use text formatting. A typical use of a Memo

field would be a detailed product description.

• Number    Numeric values, such as distances. Note that there is a separate data type for

currency.

• OLE Object    OLE objects (OLE object: An object supporting the OLE protocol for

object linking and embedding.

• Text    Short, alphanumeric values, such as a last name or a street address.

• Yes/No    Boolean values.

Page 14: Review: Application of Database Systems Application of Database Systems ER-diagram Tables and their relationships Queries Reports.

• Field Properties can be used to specify characteristics for individual fields

• Located in the lower pane of Table Design View

Caption property

Field Size property

Page 15: Review: Application of Database Systems Application of Database Systems ER-diagram Tables and their relationships Queries Reports.

Create Tables – Consider a Foreign Key

Customer ID - Primary Key in Customer TableCustomer ID –will only appear in one record - there must only be one unique id per customer

Customer ID - Regular Field in Orders TableCustomer ID may appear many times – one customer can place many orders

• Based on the above example:– Customer Id is the foreign key in the Orders table– This is referred to as a One to Many Relationship

Page 16: Review: Application of Database Systems Application of Database Systems ER-diagram Tables and their relationships Queries Reports.

• Referential Integrity

(i) Consider two relation schemas R1 and R2;

ii) The attributes in FK (foreign key) in R1 have the same domain(s) as the primary key attributes PK (primary key) in R2; the attributes FK are said to reference or refer to the relation R2.

iii) A value of FK in a tuple (record) t1 of the current state r(R1) either occurs as a value of PK for some tuple t2 in the current state r(R2) or is null. In the former case, we have t1[FK] = t2[PK], and we say that the tuple t1

references or refers to the tuple t2.Example:

Order(OrderId, …, CustId) Customer(CustId, … )

FK

Page 17: Review: Application of Database Systems Application of Database Systems ER-diagram Tables and their relationships Queries Reports.

Working with Multiple Tables – Table Relationships

• The strength of Access is the fact that it is a relational database– This means you can have multiple tables and

create relationships between each table– This helps eliminate redundant data

Relationship between two tables

Page 18: Review: Application of Database Systems Application of Database Systems ER-diagram Tables and their relationships Queries Reports.

Working with Multiple Tables – Referential Integrity

• Assures that the references to relationships between data is accurate

• Established when creating the relationship between two tables

Enforce Referential Integrity

Page 19: Review: Application of Database Systems Application of Database Systems ER-diagram Tables and their relationships Queries Reports.

Working with Multiple tables - Cascades

• When active, data changed in one table that is in a relationship will be changed in its related tables

• Can be set when establishing relationships between tables

Cascade update and cascade delete

Page 20: Review: Application of Database Systems Application of Database Systems ER-diagram Tables and their relationships Queries Reports.

Creating a Table with a Query

A make table query retrieves data from one or more tables, and then loads the result set into a new table. That new table can reside in the database that you have open, or you can create it in another database.

Page 21: Review: Application of Database Systems Application of Database Systems ER-diagram Tables and their relationships Queries Reports.

Queriesdifferent kinds of queries:- select queries- action queriesMake-Table queryDelete queryAppend-Table queryUpdate query- Crosstab query- total queriesGroup byAggregate functions:

count, sum, maximum, minimum, average- one-to-one relationship, one-to-many relationship

Page 22: Review: Application of Database Systems Application of Database Systems ER-diagram Tables and their relationships Queries Reports.

Using Query Design View

• Query Design grid has two panes – the table pane and the design pane

• Striking the F6 key will toggle you between sections

Tables pane

Design pane

Page 23: Review: Application of Database Systems Application of Database Systems ER-diagram Tables and their relationships Queries Reports.

Select Query

• Searches associated tables and returns a dataset that matches the query parameters

Page 24: Review: Application of Database Systems Application of Database Systems ER-diagram Tables and their relationships Queries Reports.

Specifying Criteria – Currency and Operands

• Specify criteria with currency – Without the dollar sign – With or without the decimal point

• Use operands such as:– Less than and greater than– Equal to or not equal to

Greater than (>) operand

Currency amount entered without dollar sign

Page 25: Review: Application of Database Systems Application of Database Systems ER-diagram Tables and their relationships Queries Reports.

Is Null criteria and resulting dataset

IS NOT NULL criteria and partial resulting dataset

• IS NULL finds only records that have no value• IS NOT NULL excludes Null value records

Page 26: Review: Application of Database Systems Application of Database Systems ER-diagram Tables and their relationships Queries Reports.

Specifying Criteria – And and Or

• OR finds records that can match one or more conditions • AND finds records that must match all criteria specified

Or Criterion and resulting dataset

And criterion and resulting dataset

Page 27: Review: Application of Database Systems Application of Database Systems ER-diagram Tables and their relationships Queries Reports.

Database Analysis Tools

• Clauses

- Added to statements to restrict/specify records

• WHERE clause

- Specifies which records to return

• ORDER BY clause

- Specifies sort order

SELECT fname FROM customerWHERE lname=“Smith”ORDER BY fname

Returns records in the fname field only where the lname field is equal to Smith. Records are sorted in ascending order by first name

Page 28: Review: Application of Database Systems Application of Database Systems ER-diagram Tables and their relationships Queries Reports.

Data AggregatesUse a Totals Query to Group

Grouping field

Field to be totaled

• Organizes query results into groups

• Only use the field or fields that you want to total and the grouping field

select Location, sum(Balance)where Account, Branchgroup by Location

Page 29: Review: Application of Database Systems Application of Database Systems ER-diagram Tables and their relationships Queries Reports.

Reportsseven sections:

- report header- page header- group header- details- group footer- page footer- report footer

Page 30: Review: Application of Database Systems Application of Database Systems ER-diagram Tables and their relationships Queries Reports.
Page 31: Review: Application of Database Systems Application of Database Systems ER-diagram Tables and their relationships Queries Reports.

Recommended