Upload
alexander-chapman
View
220
Download
1
Tags:
Embed Size (px)
Citation preview
11
Lesson OverviewLesson Overview
2.1 Basic Concept and 2.1 Basic Concept and VocabularyVocabulary
2.2 Database Approach: DBMS2.2 Database Approach: DBMS 2.3 Characteristic of DBMSs2.3 Characteristic of DBMSs 2.4 The Relationship Between 2.4 The Relationship Between
Application Programs And The Application Programs And The DBMSDBMS
2
2.12.1 Basic Concept and VocabularyBasic Concept and Vocabulary
33
2.1 Basic Concept and Vocabulary2.1 Basic Concept and Vocabulary
DatabaseDatabase FileFile Entity/ RecordsEntity/ Records Field/AttributeField/Attribute Key field:Key field:
Primary keyPrimary key Secondary keySecondary key Foreign keyForeign key
IndexIndex Data TypeData Type MetadataMetadata Data DictionaryData Dictionary
4
The Hierarchy of DataThe Hierarchy of Data
5
Data Entities, Attributes, and KeysData Entities, Attributes, and Keys
66
Entities/RecordsEntities/Records Entities are Entities are anythinganything you want to you want to
store data aboutstore data about people (students, customers, people (students, customers,
employees, etc.)employees, etc.) places (resorts, cities, countries, etc.)places (resorts, cities, countries, etc.) things (restaurants, products, things (restaurants, products,
invoices, movies, paintings, books, invoices, movies, paintings, books, buildings, contracts, etc.)buildings, contracts, etc.)
events (elections, presentations, events (elections, presentations, earthquakes, hurricanes, etc.)earthquakes, hurricanes, etc.)
77
Entity SetsEntity Sets
Entity sets are Entity sets are collectionscollections of of related entitiesrelated entities. Entities are . Entities are related by their classification:related by their classification:
student entities are related by the student entities are related by the fact that they are all studentsfact that they are all students
invoice entities are related by the invoice entities are related by the fact that they are all invoicesfact that they are all invoices
car entities are related by the fact car entities are related by the fact that they are all carsthat they are all cars
88
Entity Sets, cont.Entity Sets, cont.
Entity sets are named after the entities that Entity sets are named after the entities that are stored in them.are stored in them.
Entity set names are singular.Entity set names are singular.Entity set names are capitalized.Entity set names are capitalized.
Examples:Examples:
An entity set named STUDENT contains An entity set named STUDENT contains student entities.student entities.
An entity set named INVOICE contains An entity set named INVOICE contains invoice entities.invoice entities.
An entity set named PRODUCT contains An entity set named PRODUCT contains product entities.product entities.
99
Entity Sets, cont.Entity Sets, cont.
Entity sets can only contain Entity sets can only contain relatedrelated entitiesentities a a STUDENTSTUDENT entity set may not contain entity set may not contain
INVOICE entitiesINVOICE entities a a DEPARTMENTDEPARTMENT entity set may not contain entity set may not contain
invoice entitiesinvoice entities a a PRODUCTPRODUCT entity set may not contain entity set may not contain
employee entitiesemployee entities
……. And so on . And so on
1010
Entity Sets and EntitiesEntity Sets and Entities
Entity setsEntity sets are collections of are collections of related entitiesrelated entities
Unfortunately, database designers almost Unfortunately, database designers almost always use the two terms as synonyms. always use the two terms as synonyms.
When database designers refer to When database designers refer to entitiesentities, , they really are referring to they really are referring to entity setsentity sets. .
Therefore, when you see a reference to an Therefore, when you see a reference to an EMPLOYEEEMPLOYEE “entity” in a database design, “entity” in a database design, remember that remember that EMPLOYEEEMPLOYEE actually actually represents an entity set that contains a represents an entity set that contains a collection of employee entities.collection of employee entities.
1111
Database Table ContentsDatabase Table Contents
A database table is used to A database table is used to store an entity setstore an entity set An entity set is a collection of An entity set is a collection of
related entitiesrelated entities An entity is anything you want to An entity is anything you want to
keep track of, so an entity may be keep track of, so an entity may be a person, place, thing, event, etc.a person, place, thing, event, etc.
1212
Database Table ComponentsDatabase Table Components
At the At the conceptualconceptual level, a level, a database table may be viewed as a database table may be viewed as a matrix.matrix. Matrix rows are also known as Matrix rows are also known as tuplestuples
or or recordsrecords each row contains an entityeach row contains an entity
Matrix columns are also called Matrix columns are also called fieldsfields.. Each column (field) contains the Each column (field) contains the
entity’s attribute valuesentity’s attribute values
1313
Attributes/Field Attributes/Field
Attributes are the characteristics that Attributes are the characteristics that describe entities.describe entities.
Example: Example: a a studentstudent entity may be described by entity may be described by
attributes that may include his or attributes that may include his or her ... her ... social security numbersocial security number namename addressaddress date of birthdate of birth majormajor
1414
Attributes, cont.Attributes, cont.
Remember: Attributes are the Remember: Attributes are the characteristics that describe entities characteristics that describe entities
An invoice entity may be described An invoice entity may be described by attributes such as these:by attributes such as these: invoice numberinvoice number invoice dateinvoice date customer numbercustomer number invoice totalinvoice total
1515
Attribute NamesAttribute Names
Attribute names are capitalized.Attribute names are capitalized. For documentation reasons, For documentation reasons,
attribute names are composed attribute names are composed of two parts:of two parts: the first few characters reflect the the first few characters reflect the
entity they help describe. entity they help describe. subsequent characters are subsequent characters are
sufficiently descriptive to identify sufficiently descriptive to identify the attribute.the attribute.
1616
Attribute Names, cont.Attribute Names, cont.
Examples of attribute names:Examples of attribute names:
EMP_LNAME = employee last nameEMP_LNAME = employee last name
STU_GPA = student grade point STU_GPA = student grade point averageaverage
PROD_CODE = product codePROD_CODE = product code
CUST_LNAME = customer last nameCUST_LNAME = customer last name
INV_NUM = invoice numberINV_NUM = invoice number
1717
Key fieldKey field Primary Key (PK):Primary Key (PK):
An attribute (column), that uniquely identifies An attribute (column), that uniquely identifies each row in a database table.each row in a database table.
Cannot contains NULL valuesCannot contains NULL values Secondary Key:Secondary Key:
A non-PK search key, which may not yield A non-PK search key, which may not yield unique records. E.g.: the combination of first unique records. E.g.: the combination of first and last name may be a secondary key.and last name may be a secondary key.
Foreign Key (FK)Foreign Key (FK) An attribute (column) in a table that is a PK An attribute (column) in a table that is a PK
in another table. E.g.: in Order table, in another table. E.g.: in Order table, Customer_ID is a FK because it is a PK in Customer_ID is a FK because it is a PK in the Customer table.the Customer table.
18
Entity IntegrityEntity Integrity
A table exhibits entity integrity when all of itsPrimary Key (PK) values uniquely identify eachtable row (record.)
EMPLOYEE table
1. A PK cannot contain duplicate values2. A PK cannot contains nulls
Note: A null indicates the absence of a value; it is not a blank. (You create a null when you tap the ENTER key without first making an entry. A blank is created when you tap the space bar and then tap the ENTER key.)
19
Foreign keys (FK) Foreign keys (FK) and Referential Integrityand Referential Integrity
To maintain referential integrity, a foreign key (FK) must reference an existing PK value in a related table or it may be null.
A Foreign Key (FK) is an attribute located in one table that “points to” a Primary Key (PK) in a related table. The use ofFKs allows you relate one table to another.
INVOICE table
LINE table
2020
IndexIndex
A secondary file structure that A secondary file structure that provides an alternative path to the provides an alternative path to the data.data.
A sorted list of A sorted list of key valueskey values from the from the original table along with a pointer original table along with a pointer to the rest of the data in each row. to the rest of the data in each row.
Used to speed up searches and Used to speed up searches and data retrieval.data retrieval.
2121
Data TypeData Type
The data characteristic that The data characteristic that determines how the filed values determines how the filed values can be used.can be used.
Example:Example: An employee name is properly An employee name is properly
defined to be a text data type.defined to be a text data type. An employee birthday is defined as An employee birthday is defined as
date data typedate data type E.g.: text, numeric, date, currency, E.g.: text, numeric, date, currency,
OLE objectOLE object
2222
MetadataMetadata
Data about dataData about data Data that describe other data Data that describe other data
including the source, use, value and including the source, use, value and meaning of the datameaning of the data
Typically stored in a data dictionaryTypically stored in a data dictionary E.g.: E.g.: Data Item Name Data Type Length in
Characters (bytes) Name Text 30
Stud_No Numeric 6
Class Text 4
Major Text 4
2323
Data DictionaryData Dictionary
A compilation of the metadataA compilation of the metadata A special database that describe A special database that describe
individual databases and its individual databases and its environment. environment.
Contains data descriptors called Contains data descriptors called metadata that define source, the metadata that define source, the use, the value and the meaning use, the value and the meaning of data.of data.
24
2.12.1Database Approach: DBMSDatabase Approach: DBMS
2525
Fig 5.3Fig 5.3
2626
Problems with the “Traditional” Problems with the “Traditional” ApproachApproach
Example: Example: Students registration Students registration Students library Students library Students Industrial training Students Industrial training Students graduationStudents graduation
Data redundancyData redundancy Program-data dependenceProgram-data dependence InflexibilityInflexibility
27
Database ApproachDatabase Approach
2828
Table 5.1Table 5.1
2929
Table 5.2Table 5.2
3030
Database Management Systems Database Management Systems (DBMSs)(DBMSs)
Provide a user viewProvide a user view Provide tools to create & modify Provide tools to create & modify
the databasethe database Store & retrieve dataStore & retrieve data Manipulate dataManipulate data Produce reportsProduce reports
3131
Fig 5.15Fig 5.15
3232
Fig 5.16Fig 5.16
3333
Fig 5.17Fig 5.17
3434
Database Management System Database Management System (DBMS) “The Tools”(DBMS) “The Tools”
Define – Define – specify data types, structures and specify data types, structures and constraintsconstraints
Construct – Construct – initial creation and populationinitial creation and population
Manipulate – Manipulate – run queries, Alter table run queries, Alter table definitions, insert/delete recordsdefinitions, insert/delete records
Share – Share – Concurrent access, Concurrent access,
Protect – Protect – from system malfunction or from system malfunction or malicious attacksmalicious attacks
Maintain – Maintain – As requirements change, so As requirements change, so should the system.should the system.
3535
What DBMS have you heard What DBMS have you heard of?of? __________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
3636
Mainstream DBMSsMainstream DBMSs Oracle - Oracle - Oracle corporationOracle corporation
www.oracle.com DB2 - DB2 - IBMIBM
http://www-306.ibm.com/software/data/db2/udb/ ACCESS, SQL Server - ACCESS, SQL Server - MicrosoftMicrosoft
http://www.microsoft.com/Office/Access/prodinfo/ Adaptive Server Enterprise (ASE) - Adaptive Server Enterprise (ASE) -
SybaseSybase http://www.sybase.com/products/databaseservers/ase
MySQL - MySQL - MySQL Open sourceMySQL Open source http://www.mysql.com/
PostgreSQL –PostgreSQL – Global Development Global Development Group Group http://advocacy.postgresql.org/
3737
Oracle Oracle Ideal for large scale grid and cluster computingIdeal for large scale grid and cluster computing Currently pushing toward small business, Currently pushing toward small business,
single computer serverssingle computer servers Many Enterprise applications are available or Many Enterprise applications are available or
includedincluded Finance managementFinance management Human Resource ManagementHuman Resource Management MarketingMarketing Product lifecycle managementProduct lifecycle management On and on and on...On and on and on...
43% market share43% market share
3838
DB2DB2
Flexible to install on a wide Flexible to install on a wide variety of systemsvariety of systems
Focuses on the integration of Focuses on the integration of other DBMS. other DBMS.
Data can be distributed.Data can be distributed. Has many application packages, Has many application packages,
similar to Oraclesimilar to Oracle 24% Market Share24% Market Share
3939
SQL ServerSQL Server
Targets small businessTargets small business Easy to installEasy to install Low cost of ownershipLow cost of ownership Excellent SupportExcellent Support Notoriously insecure Notoriously insecure
Susceptible to virus and worm attacksSusceptible to virus and worm attacks New patches released monthlyNew patches released monthly
17% Market Share17% Market Share
4040
Adaptive Server Enterprise (ASE) Adaptive Server Enterprise (ASE) - Sybase- Sybase
Low resource requirementsLow resource requirements Fast and reliableFast and reliable Lower cost of ownership Lower cost of ownership
compared to Oracle or DB2compared to Oracle or DB2 Popular on Wall Street due to its Popular on Wall Street due to its
high transaction ratehigh transaction rate 2% Market Share2% Market Share
4141
MySQL MySQL
Open source DBMSOpen source DBMS Supported by a for-profit company Supported by a for-profit company Well known compared to other Well known compared to other
open source solutions.open source solutions. Offers free GPL version and a Offers free GPL version and a
licensed version that includes licensed version that includes vendor support.vendor support.
Less popular and less scalable Less popular and less scalable than Oracle, DB2 or ASEthan Oracle, DB2 or ASE
4242
PostgreSQLPostgreSQL
Open Source DBMSOpen Source DBMS Developed (originally) at the Developed (originally) at the
University of California, BerkeleyUniversity of California, Berkeley Supported by a non-for-profit Supported by a non-for-profit
organization: organization: PostgreSQL – PostgreSQL – Global Development GroupGlobal Development Group
More developed and robust than More developed and robust than MySQLMySQL
Less popular in the business Less popular in the business worldworld
43
DBMS vs. Custom applicationDBMS vs. Custom application
DatabaseDefinition
(meta-data)
StoredData
Software to Process Queries
Software to Access Stored Data
User Interface User Interface/Software to
Process Queries/Software to Access
Stored Data
StoredData
UsersDatabase approach Custom App.
DBMS software
44
2.32.3 Characteristic of DBMSsCharacteristic of DBMSs
4545
Characteristics of the Database Characteristics of the Database ApproachApproach
1.1. Self DescribingSelf Describing A catalog keeps track of the A catalog keeps track of the
database structuredatabase structure Contains a description of its own Contains a description of its own
structure called a structure called a data dictionary, data dictionary, data directory, metadatadata directory, metadata
46
SelfSelf DescribingDescribing
.1.1Catalog allows freedom to choose DBMSCatalog allows freedom to choose DBMS
DatabaseDefinition
(meta-data)
StoredData
Software to Process Queries
Software to Access Stored Data
User Interface
Software to Process Queries
Software to Access Stored Data
choice 1 choice 2
...Software to
Process Queries
Software to Access Stored Data
choice n
47
Self DescribingSelf Describing
.1.1One DBMS can access several independent databasesOne DBMS can access several independent databases
Meta-Data1
StoredData
1
User Interface
Software to Process Queries
Software to Access Stored Data
Meta-Data2
StoredData
2
University DB Matchmaker DB
4848
Characteristics of the Database Characteristics of the Database ApproachApproach
1.1. Self DescribingSelf Describing A catalog keeps track of the A catalog keeps track of the
database structuredatabase structure
2.2. Program/Data IndependenceProgram/Data Independence Allows program to be modified Allows program to be modified
without changing the file without changing the file structure.structure.
49
Program/Data IndependenceProgram/Data Independence
DBMS Custom App.
User Interface User Interface
Catalog
Name AgeGender
Name AgeGender
Client:
Client:
50
Program/Data IndependenceProgram/Data Independence
DBMS Custom App.
User Interface User Interface
Catalog
Name AgeGender
Name AgeGender
Height
Height
Client:
Client:
Is the existence of a catalog sufficient for program data independence?
5151
Characteristics of the Database Characteristics of the Database ApproachApproach
1.1. Self DescribingSelf Describing A catalog keeps track of the A catalog keeps track of the
database structuredatabase structure
2.2. Program/Data IndependenceProgram/Data Independence
3.3. Multiple ViewsMultiple Views View=Virtual TableView=Virtual Table
52
ViewsViews
Internal (Physical) Tables
Conceptual tables
...View 1 View 2 View 3 View n
User Interface, variety of users
5353
When would multiple views be When would multiple views be useful?useful?
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
54
Example Views – Matchmaker Example Views – Matchmaker DBDB
Client ID Name Phone email Gender Age123 Edward 223-4432 [email protected] M 20574 Sally 394-0293 [email protected] F 22
My Info Name Phone email Gender AgeEdward 223-4432 [email protected] M 20
Brows Others Name email Gender Age Hobby1 Hobby2 Avg RatingEdward [email protected] M 20 Baseball 1Sally [email protected] F 22 Baseball Drawing 5
DBA view (logical table)
Owning client’s view (virtual table)
View to brows other client’s info. (virtual table)
5555
Characteristics of the Database Characteristics of the Database ApproachApproach
1.1. Self DescribingSelf Describing A catalog keeps track of the database structureA catalog keeps track of the database structure
2.2. Program/Data IndependenceProgram/Data Independence
3.3. Multiple ViewsMultiple Views View=Virtual TableView=Virtual Table
4.4. Data Integration - Pooling the files in a centralized locationData Integration - Pooling the files in a centralized location Data Sharing - Allows all authorized users access through data integrationData Sharing - Allows all authorized users access through data integration Minimum Data Duplication Or Redundancy - Maintaining System integrity, Minimum Data Duplication Or Redundancy - Maintaining System integrity,
efficiency and reliabilityefficiency and reliability
56
2.42.4 The Relationship Between The Relationship Between Application Programs And The DBMSApplication Programs And The DBMS
5757
The Relationship Between Application The Relationship Between Application Programs And The DBMSPrograms And The DBMS
A User Interacts with a A User Interacts with a Application with Database Application with Database
The Application Interfaces The Application Interfaces with the DBMSwith the DBMS
The DBMS accesses the The DBMS accesses the DatabaseDatabase
5858
Actors/UsersActors/Users
DevelopersDevelopers DBADBA DesignerDesigner System AnalystSystem Analyst ProgrammerProgrammer
End userEnd user ParametricParametric CasualCasual SophisticatedSophisticated
5959
The Relationship Between Application The Relationship Between Application Programs And The DBMS -Continue ...Programs And The DBMS -Continue ...
At one time application programs and At one time application programs and the DBMS were clearly distinctthe DBMS were clearly distinct
Application Programs were written In Application Programs were written In 3GL such as COBOL in the past.3GL such as COBOL in the past.
Currently all 4Currently all 4thth GL or web-based GL or web-based development tools can associate with development tools can associate with DBMS. DBMS.
These Application Programs called These Application Programs called upon the DBMS for management upon the DBMS for management services.services.
60
USER
DatabaseApplications
DBMS Database
The Relationship Between Application The Relationship Between Application Programs And The DBMS -ContinuePrograms And The DBMS -Continue... ...
6161
SummarySummary Basic Concept and VocabularyBasic Concept and Vocabulary
DatabaseDatabase FileFile Entity/ RecordsEntity/ Records Field/AttributeField/Attribute Key field:Key field: Primary keyPrimary key Secondary keySecondary key Foreign keyForeign key IndexIndex Data TypeData Type MetadataMetadata Data DictionaryData Dictionary
6262
SummarySummary
Characteristic of DBMSsCharacteristic of DBMSs1.1. Self DescribingSelf Describing
2.2. Program/Data IndependenceProgram/Data Independence
3.3. Multiple ViewsMultiple Views
4.4. Data IntegrationData Integration
The Relationship Between The Relationship Between Application Programs And The Application Programs And The DBMSDBMS