Sie sind auf Seite 1von 93


What You'll Learn This Week

Introduction to the course Introduction to Databases File Systems Example Database Brief History of Database Systems Contents of a Database
o o o o

User Data Metadata Indexes Applications Metadata

Data Modelin and Database Desi n !he Database De"elopment #rocess Desi nin A Database $ A Brief Example For %ext &ee'

Introduction to the course

Syllabus Computer (abs and Soft)are Course (o istics

Introduction to Databases
BDS: Connolly, Begg, Holo c!ak Ch* + and , -roenke Book ).th ed+, Chap* + and , /ata2 Toledo # Cush%an Schaum-s .utlines Ch* +


&l%asri#'a(athe )*rd ed+,

/c0adden )1th ed+,

Ch* +

Ch* + and ,

Chap* +

3: What is a Database 4 Ans)er from BDS/ A shared collection of lo ically related data and descriptions of that data0 desi ned to meet the needs of na or ani1ation* Ans)er from Elmasri2%a"athe/

A Database 3DB4 is collection of related data $ )ith the follo)in properties/ +* A DB is lo ically coherent and has some rele"ant meanin ,* A DB is desi ned0 built and populated )ith data for a specific purpose 5* A DB represents some aspect of the real )orld*

&e can also say that the database is a model of )hat the users percei"e* !hree main cate ories of models/
1. 2.

5ser or Conce6tual /odels: Ho) users percei"e the )orld and2or the business* Logical /odels: 6epresent the lo ic of ho) a a business operates* For example0 the relationship bet)een different entities and the flo) of data throu h the or ani1ation* Based on the User-s model* "hysical /odels: 6epresent ho) the database is actually implemented on a computer system* !his is based on the lo ical model*


7 Database /anage%ent Syste% )DB/S, A Soft)are system that enables users to define0 create and maintain the database and pro"ides controlled access to the database* 7 Database Syste% )DBS, contains/ !he Database 8 !he DBMS 8 Application #ro rams 3)hat users interact )ith4

%ote/ &e )ill explore ho) the application0 DBMS and database are distributed in the Database System Architecutres module later in the semester*

0ile Syste%s

0ile Syste%: A collection of indi"idual files accessed by applications pro rams Li%itations o7 a 0ile Syste%:

Separated and Isolated Data $ Ma'es coordinatin 0 assimilatin and representin data difficult Data Duplication $ &astes space and can lead to data inte rity 3inconsistency4 problems Application #ro ram Dependencies $ Chan es to a sin le file can re9uire chan es to numerous application pro rams Incompatible Files (ac' of Data Sharin $ Difficult to control access to files0 especially to indi"idual portions of files

o o

$d(antages o7 a DB/S A DBMS can pro"ide/

Data Consistency and Inte rity $ by controllin access and minimi1in data duplication Application pro ram independence $ by storin data in a uniform fashion Data Sharin $ by controllin access to data items0 many users can access data concurrently Bac'up and 6eco"ery Security and #ri"acy Multiple "ie)s of data

o o

o o o

&8a%6le Database
$n &8a%6le Database Custo%erID +,5 +,5 +,? +,B +,B +,> +,>

'a%e Mr* Smith Mr* Smith Mrs* Aones Mr* Axe Mr* Axe Mr* E Mrs* Builder Mr* E Mrs* Builder



State $cct9'u%ber Balance <<=> <<=@ ==++ ??,, ??55 55,, ++,, ?@@@ ,@@@ +@@@ D@@@ <@@@ B@@ =@@

+,5 (exin ton Smith"ille :; +,5 (exin ton Smith"ille :; +, Da"is A"e* ??5 Crinder (n* ??5 Crinder (n* Smith"ille :; Broad"ille CA Broad"ille CA CA CA

DD+ #ar'er 6d* Street"ille DD+ #ar'er 6d* Street"ille

&hat happens )hen a customer mo"es to a ne) house F &ho should ha"e access to )hat data in this database F &hat happens if Mr* and Mrs* Builder both try and )ithdra) GB@@ from account 55,, F &hat happens if the system crashes Hust as Mr* Axe is depositin his latest paychec' F &hat data is the customer concerned )ith F &hat data is a ban' mana er concerned )ith F Send a mailin to all customers )ith chec'in accounts ha"in balance reater than G,@@@

(et all CA customers 'no) of a ne) branch location

Brie7 History o7 Database Syste%s

:;<='s, 1='s Initial use of computers as calculators* (imited data0 focus on al orithms* Science0 military applications* :;>='s Business uses* .r ani1ational data0 customer data0 sales0 in"entory0 accountin 0 etc* File system based0 hi h emphasis on applications pro rams to extract and assimilate data* (ar er amounts of data0 relati"ely simple calculations* :;.='s !he relational model* Data separated into indi"idual tables* 6elated by 'eys* Initially re9uired hea"y system resources* Examples/ .racle0 Sybase0 Informix0 Di ital 6DB0 IBM DB,* :;?='s Microcomputers $ the IBM #C0 Apple Macintosh* Database pro ram such as DBase 3sort of40 #aradox0 Fox#ro0 MS Access* Indi"idual user can crate0 maintain small databases* Late2 :;?='s (ocal area net)or's* &or' roups sharin resources such as files0 printers0 e$mail* Client#Ser(er Database resides on a central ser"er0 applications pro rams run on client #Cs attached to the ser"er o"er a (A%* :;;='s Internet and &orld &ide &eb ma'e databases of all 'inds a"ailable from a sin le type of client $ the &eb Bro)ser* Data )arehousin and Data Minin also emer e* .ther types of Databases/

.bHect$.riented Database Systems* .bHects 3data and methods4 stored persistently* Distributed Database Systems* Copies of data reside at different locations for redundancy or for performance reasons*

$66ro6riate 5se 7or a Database

In addition to the ad"anta es already mentioned/ o #erformance

o o o

Expendability0 Flexibility0 Scalability 6educed application de"elopment times Standards enforcement

Ho)e"er0 'eep in mind/


DBMS has Hi h initial cost 3althou h fallin 4

o o

DBMS has Hi h ."erhead $ re9uires po)erful computers DBMS are not special purpose soft)are pro rams e* *0 contrast a canned accoutin soft)are pac'a e li'e Iuic'en or Iuic'Boo's )ith DBMS li'e MS Access*

&hen is a DBMS Not AppropriateF o Database is small )ith a simple structure

o o

Applications are simple0 special purpose and relati"ely static* Applications ha"e real$time re9uirements Examples/ !raffic si nal control ECU patient monitorin Concurrent0 multi$user access to data is not re9uired*

Contents o7 a Database
A Database contains/ User Data Metadata

Indexes Application metadata

5ser Data

Data users )or' )ith directly by enterin 0 updatin and "ie)in * For our purposes0 data )ill be enerally stored in tables )ith some relationships bet)een tables* Each table has one or more columns* A set of columns forms a database record* 6ecall our example database for the ban'* &hat )ere some problems )e discussed F Here is one impro"ement $ split into , tables/

Custo%er Table Custo%erID +,5 +,? +,B 'a%e Mr* Smith Mrs* Aones Mr* Axe $ddress +,5 (exin ton +, Da"is A"e* City State Smith"ille :; Smith"ille :;

??5 Crinder (n* Broad"ille CA


Mr* E Mrs* Builder DD+ #ar'er 6d*

Street"ille CA

$ccounts Table Custo%erID $cct9'u%ber Balance +,5 +,5 +,? +,B +,B +,> +,>

<<=> <<=@ ==++ ??,, ??55 55,, ++,,

?@@@ ,@@@ +@@@ D@@@ <@@@ B@@ =@@

!he customer table has ? records and B columns* !he Accounts table has > records and 5 columns* %ote relationship bet)een the t)o tables $ CustomerID column* Ho) should )e split data into the tables F &hat are the relationships bet)een the tables F !here are 9uestions that are ans)ered by Database Modelin and Database Desi n*


6ecall that a database is self describing /etadata: Data about data* Data that describe ho) user data are stored in terms of table name0 column name0 data type0 len th0 primary 'eys0 etc* Metadata are typically stored in System tables or System Catalog and are typically only directly accessible by the DBMS or by the system administrator* Ha"e a loo' at the Database Documentor feature of MS Access 3under the tools menu0 choose Analy1e and then Documentor4* !his tool 9ueries the system tables to i"e all 'inds of Metadata for tables0 etc* in an MS Access database*


In 'eepin )ith our desire to pro"ide users )ith se"eral different "ie)s of data0 indexes pro"ide an alternate means of accessin user data* Sortin and Searchin /

An index for our ne) ban'in example mi ht include the account numbers in a sorted order* Indexes allo) the database to access a record )ithout ha"in to search throu h the entire table* Updatin data re9uires an extra step/ !he index must also be updated* Example/ Index in a boo' consists of t)o thin s/ +4 A :ey)ord stored in order ,4 A pointer to the rest of the information* In the case of the boo'0 the pointer is a pa e number*

$66lications /etadata

Many DBMS ha"e stora e facilities for forms0 reports0 9ueries and other application components* Applications Metadata is accessed "ia the database de"elopment pro rams* Example/ (oo' at the Documentor tool in MS Access* It can also sho) metadata for Iueries0 Forms0 6eports0 etc*

Data /odeling and Database Design

Database Design: !he acti"ity of specifyin the schema of a database in a i"en data model Database Sche%a: !he structure of a database that/
o o o

Captures data types0 relationships and constraints in data Is independent of any application pro ram Chan es infre9uently

Data /odel:
o o o

A set of primiti"es for definin the structure of a database* A set of operations for specifyin retrie"al and updates on a database Examples/ 6elational0 Hierarchical0 %et)or'ed0 .bHect$.riented

In this course0 )e focus on the 6elational data model*

Database Instance or State: !he actual data contained in a database at a i"en time*

The Database De(elo6%ent "rocess

!)o o"erall approaches/

+* !op$Do)n/ Desi n systems from an o"erall or ani1ation perspecti"e ,* Bottom$Up/ Desi n systems from a specific perspecti"e $ one system at a time* !he follo)in is a very brief outline describin the database de"elopment process*

5ser needs assess%ent and re@uire%ents gathering: Determine )hat the user-s are loo'in for0 )hat functions should be supported0 ho) the system should beha"e* Data /odeling: Based on user re9uirements0 form a lo ical model of the system* !his lo ical model is then con"erted to a physical data model 3tables0 columns0 relationships0 etc*4 that )ill be implemented* I%6le%entation: Based on the data model0 a database can be created* Applications are then )ritten to perform the re9uired functions* Testing: !he system is tested usin real data* De6loy%ent: !he system is deployed to users* Maintenance of the system be ins*

!here are many "ariations to this basic de"elopment process* A Systems Analysis and Desi n course 3such as CIS ?=@@ for under raduates0 CIS <?<@ for raduates4 co"ers these topics in reater detail*

Designing $ Database 2 $ Brie7 &8a%6le

For our Ban' example0 lets assume that the mana ers are interested in creatin a database to trac' their customers and accounts* Tables CUS!.ME6S CustomerJId0 %ame0 Street0 City0 State0 Kip ACC.U%!S CustomerJId0 AccountJ%umber0 AccountJ!ype0 DateJ.pened0 Balance %ote that )e use an artificial identifier 3a number )e ma'e up4 for the customer called CustomerJId* Ci"en a CustomerJId0 )e can uni9uely identify the remainin information* &e call CustomerJId a -ey for the CUS!.ME6S table*
o o o

CustomerJId is the key for the CUS!.ME6S table* AccountJ%umber is the 'ey for the ACC.U%!S table* CustomerJId in the ACC.U%!S table is called a Foreign Key

%otice that )hen namin columns in the tables )e al)ays use an underscore character and do not use any other punctuation* e"en thou h Access allo)s you to use spaces0 etc* it is not a ood idea*

Aelationshi6s !he relationship bet)een CUS!.ME6S and ACC.U%!S is by CustomerJId* Since a customer may ha"e more than one account at the ban'0 )e call this a One to Many relationship* 3+/%4* Do%ains A domain is a set of "alues that a column may ha"e* Domain also includes the type and len th or si1e of data found in each column* CUS!.ME6S Colu%n Do%ain Data Ty6e Si!e CustomerJId 3:ey4 Inte er %ame Street City State Kip ACC.U%!S Colu%n CustomerJId 3F:4 AccountJ!ype DateJ.pened Do%ain Data Ty6e Si!e Inte er ,@ +B AccountJ%umber 3:ey4 Inte er Date ,@ Character 5@ Character 5@ Character ,B Character , Character B

Character ,

Balance 6eal +,0, &e use the abo"e information to build a lo ical model of the database* !his lo ical model is then con"erted to a physical model and implemented as tables*

!he follo)in is some example data for the Accounts and Customers tables/ Custo%er Table Custo%er9Id +,5 +,? +,B 'a%e Mr* Smith Mrs* Aones Mr* Axe $ddress +,5 (exin ton +, Da"is A"e* City State Bi6 <+,5, <+,5, =+<<,

Smith"ille :; Smith"ille :;

??5 Crinder (n* Broad"ille CA


Mr* E Mrs* Builder DD+ #ar'er 6d*

Street"ille CA


$ccounts Table Custo%er9Id $ccount9'u%ber $ccount9Ty6e Date9C6ened Balance +,5 +,5 +,? +,B +,B +,> +,> <<=> <<=@ ==++ ??,, ??55 55,, ++,, Chec'in Sa"in s Sa"in s Chec'in Sa"in s Sa"in s Chec'in +@2+,2=< +@2+,2=< @+2@B2<, +,2@+2<? +,2@+2<? @=2,,2<? ++2+52== ?@@@*@@ ,@@@*@@ +@@@*@@ D@@@*@@ <@@@*@@ B@@*@@ =@@*@@

Business Aules Business rules allo) us to specify constraints on )hat data can appear in tables and )hat operations can be performed on data in tables* For example/ An account balance can ne"er be ne ati"e*
2. 3. 4.


A Customer can not be deleted if they ha"e an existin 3open4 account* Money can only be transferred from a LSa"in sL account to a LChec'in L account* Sa"in s accounts )ith less than a GB@@ balance incur a ser"ice char e*

Ho) do )e enforce business rules F

o o

Constraints on the database Applications

0or 'e8t Week

Chec' for formal assi nments Chapters to 6ead/ Connolly0 Be 0 Holo)c1a' Chapters ? and < Start formin your roups and discussin ideas for the roup proHects*

What You'll Learn This Week

Systems Analysis and Desi n Information Systems De"elopment (ife Cycle 3SD(C4 Database Desi n #rocess Computer Aided Soft)are En ineerin 3CASE4 Database Application Components
o o o o o

Data Entry Forms 6eports Iueries Menus Applications Code

&&& Applications "ratt#$da%ski Ch* + and D &l%asri#'a(athe )*rd, ed+ Ch* 5 and +D -roenke Book ).th ed+, Ch* , and +@ /c0adden )1th ed+, Ch* +0 , and +@ 3p * 5=+$?@@4

BDS: Connolly, Begg, Holo c!ak Ch* ?0 B and D

Syste%s $nalysis and Design

!he oal of Systems Analysis is to capture an accurate representation of business processes and user-s perceptions of them* !he Business "rocesses )e are interested in are those that encompass the flo) of data 3input0 storin 0 processin 0 output4 throu hout an or ani1ation* "roble%: E"en the best analysts in the )orld )ould come up )ith differin analyses of the same problem* Syste%s $nalysis applies a structured0 formal method to model and impro"e upon business processes* A Syste%s $nalyst can act as an outside consultant brou ht in to address a specific system desi n problemM as a supportin expertM as an a ent of chan e in an or ani1ation

In7or%ation Syste%s De(elo6%ent Li7e Cycle )SDLC,

!here are a number of different "ie)s on the exact steps of SD(C for information systems* !his list i"es a eneral o"er"ie)*

+* "roble%, o66ortunity and obDecti(e Identi7ication 3System Definition4 "roble%s include shortcomin s in present business practices that need to be corrected* C66ortunities include )ays to impro"e existin practices* CbDecti(es identify the oal of an or ani1ation and for specific business processes* !his may also include a feasibility analysis to see )hich problems0 etc* can be ade9uately addressed* ,* In7or%ation Ae@uire%ents deter%ination and Ae@uire%ents Eathering Determine )hat data and information are re9uired to perform business functions* 3BDS chapter B co"ers this4
o o o o

Samplin existin data files0 databases Examinin existin reports and forms User inter"ie)in and 9uestionnaires #rototypin

5* Syste% 'eeds analysis System re9uirements that are based on data re9uirements and decision ma'in processes* 6esult is a system proposal that lists the recommended actions and cost2benefits* 3BDS chapter B co"ers this4 ?* Syste% Design (o ical desi n of the information system includin identification of databases 3tables0 columns0 'eys0 indexes4 that )ill store re9uired data and applications 3forms0 reports0 menus4 that )ill operate on the database* B* Syste% De(elo6%ent and Docu%entation System applications are de"eloped includin data entry forms0 reports0 menus and 9ueries* Documentation for end users is also )ritten* D* Syste% Testing and /aintenance System is tested on real data to pinpoint faults* Any necessary chan es are applied in this step before the system oes into production* >* I%6le%entation and &(aluation !he system is put into production* End user trainin is performed* Users and analysis e"aluate the effecti"eness of the system*

At each step of the cycle0 there is an opportunity to cycle bac' to a prior step* For example0 durin system de"elopment0 it is common to re9uire some chan es to data models de"eloped in the system desi n step* !he abo"e is considered a L&aterfallL de"elopment approach* 6apid Application De"elopment 36AD4 and A ile De"elopment approaches run 9uic'ly throu h steps +$B for small portions of a complete application*

Database Design "rocess

In this course0 )e focus on Step ? in the abo"e SD(C as it pertains to the desi n and modelin of databases* &ith this Ldatabase$centricL approach )e )ill focus on/ +* Cather user and system re9uirements ,* Create a conceptual model of the database usin the Entity 6elationship model that is based on the user re9uirements 5* Choose a DBMS $ in our case0 )e )ill use MS Access0 a des'top relational DBMS* ?* Con"ert this conceptual model 3E$64 into a lo ical database model $ )e )ill use the 6elational model* Elmasri2%a"athe boo' calls this Data model mapping B* %ormali1e the 6elational model of the database D* Implement the normali1ed relations as tables in a relational database $ this is the #hysical Database desi n and implementation* !he abo"e discussion corresponds to Elmasri2%a"athe-s D #hases for DB desi n 3chapter +?4*

Co%6uter $ided So7t are &ngineering )C$S&,

CASE tools can assist analysts in the SD(C* o #ro"ide a repository to store information on each of the phases $ excellent for comprehensi"e documentation of the de"elopment process*

Dia ramin tools assist in analyst2user communications* For example0 Data Flo) Dia rammer and E$6 Model Dia rammer* #ro"ide proHect mana ement capabilities includin maintenance mana ement $ impact analysis*

Ho)e"er0 each CASE tool supports a specific implementation of an SD(CM often in a "ery rid ed fashion* 566er C$S& Tools typically focus on the first B steps of the SD(C* Lo er C$S& Tools focus on steps ?$D and include code eneration capabilities* Integrated C$S& Tools co"er all of the steps* Examples/ .racle Desi ner 3inte rated4 Nisible Analyst 3upper4 IBM System Architect3formerly #op'in SA4 3inte rated4 More on CASE in the System Analysis classes*

Database $66lication Co%6onents

In prior classes0 )e discussed the "arious components of DBMS and databases* &e no) turn our attention to the applications that are used to access databases*

Data &ntry 0or%s

A primary means to enter data into a database and to edit existin data* Can also be used to 9uery 3Iuery By Example4* Data are typically arran ed in roups of related data items* Consider the tables )e created from last )ee'/ CUS!.ME6S CustomerJId0 %ame0 Street0 City0 State0 Kip ACC.U%!S CustomerJId0 AccountJ%umber0 AccountJ!ype0 DateJ.pened0 Balance A data entry form )ould ha"e fields that correspond to each of the database columns* For example0 a Customer data entry form )ould ha"e fields for/ CustomerJId0 %ame0 Street0 City0 State0 Kip

&ith Craphical User Interfaces0 more efficient data entry can be affected* CIC. o (ist boxes $ pro"ide a list of "alid "alues for a user to choose from* Example/ (ist of US States*
o o

6adio Buttons $ Exclusi"e list of options* Example/ Cender M2F Chec' Boxes $ %on$Exclusi"e list of options*

.ther options to constrain user input/

o o o

Con"ert input to all upper case or all lo)ercase 6estrict the number of di its entered Chec' for "alid numbers and other "alues

A typical database application )ill ha"e rou hly one form for each table* Also information$only forms 3Iuery$only4* %ot used for updatin or creatin ne) data*

Four main types of forms/

Sin le table 3bloc'4 form 3upper left4 Sin le table 3bloc'4 form )ith (oo'up 3lo)er left4 Master 2 Detail form 3upper ri ht4 Master 2 Detail )ith (oo'up 3lo)er ri ht4


Common Iueries to the database can be formed by the database desi ners* Sa"e 9ueries for specific purposes* User supplies criteria for the 9uery and e ecutes the 9uery a ainst the tables in the database*


#rimarily used to con"ey lar e portions of data in the database* .utput can be specially formatted for a "ariety of purposes such as printin mailin labels*

$66lications Code

Applications code is used to enforce business rules* For example/ No account should have a negative balance Applications Code/
IF (withdraw_amount > current_balance) THEN I!"#$%_E&&'&((In)u**icient Fund)() E#!E !ET current_balance + current_balance , withdraw_amount


Menus tie applications to ether* #ro"ide a con"enient )ay for users to access forms0 reports and 9ueries*

WWW $66lications

Users access database throu h a &&& Bro)ser* Data entry forms can be filled out and submitted to be sa"ed in the database*

6eports can be formatted and displayed as )eb pa es* Menus are simply lin's to different )eb pa es for for forms and reports* Ca"eat/ All applications Code typically resides on the &&& ser"er* MS Access -<> has tools to support/
o o

Exportin a report as an H!M( pa e Creatin Microsoft Acti"e Ser"er #a es 3AS#4 for data entry forms*

An example of a typical &&& data entry form tied to a bac' end database/

0or 'e8t Week

Chec' for formal assi nments Chapters to 6ead Connolly0 Be 0 Holo)c1a' Chapters D0 > and < Form your roups and con"er e on one or t)o ideas for the roup proHect*

&ntity Aelationshi6 /odeling

What You'll Learn This Week

Entity 6elationship Modelin o Set of E$6 modelin constructs

o o o o

Entities Attributes Identifiers 6elationships

E$6 Dia rams

o o o o o o o o o o

Nariation .ne $ Unified Modelin (anu a e Nariation !)o $ &hat the :roen'e boo' uses Nariation !hree $ Elmasri2%a"athe Boo' Nariation Four $ .racle Desi ner2,@@@ CASE Nariation Fi"e $ Nisible Analyst Nariation Six $ Sybase #o)erDesi ner !his is %.! an E$6 dia ramO Displayin Attributes &ea' Entities Subtype Entities &l%asri#'a(athe )*rd, ed+ -roenke ).th ed+, /c0adden )1th ed+, Chapters 5 and ? /ata2 Toledo # Cush%an Schaum-s .utlines Ch* >

Connolly, Begg, Holo c!ak


Chapters D and Chapter D >

Chapter 5 and ?

Chapters 5

&ntity Aelationshi6 /odeling

&ntity Aelationshi6 /odeling: A Set of constructs used to interpret0 specify and document lo ical data re9uirements for database processin systems* E$6 Models are Conceptual Models of the database* !hey can not be directly implemented in a database*

Many "ariations of E$6 Modelin used in practice* Mainly differences in notation0 symbols used to represent the ? main constructs*

&2A /odeling Constructs

&2A /odeling Constructs are/ Entity0 6elationship0 Attributes0 Identifiers It is important to et used to this terminolo y and to be able to use it at the appropriate time* For example0 in the E6 Model0 )e do not refer to tables* Here )e call them entities* &ntity: Some identifiable obHect rele"ant to the system bein built* Examples of Entities are/ EM#(.;EE CUS!.ME6 .6CA%IKA!I.% #A6! I%C6EDIE%! #U6CHASE .6DE6 CUS!.ME6 .6DE6 #6.DUC! An instance of an entity is li'e a specific example/ Bill Cates is an Employee of Microsoft S#AM is a #roduct Creenpeace is an .r ani1ation Flour is an in redient

$ttribute: A characteristic of an Entity* #roperties used to distin uish one entity instance from another* Attributes of entity EM#(.;EE mi ht include/ EmployeeID Social Security %umber First %ame (ast %ame Street Address City State KipCode Date Hired Health Benefits #lan Attributes of entity #6.DUC! mi ht include/ #roductID #roductJDescription &ei ht Si1e Cost

Exercise/ Come up )ith a list of attributes for each of the entities abo"e*

Identi7ier: A special attribute used to identify a specific instance of an entity* o !ypically )e loo' for uni!ue identifiers/
o o o

Social Security %umber uni9uely identifies an EM#(.;EE CustomerID uni9uely identifies a CUS!.ME6 &e can also use t)o attributes to indicate an identifier/ .6DE6J%UMBE6 and (I%EJI!EM uni9uely identify an item on an order*

Exercise/ Choose one of your attributes as the identifier for each of the entities abo"e*

Aelationshi6: An association bet)een t)o entities* o A CUS!.ME6 places a CUS!.ME6 .6DE6 An EM#(.;EE takes a CUS!.ME6 .6DE6 A S!UDE%! enrolls in a C.U6SE A C.U6SE is taught by a FACU(!; MEMBE6
o o o

6elationships are typically i"en names* A relationship can include one or more entities !he degree of a relationship is the number of Entities that participate in the relationship* 6elationships of de ree , are called binary relationships* Most relationships in databases are binary* 6elationship Cardinality refers to the number of entity instances in"ol"ed in the relationship* For example/ one CUS!.ME6 may place many CUS!.ME6 .6DE6S many S!UDE%!S may si n up for many C(ASSES one EM#(.;EE recei"es one #A;CHEC: one SA(ES#E6S.% is assi ned one C.M#A%;JCA6 ::' to ManyL

':/ LMany to ManyL ::: to .neL o Be)are of ::: relationships* !he t)o entities in"ol"ed mi ht be coalesced into one* Also called H$S2$ relationship*

Be)are of ':/ relationships* !ypically split these into t)o ::' relationships )ith an intersection entity* "articipation of instances in a relationship may be mandatory or optional*

For example0 one CUS!.ME6 may place many CUS!.ME6 .6DE6S one EM#(.;EE must fill out one or more #A; SHEE!S !his is also called Lminimal cardinalityL or the LoptionalityL of a relationship*

&2A Diagra%s

!he most common )ay to represent the E$6 constructs is by usin a dia ram !here are a )ide "ariety of notations for E$6 Dia rams* Most of the differences concern ho) relationships are specified and ho) attributes are sho)n* In almost all "ariations0 entities are depicted as rectan les )ith either pointed or rounded corners* !he entity name appears inside* 6elationships can be displayed as diamonds 3see belo)4 or can be simply line se ments bet)een t)o entities* For 6elationships0 need to con"ey/ 6elationship name0 de ree0 cardinality0 optionality 3minimal cardinality4 Here )e )ill i"e examples from se"eral "ariations/

Fariation Cne 2 5ni7ied /odeling Language

6elationship %ame/ Displayed alon the line De ree/ Sho)n by line se ments bet)een the entities* Cardinality/ Displayed alon the relationship line in the form/ min# ma Max Cardinality is typically $ or G .ptionality/ Mandatory participation indicated by min P + .ptional participation indicated by min P @

Fariation T o 2 What the -roenke book uses

6elationship %ame/ Displayed Hust outside of the relationship diamond* De ree/ Sho)n by line se ments bet)een the relationship diamond and , or more entities* Cardinality/ Displayed inside the relationship diamond* .ptionality/ Mandatory participation indicated by an intersectin hash mar' made perpendicular to the relationship line se ment* .ptional participation indicated by a = intersectin the relationship line se ment*

0or this diagra%:

An .6DE6 %ust be placed by one and only one CUS!.ME6* A CUS!.ME6 %ay place !ero or %ore .6DE6S* An .6DE6 %ay have !ero or %ore I!EMS* An I!EM %ust have one and only one .6DE6*

!hese are admittedly clumsy0 but you et the point*

Fariation Three 2 &l%asri#'a(athe Book

6elationship %ame/ Displayed Hust inside the relationship diamond* De ree/ Sho)n by line se ments bet)een the relationship diamond and , or more entities* Cardinality/ Displayed bet)een the participatin entity and the relationship diamond next to the relationship line* Split up the cardinality* .ptionality/ Mandatory participation indicated by double relationship line .ptional participation indicated by a sin le relationship line*

Fariation 0our 2 Cracle Designer C$S&

In .racle Corporation-s Desi ner CASE tool0 relationships are expressed in a ri id sentence format* For example/ An .6DE6 %ust be placed by one and only one CUS!.ME6* !he LbeL is mandatory ma'in the "erb difficult to et ri ht* 6elationship diamonds are not used*

6elationship %ames/ Are expressed as a "erb phrase startin )ith LbeL* !here are t)o phrases0 one for each direction of the relationship* !his phrase is then )ritten alon the line se ments for the relationship* De ree/ Sho)n by line se ments bet)een any t)o entities* As such0 5 )ay relationships as described in the :ron'e boo' can not exist* Cardinality/ Sin le participation 3L+L in the pre"ious example4 is indicated by a sin le line se ment* Multiple participation 3L%L4 is indicated by cro%&s feet .ptionality/ Mandatory participation is indicated by a solid relationship line se ment* .ptional participation is indicated by a dotted line se ment*

.ne .6DE6 %ust be placed by one and only one CUS!.ME6* .ne CUS!.ME6 %ay be placing !ero or %ore .6DE6S* .ne .6DE6 %ay be made up of !ero or %ore I!EMS* .ne I!EM %ust be an item on one and only one .6DE6*

!here are a set of tools that can print these Lrelationship sentencesL*

Fariation 0i(e 2 Fisible $nalyst

Nisible Analyst &or'bench 3NA&4 uses the rounded box to sho) an 'ttributive (ntity $ one that depends on the existence of a fundamental entity 3noted by Hust the rectan le4* !he relationships use the follo)in symbols/
o o o

For cardinality0 the cro)-s feet are used to sho) a LManyL side of a relationship* A sin le line sho) a L.neL side of the relationship* .ptional participation is sho)n )ith an open circle* !hus in the abo"e dia ram0 a Customer May place one or more .rders* Mandatory participation is sho)n )ith t)o hash mar's* !hus in the abo"e dia ram0 an .rder Must be placed by one and only one Customer*

Fariation Si8 2 Sybase "o erDesigner

This is not an &ntity Aelationshi6 Diagra%H

It is true/ !he L6elationshipsL screen in MS Access is %.! an Entity 6elationship dia rammin tool* !his is a LphysicalL le"el dia ram of ho) the tables are actually created*

Dis6laying $ttributes

!echnically0 an (ntity)*elationship dia ram should sho) only entities and their relationships* Consider/ (ntity)*elationship)'ttribute 3E6A4 model* !)o main )ays to display attributes associated )ith an entity* +* Attributes appear in o"als attached to the entity* Cets messy* ,* (ist attributes inside of the entity box*

UM( %otation/

.racle Desi ner CASE %otation/

Weak &ntities

Broad definition* Weak &ntity/ An entity that depends on another for its existence* Elmasri2%a"athe definition/ Weak entity/ Entity types that do not ha"e 'ey attributes of their o)n* ID De6endent &ntity/ A )ea' entity that includes the identifier of the related stron entity*

Examples of strong entities/ #eople0 Employees0 Customers0 Clients0 Nendors0 Students #roducts0 Ser"ices0 #arts0 6esources0 Materials Ban's Examples of ID Dependent entities/ Dependents 3of employees40 Ban' Branches 3of Ban's4* ID Dependent entities are sometimes sho)n )ith cur"ed boxes as in the Nisible Analyst E6 example* %ote that an I!EM can not exist by itself* It must be identified )ith a specific .rder*

!he Elmasri2%a"athe notation sho)s the ID Dependent entity )ith a double box* !he Lidentifyin relationshipL 3from the stron entity to the )ea' entity4 is sho)n )ith a double diamond* Final note/ ID Dependent entities )ill al)ays result in relations 3and later on tables4 )ith composite keys*

Subty6e &ntities

Attributes of t)o or more Entities may o"erlap si nificantly but not completely* Consider/ Full!imeEmployee3EmployeeID0%ame0Address0#hone0AnnualSalary0BenefitsCate ory4 #art!imeEmployee3EmployeeID0%ame0Address0#hone0Hourly6ate0MaxHours#er&ee'4 .ne approach )ould be to put all of the attributes into a sin le entity*

Second approach0 put common attributes into a parent or supertype entity and then ha"e t)o subtype entities* 6elationship is called an IS2$ relationship*

!he abo"e dia ram uses the UM( symbols for Supertype2Subtype*

Small E6 Case study example

What You'll Learn This Week

Con"ertin E$6 Model to 6elational Model o Entity to 6elation Con"ersion

o o o o

6epresentin 6elationships 6ecursi"e 6elationships !ernary 6elationships IS$A 6elationships

Common E$6 Structures

o o

!ree Structures %et)or' Structures $ Simple and Complex

For %ext &ee' "ratt#$da%ski Chapter D &l%asri#'a(athe )*rd, ed+ Chapter < -roenke ).th ed+, Chapter D /c0adden )1th ed+, Chapter D and Appendix B

Connolly, Begg, Holo c!ak Chapter +@

Con(erting )/a66ing, &2A /odel to Aelational /odel

E,& -odel ,> &elational -odel #re"iously0 )e co"ered modelin ,> ataba)e

the user-s "ie) as an E$6 dia ram* Entities0 6elationships0 Attributes and Identifiers* &e no) need to con"ert this conceptual representation to a model that can be implemented directly in a database* 6elational Model includes/ *elations# +uples# 'ttributes# keys and foreign keys,

Aelation/ A t)o dimensional table ma'e up of tuples 3!his is a simple definition that )e )ill define more ri orously in a later chapter4* Tu6le/ A ro) of data in a relation made up of one or more attributes* $ttribute/ A characteristic of the relation contained in a tuple*

o o

!he follo)in are some "ocabulary that are commonly used* %ote the different terms used dependin on the model bein discussed*

&A /odel Entity

Aelational /odel Database Traditional "rogra%%er 6elation !able 6o) Column :ey File 6ecord Field :ey 3or lin'4

Entity Instance !uple Attribute Identifier Attribute :ey

%ote/ !he terms in the left most column under &A /odel are not the four E6 modelin constructs*

&ntity to Aelation Con(ersion

For a maHority of E6 Models0 entities and )ea' entities con"ert easily into relations* &ntities $ In eneral0 each entity )ill be con"erted directly to a relation* !he attributes of the entity become the attributes of the 6elation* !he Identi7ier of the Entity becomes a -ey of the 6elation*

C5STC/&A 3CustomerID0 %ame0 Address0 #hone4 CAD&A 3.rder%umber0 .rderDate0 Sales#erson0 CustomerID 3f'44

Weak &ntities $ If a )ea' entity is not ID Dependent0 then treat it li'e any other entity $ Application must enforce referential integrity* If )ea' entity is ID Dependent0 then the parent relation-s 'ey 3Identifier4 is copied into the dependent relation* !his is often referred to as a Foreign Key*

CAD&A 3.rder%umber0 .rderDate0 Sales#erson4 CAD&AIT&/S 3.rder%umber0 Item%umber0 #art%um0 Iuantity0 #rice4 In the abo"e example0 in the I!EMS 6elation/ .rder%umber is the Foreign Key and .rder%umber plus Item%umber is the Composite Key* In the .6DE6 6elation/ .rder%umber is the Key*

Ae6resenting Aelationshi6s

::: 6elationships* !he 'ey or one relation is stored in the second relation* (oo' at example 9ueries to determine )hich 'ey is 9ueried most often* ::' 6elationships* "arent $ 6elation on the L+L side* Child $ 6elation on the LManyL side* 6epresent each Entity as a relation* Copy the 'ey of the parent into the child relation*

CUS!.ME6 3CustomerID0 %ame0 Address0 ***4 .6DE6 3.rder%umber0 .rderDate0 Sales#0 CustomerID4

/:' 6elationships* Many to Many relationships can not be directly implemented in relations* Solution/ Introduce a third Intersection relation and copy 'eys from ori inal t)o relations*

SU##(IE6 3SupplierID0 Firm%ame0 Address0 ***4 #6.DUC! 3#roductID0 Description0 ***4 #6.DUC!JSU##(IE6 3SupplierID0 #roductID4

%ote that this can also be sho)n in the E6 dia ram* Also0 loo' for potential added attributes in the intersection relation*

Aecursi(e Aelationshi6s

Consider assemblin an automobile $ a collection of basic parts are combined to ether to ma'e a complete car* In this case0 a part or component mi ht be made up of one or more other parts* !his forms a recursi"e ::' relationship*

&e can implement this directly by includin another copy of the 'ey in the relation* #A6! 3#artJID0 #arentJ#artJID0 Description4 Here are some example data/ "art9ID +@@@ ,@@ B@@ B+@ B,@ B5@ B?@ BB@ B+, B+? B+D B+= "arent9"art9ID null +@@@ +@@@ B@@ B@@ B@@ B@@ B@@ B+@ B+@ B+@ B+@ Descri6tion Complete Car En ine Body Doors Hood Iuarter #anels !run' 6oof Front #assen er Door Front Dri"er-s Door Bac' #assen er Door Bac' Dri"er-s Door etc*

!his forms a +ree structure/

.om/lete .ar En1ine 2od3 oor) Front "a))en1er 1000 200 400 410 412


Front ri5er6) oor 2ac7 "a))en1er oor 2ac7 ri5er6) oor Hood :uarter "anel) Trun7 &oo*

414 418 419 420 430 440 440

null P %o Nalue present .ther 'inds of recursi"e relationships/ ::: CUS!.ME6 is referred by one and only one other CUS!.ME6 ':/ S!UDE%! tutors one or more other S!UDE%!S $ Also0 that S!UDE%! can be tutored by one more other S!UDE%!S*

S!UDE%! 3StudentJID0 %ame0 Address0 ***4 !U!.6$I%!E6SEC!I.% 3StudentJID0 !utoredJbyJID4

Example Data/ S!UDE%! Student ID +@+ ,@, 5@5 ?@? 'a%e B* Smith $ddress +,5? Smith St*

A* Creen +, Crant St* D* Aones #* E)in <= Short St* <<< !all St*

!U!.6$I%!E6SEC!I.% Student ID Tutored by ID +@+ ?@? ,@, ,@,

,@, ?@?

5@5 5@5

Ternary Aelationshi6s

For most situations0 )e can treat a ternary relationship as se"eral binary relationships bet)een the entities* If )e can re$)rite the ternary relationship as se"eral binary relationships0 then the abo"e steps can be used to con"ert the entities into relations* Example/ .6DE60 CUS!.ME60 SA(ES#E6S.% becomes/ .6DE6 3.rderJ%umber0 .rderJDate0 CustomerJID0 SalespersonJId4 CUS!.ME6 3CustomerJID0 Contact0 Address***SalespersonJid4 SA(ES#E6S.% 3SalespersonJId0 %ame0 Department0 #hone4 Applications must control the assi nments of salesperson to customer and ensure this pair of IDs is represented properly in any .rders*

IS2$ Aelationshi6s

6ecall that some entities may ha"e subtypes associated )ith them*

Strate y is/ +* Con"ert the supertype entity directly into a relation usin only those attributes in the supertype $ note the 'ey* ,* Con"ert each of the subtype entities into relations $ also only )ith the attributes they contain* 5* Copy the 'ey for the supertype entity into each of the subtypes*

So our example becomes/ CA(( 3CallJIdentifier0 CustomerJId0 SourceJ%umber0 DestinationJ%umber0 !ime.fDay4 6ECU(A6JCA(( 3CallJIdentifier0 Duration4 (.%CJDIS!A%CE 3CallJIdentifier0 Duration0 (on DistanceCarrier4 CE((JCA(( 3CallJIdentifier0 AirJ!ime0 (andJ!ime4 CUS!.ME6 3CustomerJID0 %ame0 Address0 ***4

Co%%on &2A Structures

!here are many common structures you are li'ely to encounter* Some simple ones include/ Classic + to Many0 also called Master2Detail or #arent2Child/ #urchase .rder2Items Customer .rder2Items Class 6oster2Students Employee2Dependents #ortfolio2Stoc's Deli"ery Manifest2Items *** More complex structures include !rees0 Bill of Materials and %et)or's*

Tree Structures

Also called a -ierarchy A series of ::' relationships*

Each Node in the hierarchy has at most only one parent* Each "arent can ha"e 1ero0 one or more children* QCHI(D6E%Q IR)ith a common parent are called siblings* In a !ree structure0 each node has exactly one parent 3except for the top or root node* Example/ Boo's 3fiction 2 %on Fiction40 etc*

Another example/

!o con"ert a tree structure into a set of relations0 follo) the uidelines for con"ertin ::' relationships0 and repeat for each one*

'et ork Structure

!)o types/ Simple %et)or' and Complex %et)or' Si%6le 'et ork All relationships are ::'0 ho)e"er0 each node can ha"e more than one parent* Consider/

!o con"ert a simple net)or' into relations0 follo) the same rules for con"ertin ::' relationships* For an entity )ith t)o parents0 this means that there )ill be t)o forei n 'eys 3one from each parent4 copied in*

Co%6le8 'et ork (i'e simple net)or' only one of the relationships can be /:'* Consider the follo)in example/

(I%EJI!EM has t)o parents0 I%N.ICE and #A6!* !hese ha"e ::' relationships* !here is also a /:' relationship bet)een #A6! and SU##(IE6* !his ma'es it a Comple Net%ork* !o con"ert a complex net)or' into relations0 follo) the same uidelines i"en for simple net)or's* For the /:' relationship0 introduce an intersection relation as )e did before* I%N.ICE 3In"oiceJId0 In"oiceJDate0 DueJDate***4 (I%EJI!EM 3In"oiceJId0 #artJId0 (ineJ%umber0 Ity0 #rice***4 #A6! 3#artJId0 Description***4 SU##(IE6 3SupplierJId0 %ame0 Address0 ***4 SU##(IE6J#A6! 3SupplierJId0 #artJId4

What You'll Learn

!he 6elational Model Functional Dependencies :eys and Uni9ueness Modification Anomalies %ormali1ation
o o

First %ormal Form Second %ormal Form

o o o o o

!hird %ormal Form Boyce$Codd %ormal Form Fourth %ormal Form Fifth %ormal Form Domain2:ey %ormal Form

De$%ormali1ation All$In$.ne Example of normali1ation* For %ext &ee'

Ho77er, Business /ata2 "ratt#$da%sk Aob#Corone &l%asri#'a(ath -roenke "rescott I Database Toledo # i l )1th ed, e )*rd, ed+ ).th ed+, /c0adden Syste%s Cush%an )>th ed, Chapter +? and +B Chapter B Chapter B and Appendix B Shaum-s .utlines Ch* ? and B

Chapter = Chapter B

Chapter ?

The Aelational /odel

6ecall0 the 6elational Model consists of the elements/ relations0 )hich are made up of attributes* A relation is a set of columns 3attributes4 )ith "alues for each attribute such that/ +* Each attribute 3column4 "alue must be a sin le "alue only* ,* All "alues for a i"en attribute 3column 4 must be of the same type* 5* Each attribute 3column4 name must be uni9ue* ?* !he order of attributes 3columns4 is insi nificant B* %o t)o tuples 3ro)s4 in a relation can be identical* D* !he order of the tuples 3ro)s4 is insi nificant*

From our discussion of E$6 Modelin 0 )e 'no) that an Entity typically corresponds to a relation and that the Entity-s attributes become attributes of the relation* &e also discussed ho)0 dependin on the relationships bet)een entities0 copies of attributes 3the identifiers4 )ere placed in related relations as forei n 'eys*

!he process )e are follo)in is/ +* Cather user2business re9uirements* ,* De"elop the E$6 Model 3sho)n as an E$6 Dia ram4 based on the user2business re9uirements* 5* Con"ert the E$6 Model to a set of relations in the relational model ?* %ormali1e the relations to remo"e any anomalies 3SSS4* B* Implement the database by creatin a table for each normali1ed relation*

0unctional De6endencies

A Functional Dependency describes a relationship bet)een attributes in a sin le relation* An attribute is functionally dependant on another if )e can use the "alue of one attribute to determine the "alue of another* Example/ EmployeeJ%ame is functionally dependant on SocialJSecurityJ%umber because SocialJSecurityJ%umber can be used to uni9uely determine the "alue of EmployeeJ%ame* &e use the arro) symbol ,> to indicate a functional dependency* T ,> ; is read . functionally determines /
!tudent_I ,> !tudent_-a;or !tudent_I < .our)eNumber< !eme)ter ,> =rade !>? ,> .om/act_ i)7_Title< $rti)t -odel< '/tion)< Ta@ ,> .ar_"rice .our)e_Number< !ection ,> "ro*e))or< .la))room< Number'*!tudent) !he attributes listed on the left hand side of the ,> are called determinants* .ne can read $ ,> 2 as0 LA determines BL*

-eys and 5ni@ueness

-ey/ .ne or more attributes that uni9uely identify a tuple 3ro)4 in a relation* !he selection of 'eys )ill depend on the particular application bein considered* Users can offer some uidance as to )hat )ould ma'e an appropriate 'ey* Also this is pretty much an art as opposed to an exact science* 6ecall that no t)o relations should ha"e exactly the same "alues0 thus a candidate 'ey )ould consist of all of the attributes in a relation* A 'ey functionally determines a tuple 3ro)4* %ot all determinants are keys*

/odi7ication $no%alies

.nce our E$6 model has been con"erted into relations0 )e may find that some relations are not properly specified* !here can be a number of problems/ o Deletion $no%aly/ Deletin a relation results in some related information 3from another entity4 bein lost*

Insertion $no%aly/ Insertin a relation re9uires )e ha"e information from t)o or more entities $ this situation mi ht not be feasible*

Here is a 9uic' example/ A company has a #urchase order form/

.ur dutiful consultant creates the E$6 Model/

(I%EJI!EMS 3#.J%umber0 Item%um0 #art%um0 Description0 #rice0 Ity4 #.JHEADE6 3#.J%umber0 #.Date0 Nendor0 ShipJ!o0 ***4 Consider some sample data for the (I%EJI!EMS relation/ "C9'u%ber Ite%'u% "art'u% Descri6tion "rice 3ty .+@+ .+@+ .+@+ .+@, .+@, .+@5

I@+ I@, I@5 I@+ I@, I@+

#<< #<= #>> #<< #>> #55

#late Cup Bo)l #late Bo)l For'

G5*@@ > G+*@@ ++ G,*@@ D G5*@@ B G,*@@ B G,*B@ =

&hat are some of the problems )ith this relation F &hat happens )hen )e delete item , from .rder .+@+ F !hese problems occur because the relation in 9uestion contains data about , or more themes* !ypical )ay to sol"e these anomalies is to split the relation in to t)o or more relations $ #rocess called Normali0ation*

Consider the performance impact*


6elations can fall into one or more cate ories 3or classes4 called Normal Forms 'or%al 0or%/ A class of relations free from a certain set of modification anomalies* %ormal forms are i"en name such as/
o o o o o o o

First normal form 3+%F4 Second normal form 3,%F4 !hird normal form 35%F4 Boyce$Codd normal form 3BC%F4 Fourth normal form 3?%F4 Fifth normal form 3B%F4 Domain$:ey normal form 3D:2%F4

!hese forms are cumulati"e* A relation in !hird normal form is also in ,%F and +%F*

0irst 'or%al 0or% ):'0,

A relation is in first normal form if it meets the definition of a relation/ +* Each attribute 3column4 "alue must be a sin le "alue only* ,* All "alues for a i"en attribute 3column 4 must be of the same type* 5* Each attribute 3column4 name must be uni9ue* ?* !he order of attributes 3columns4 is insi nificant B* %o t)o tuples 3ro)s4 in a relation can be identical* D* !he order of the tuples 3ro)s4 is insi nificant*

If you ha"e a key defined for the relation0 then you can meet the uni!ue ro% re9uirement* Example relation in +%F/ S!.C:S 3Company0 Symbol0 Head9uarters0 Date0 CloseJ#rice4 Co%6any Sy%bol Microsoft MSF! Microsoft MSF! Head@uarters 6edmond0 &A 6edmond0 &A Date Close "rice

@<2@>2,@+@ ,5*<D @<2@=2,@+@ ,5*<5

Microsoft MSF! .racle .racle .racle .6C( .6C( .6C(

6edmond0 &A

@<2@<2,@+@ ,?*@+

6ed)ood Shores0 CA @<2@>2,@+@ ,?*,> 6ed)ood Shores0 CA @<2@=2,@+@ ,?*+? 6ed)ood Shores0 CA @<2@<2,@+@ ,?*55

Second 'or%al 0or% )J'0,

A relation is in second normal form 3,%F4 if all of its non$'ey attributes are dependent on all of the key* 6elations that ha"e a sin le attribute for a 'ey are automatically in ,%F* !his is one reason )hy )e often use artificial identifiers as 'eys* In the example belo)0 .lo)e "rice is dependent on .om/an3< !he follo)in example relation is not in ,%F/ S!.C:S 3Company0 Symbol0 Head9uarters0 Date0 CloseJ#rice4 Co%6any Sy%bol Microsoft MSF! Microsoft MSF! Microsoft MSF! .racle .racle .racle .6C( .6C( .6C( Head@uarters 6edmond0 &A 6edmond0 &A 6edmond0 &A Date Close "rice

and !3mbol<


@<2@>2,@+@ ,5*<D @<2@=2,@+@ ,5*<5 @<2@<2,@+@ ,?*@+

6ed)ood Shores0 CA @<2@>2,@+@ ,?*,> 6ed)ood Shores0 CA @<2@=2,@+@ ,?*+? 6ed)ood Shores0 CA @<2@<2,@+@ ,?*55

.om/an3< ate ,> .lo)e "rice !3mbol< ate ,> .lo)e "rice .om/an3 ,> !3mbol< HeadAuarter) !3mbol ,> .om/an3< HeadAuarter)

Consider that .om/an3< ate ,> .lo)e "rice* So )e mi ht use Company0 Date as our 'ey* Ho)e"er/ .om/an3 ,> HeadAuarter) !his "iolates the rule for ,%F* Also0 consider the insertion and deletion anomalies* Cne Solution: Split this up into t)o relations/ C.M#A%; 3Company0 Symbol0 Head9uarters4 S!.C:S 3Symbol0 Date0 CloseJ#rice4 Co%6any Sy%bol Head@uarters

Microsoft MSF! .racle

6edmond0 &A 6ed)ood Shores0 CA


.om/an3 ,> !3mbol< HeadAuarter) !3mbol ,> .om/an3< HeadAuarter)

Sy%bol MSF! MSF! MSF! .6C( .6C( .6C(



Close "rice

@<2@>2,@+@ ,5*<D @<2@=2,@+@ ,5*<5 @<2@<2,@+@ ,?*@+ @<2@>2,@+@ ,?*,> @<2@=2,@+@ ,?*+? @<2@<2,@+@ ,?*55
ate ,> .lo)e "rice

Third 'or%al 0or% )*'0,

A relation is in third normal form 35%F4 if it is in second normal form and it contains no transitive dependencies* Consider relation 6 containin attributes A0 B and C* If $ ,> 2 and 2 ,> . then $ ,> . Transiti(e De6endency/ !hree attributes )ith the abo"e dependencies* Example/ At CU%;/
.our)e_.ode ,> .our)e_Num< !ection .our)e_Num< !ection ,> .la))room< "ro*e))or

Consider one of the ne) relations )e created in the abo"e example for ,nd normal form/ Co%6any Sy%bol Microsoft MSF! .racle .6C( Head@uarters 6edmond0 &A 6ed)ood Shores0 CA

.om/an3 ,> !3mbol !3mbol ,> HeadAuarter) )o there*oreB .om/an3 ,> HeadAuarter)

&hat happens if )e remo"e .racle F &e loose information about , different themes* Split this up into t)o relations/

Co%6any Sy%bol Microsoft MSF! .racle

.6C( Head@uarters 6edmond0 &A 6ed)ood Shores0 CA


.om/an3 ,> !3mbol

Sy%bol MSF! .6C(

!3mbol ,>

Boyce2Codd 'or%al 0or% )BC'0,

A relation is in BC%F if e"ery determinant is a candidate 'ey* 6ecall that not all determinants are 'eys* !hose determinants that are 'eys )e initially call candidate keys* E"entually0 )e select a sin le candidate 'ey to be the primary key for the relation* Consider the follo)in example/ Funds consist of one or more In"estment !ypes* Funds are mana ed by one or more Mana ers In"estment !ypes can ha"e one more Mana ers Mana ers only mana e one type of in"estment* 0undID In(est%entTy6e /anager << << 55 ,, ++ Common Stoc' Common Stoc' Cro)th Stoc's Common Stoc' Smith Creen Bro)n Smith Municipal Bonds Aones

FundI < In5e)tmentT3/e ,> -ana1er FundI < -ana1er ,> In5e)tmentT3/e -ana1er ,> In5e)tmentT3/e

In this case0 the combination FundID and In"estment!ype form a candidate key because )e can use FundID0In"estment!ype to uni9uely identify a tuple in the relation* Similarly0 the combination FundID and Mana er also form a candidate key because )e can use FundID0 Mana er to uni9uely identify a tuple* Mana er by itself is not a candidate 'ey because )e cannot use Mana er alone to uni9uely identify a tuple in the relation*

Is this relation 63FundID0 In"estment!ype0 Mana er4 in +%F0 ,%F or 5%F F Ci"en )e pic' FundID0 In"estment!ype as the "rimary Key1 +%F for sure* ,%F because all of the non$'ey attributes 3Mana er4 is dependant on all of the 'ey* 5%F because there are no transiti"e dependencies* Consider )hat happens if )e delete the tuple )ith FundID ,,* &e loose the fact that Bro)n mana es the In"estment!ype LCro)th Stoc's*L !he follo)in are steps to normali1e a relation into BC%F/ +* (ist all of the determinants* ,* See if each determinant can act as a 'ey 3candidate 'eys4* 5* For any determinant that is not a candidate 'ey0 create a ne) relation from the functional dependency* 6etain the determinant in the ori inal relation*

For our example/ 6ori 3FundID0 In"estment!ype0 Mana er4

1. !he determinants are/
FundI < In5e)tmentT3/e FundI < -ana1er -ana1er

2. &hich determinants can act as 'eys F

FundI < In5e)tmentT3/e FundI < -ana1er /(S -ana1er NO


5* Create a ne) relation from the functional dependency/ 6ne)3Mana er0 In"estment!ype4 6ori 3FundID0 Mana er4 In this last step0 )e ha"e retained the determinant LMana erL in the ori inal relation 6ori *

0ourth 'or%al 0or% )<'0,

A relation is in fourth normal form if it is in BC%F and it contains no multivalued dependencies* /ulti(alued De6endency/ A type of functional dependency )here the determinant can determine more than one "alue* More formally0 there are 5 criteria/ +* !here must be at least 5 attributes in the relation* call them A0 B0 and C0 for example*

,* Ci"en A0 one can determine multiple "alues of B* Ci"en A0 one can determine multiple "alues of C* 5* B and C are independent of one another*

Boo' example/ Student has one or more maHors* Student participates in one or more acti"ities* StudentID +@@ +@@ +@@ +@@ ,@@ /aDor CIS CIS Accountin Accountin Mar'etin $cti(ities Baseball Nolleyball Baseball Nolleyball S)immin

!tudentI !tudentI

,>,> -a;or ,>,> $cti5itie)

"ort7olio ID <<< <<< <<< <<< ===

Stock 0und Aanus Fund Aanus Fund Municipal Bonds

Bond 0und Dreyfus Short$Intermediate Municipal Bond Fund

Scudder Clobal Fund Municipal Bonds Scudder Clobal Fund Dreyfus Short$Intermediate Municipal Bond Fund :aufmann Fund !* 6o)e #rice Emer in Mar'ets Bond Fund

A fe) characteristics/ +* %o re ular functional dependencies ,* All three attributes ta'en to ether form the 'ey* 5* (atter t)o attributes are independent of one another* ?* Insertion anomaly/ Cannot add a stoc' fund )ithout addin a bond fund 3%U(( Nalue4* Must al)ays maintain the combinations to preser"e the meanin *

Stoc' Fund and Bond Fund form a multi"alued dependency on #ortfolio ID*
"ort*olioI "ort*olioI ,>,> ,>,> !toc7 Fund 2ond Fund

6esolution/ Split into t)o tables )ith the common 'ey/

"ort7olio ID <<< <<< === "ort7olio ID <<< <<< ===

Stock 0und Aanus Fund Scudder Clobal Fund :aufmann Fund Bond 0und Municipal Bonds Dreyfus Short$Intermediate Municipal Bond Fund !* 6o)e #rice Emer in Mar'ets Bond Fund

0i7th 'or%al 0or% )1'0,

!here are certain conditions under )hich after decomposin a relation0 it cannot be reassembled bac' into its ori inal form* &e don-t consider these issues here*

Do%ain -ey 'or%al 0or% )D-#'0,

A relation is in D:2%F if e"ery constraint on the relation is a lo ical conse9uence of the definition of keys and domains* Constraint: An rule o"ernin static "alues of an attribute such that )e can determine if this constraint is !rue or False* Examples/ +* Functional Dependencies ,* Multi"alued Dependencies 5* Inter$relation rules ?* Intra$relation rules Ho)e"er/ Does Not include time dependent constraints*

-ey: Uni9ue identifier of a tuple* Do%ain: !he physical 3data type0 si1e0 %U(( "alues4 and semantic 3lo ical4 description of )hat "alues an attribute can hold* !here is no 'no)n al orithm for con"ertin a relation directly into D:2%F*


Consider the follo)in relation/ CUS!.ME6 3CustomerID0 %ame0 Address0 City0 State0 Kip4

!his relation is not in D:2%F because it contains a functional dependency not implied by the 'ey*
Ci/ ,> .it3< !tate

&e can normali1e this into D:2%F by splittin the CUS!.ME6 relation into t)o/ CUS!.ME6 3CustomerID0 %ame0 Address0 Kip4 C.DES 3Kip0 City0 State4 &e may pay a performance penalty $ each customer address loo'up re9uires )e loo' in t)o relations 3tables4* In such cases0 )e may de)normali0e the relations to achie"e a performance impro"ement*

$ll2in2Cne &8a%6le
Many of you as'ed for a LcompleteL example that )ould run throu h all of the normal forms from be innin to end usin the same tables* !his is tou h to do0 but here is an attempt/ Example relation/ EM#(.;EE 3 %ame0 #roHect0 !as'0 .ffice0 #hone 4 %ote/ :eys are underlined* Example Data/ 'a%e "roDect Task C77ice 0loor "hone Bill Bill Bill Bill Sue Sue Sue Ed

+@@T +@@T ,@@; ,@@; +@@T ,@@; 5@@K +@@T

!+ !, !+ !, !55 !55 !55 !,

?@@ ?@@ ?@@ ?@@ ??, ??, ??, B==

? ? ? ? ? ? ? B

+?@@ +?@@ +?@@ +?@@ +??, +??, +??, +B==

'a%e is the employee-s name "roDect is the proHect they are )or'in on* Bill is )or'in on t)o different proHects0 Sue is )or'in on 5*

Task is the current tas' bein )or'ed on* Bill is no) )or'in on !as's !+ and !,* %ote that !as's are independent of the proHect* Examples of a tas' mi ht be faxin a memo or holdin a meetin * C77ice is the office number for the employee* Bill )or's in office number ?@@* 0loor is the floor on )hich the office is located* "hone is the phone extension* %ote this is associated )ith the phone in the i"en office*

0irst 'or%al 0or%

Assume the key is %ame0 #roHect0 !as'* Is EM#(.;EE in +%F F

Second 'or%al 0or%

(ist all of the functional dependencies for EM#(.;EE* Are all of the non$'ey attributes dependant on all of the 'ey F Split into t)o relations EM#(.;EEJ#6.AEC!J!AS: and EM#(.;EEJ.FFICEJ#H.%E* EM#(.;EEJ#6.AEC!J!AS: 3%ame0 #roHect0 !as'4 'a%e "roDect Task Bill Bill Bill Bill Sue Sue Sue Ed +@@T +@@T ,@@; ,@@; +@@T ,@@; 5@@K +@@T !+ !, !+ !, !55 !55 !55 !,

EM#(.;EEJ.FFICEJ#H.%E 3%ame0 .ffice0 Floor0 #hone4 'a%e C77ice 0loor "hone Bill Sue Ed ?@@ ??, B== ? ? B +?@@ +??, +B==

Third 'or%al 0or%

Assume each office has exactly one phone number* Are there any transiti"e dependencies F &here are the modification anomalies in EM#(.;EEJ.FFICEJ#H.%E F Split EM#(.;EEJ.FFICEJ#H.%E* EM#(.;EEJ#6.AEC!J!AS: 3%ame0 #roHect0 !as'4 'a%e "roDect Task Bill Bill Bill Bill Sue Sue Sue Ed +@@T +@@T ,@@; ,@@; +@@T ,@@; 5@@K +@@T !+ !, !+ !, !55 !55 !55 !,

EM#(.;EEJ.FFICE 3%ame0 .ffice0 Floor4 'a%e C77ice 0loor Bill Sue Ed ?@@ ??, B== ? ? B

EM#(.;EEJ#H.%E 3.ffice0 #hone4 C77ice "hone ?@@ ??, B== +?@@ +??, +B==

Boyce2Codd 'or%al 0or%

(ist all of the functional dependencies for EM#(.;EEJ#6.AEC!J!AS:0 EM#(.;EEJ.FFICE and EM#(.;EEJ#H.%E* (oo' at the determinants* Are all determinants candidate 'eys F

0orth 'or%al 0or%

Are there any multi"alued dependencies F &hat are the modification anomalies F Split EM#(.;EEJ#6.AEC!J!AS:* EM#(.;EEJ#6.AEC! 3%ame0 #roHect 4 'a%e "roDect Bill Bill Sue Sue Sue Ed +@@T ,@@; +@@T ,@@; 5@@K +@@T

EM#(.;EEJ!AS: 3%ame0 !as' 4 'a%e Task Bill Bill Sue Ed !+ !, !55 !,

EM#(.;EEJ.FFICE 3%ame0 .ffice0 Floor4 'a%e C77ice 0loor Bill Sue Ed ?@@ ??, B== ? ? B

6? 3.ffice0 #hone4

C77ice "hone ?@@ ??, B== +?@@ +??, +B==

At each step of the process0 )e did the follo)in / +* &rite out the relation ,* 3optionally4 &rite out some example data* 5* &rite out all of the functional dependencies ?* Startin )ith +%F0 o throu h each normal form and state )hy the relation is in the i"en normal form*

$nother short e8a%6le

Consider the follo)in example of normali1ation for a CUS!.ME6 relation* Aelation 'a%e CUS!.ME6 3CustomerID0 %ame0 Street0 City0 State0 Kip0 #hone4 &8a%6le Data Custo%erID C+@+ C+@, 'a%e Bill Smith Street City State %A Bi6 "hone

+,5 First St* %e) Bruns)ic' %A

@>+@+ >5,$BBB$+,+, @>@DD <@=$BBB$+,+,

Mary Creen ++ Birch St* .ld Brid e

0unctional De6endencies
.u)tomerI ,> Name< !treet< .it3< !tate< Ci/< "hone Ci/ ,> .it3< !tate


:'0 Meets the definition of a relation* J'0 All non 'ey attributes are dependent on all of the 'ey* *'0 6elation CUS!.ME6 is not in 5%F because there is a transiti"e dependency* CustomerID $R Kip and Kip $R City0 State * Solution/ Split CUS!.ME6 into t)o relations/ CUS!.ME6 3CustomerID0 %ame0 Street0 Kip0 #hone4 KI#C.DES 3Kip0 City0 State4

Chec' both CUS!.ME6 and KI#C.DE to ensure they are both in +%F up to BC%F* As a final step0 consider de$normali1ation*

Aelational $lgebra
What You'll Learn This Week

6elational Al ebra o Set !heoretic .perations

o o o o

Union0 Intersection and Difference Union Compatible 6elations Cartesian #roduct Selection and #roHection

Selection .perator Selection Examples #roHection .perator #roHection Examples Combinin Selection and #roHection

o o

re ate Functions

Aoin .perations

Aoin Examples %atural Aoin .uter Aoin

.uter Union

Ho) to ma'e 6elational Al ebra Symbols in MS &ord

Aelational $lgebra
&l%asri#'a(athe -roenke Connolly#Begg Aob#Coronel Ho77er, /ata2

)* , ed+


).th ed+,

)* &d+,


)1 ed,


"rescott I /c0adden )>th ed+, %2A

Toledo # Cush%an Shaum-s .utlines Ch* ,

Chapter >

Chapter =

Chapter ?


6ecall0 the 6elational Model consists of the elements/ relations0 )hich are made up of attributes* A relation is a set of attributes )ith "alues for each attribute such that/ +* Each attribute "alue must be a sin le "alue only 3atomic4* ,* All "alues for a i"en attribute must be of the same type 3or domain4* 5* Each attribute name must be uni9ue* ?* !he order of attributes is insi nificant B* %o t)o ro)s 3tuples4 in a relation can be identical* D* !he order of the ro)s 3tuples4 is insi nificant*

6elational Al ebra is a collection of operations on 6elations* 6elations are operands and the result of an operation is another relation* !)o main collections of relational operators/ +* Set theory operations/ Union0 Intersection0 Difference and Cartesian product* ,* Specific 6elational .perations/ Selection0 #roHection0 Aoin0 Di"ision

Set Theoretic C6erations

Consider the follo)in relations A and S A 0irst Last $ge Bill Smith ,, Sally Creen ,= Mary :een ,5 !ony Aones 5, S

0irst Forrest Sally

Last Cump Creen

$ge 5D ,=

DonAuan DeMarco ,> Union/ 6 S 6esult/ 6elation )ith tuples from 6 and S )ith duplicates remo"ed* Difference/ 6 , S 6esult/ 6elation )ith tuples from 6 but not from S Intersection/ 6 S 6esult/ 6elation )ith tuples that appear in both 6 and S* S Last Smith Creen :een Aones Cump $ge ,, ,= ,5 5, 5D

0irst Bill Sally Mary !ony Forrest

DonAuan DeMarco ,> A-S 0irst Last $ge Bill Smith ,, Mary :een ,5 !ony Aones 5, A S

0irst Last $ge Sally Creen ,=

5nion Co%6atible Aelations

Attributes of relations need not be identical to perform union0 intersection and difference operations* Ho)e"er0 they must ha"e the same number of attributes or arity and the domains for correspondin attributes must be identical* Do%ain is the datatype and si1e of an attribute* !he degree of relation 6 is the number of attributes it contains* Definition/ !)o relations 6 and S are union compatible if and only if they ha"e the same de ree and the domains of the correspondin attributes are the same* Some additional properties/

Union0 Intersection and difference operators may only be applied to Union Compatible relations* Union and Intersection are commutati"e operations 6 SPS 6 6 SPS 6 Difference operation is %.! commutati"e* 6 $ S not e9ual S $ 6 !he resultin relations may not ha"e meanin ful names for the attributes* Con"ention is to use the attribute names from the first relation*


Assume relation T 7'a%e Sally Mary l'a%e Creen Score ?? ,= &illiam Smith

:ontrary ,>

Compute 6 ! Compute 6 ! Sho) that 6 $ ! is not e9ual to ! $ 6

Cartesian "roduct

#roduce all combinations of tuples from t)o relations* A

0irst Last $ge Bill Smith ,, Mary :een ,5 !ony Aones 5, S Dinner Stea' Dessert Ice Cream

(obster Cheeseca'e AKS 0irst Last $ge Dinner Bill Bill Smith ,, Smith ,, Stea' Stea' Stea' Dessert Ice Cream Ice Cream Ice Cream

(obster Cheeseca'e (obster Cheeseca'e (obster Cheeseca'e

Mary :een ,5 Mary :een ,5 !ony Aones 5, !ony Aones 5,

Selection C6erator

Selection and #roHection are unary operators* !he selection operator is si ma/ !he selection operation acts li'e a filter on a relation by returnin only a certain number of tuples* !he resultin relation )ill ha"e the same de ree as the ori inal relation* !he resultin relation may ha"e fe)er tuples than the ori inal relation* !he tuples to be returned are dependent on a condition that is part of the selection operator*
. (&)

6eturns only those tuples in 6 that satisfy condition C

A condition C can be made up of any combination of comparison or lo ical operators that operate on the attributes of 6*
o o

Comparison operators/ (o ical operators/

Use the !ruth tables 3memori1e these4 for lo ical expressions/

T T 0 ! F

0 F F T 0

T ! !

0 T ! F F ! 0

Selection &8a%6les
Assume the follo)in relation EM# has the follo)in tuples/ 'a%e Smith Aones Creen C77ice De6t ?@@ ,,@ +D@ CS Aank Assistant

Econ AdHunct Econ Assistant CS Fin Associate Associate

Bro)n ?,@ Smith


Select only those Employees in the CS department/ Dept P -CS- 3EM#4 6esult/ 'a%e Smith C77ice De6t ?@@ CS CS Aank Assistant Associate 3EM#4

Bro)n ?,@

Select only those Employees )ith last name Smith )ho are assistant professors/
%ame P -Smith6an' P -Assistant-


'a%e C77ice De6t Smith

Aank Assistant



Select only those Employees )ho are either Assistant #rofessors or in the Economics department/
6an' P -AssistantDept P -Econ-


6esult/ 'a%e C77ice De6t Smith Aones Creen

Aank Assistant

?@@ ,,@ +D@


Econ AdHunct Econ Assistant 3EM#4

Select only those Employees )ho are not in the CS department or AdHuncts/
36an' P -AdHunctDept P -CS-4

6esult/ 'a%e C77ice De6t Creen Smith +D@ B@@ Aank

Econ Assistant Fin Associate


E"aluate the follo)in expressions/ +* ,* 5* ?* B*

36an' P -AdHunctDept P -CS-4


6an' P -Associate-

Dept P -CS-

EM# 4 EM# 4 3EM#4

Dept P -CS-

6an' P -Associate-

6an' P -Associate-

Dept P -CS-

A e R ,D



For this expression0 use 6 and S from the Set !heoretic .perations section abo"e*

Do expressions ,0 5 and ? abo"e all e"aluate ot the same thin F

"roDection C6erator

#roHection is also a Unary operator* !he #roHection operator is pi/ #roHection limits the attributes that )ill be returned from the ori inal relation* !he eneral syntax is/ attributes 6 &here attributes is the list of attributes to be displayed and 6 is the relation* !he resultin relation )ill ha"e the same number of tuples as the ori inal relation 3unless there are duplicate tuples produced4* !he de ree of the resultin relation may be e9ual to or less than that of the ori inal relation*

"roDection &8a%6les
Assume the same EM# relation abo"e is used* #roHect only the names and departments of the employees/ name0 dept 3EM#4 6esults/ 'a%e Smith Aones Creen De6t CS Econ Econ

Bro)n CS Smith Fin

Co%bining Selection and "roDection

!he selection and proHection operators can be combined to perform both operations* Sho) the names of all employees )or'in in the CS department/ name 3 Dept P -CS- 3EM#4 4 6esults/ 'a%e Smith Bro)n

Sho) the name and ran' of those Employees )ho are not in the CS department or AdHuncts/
name0 ran'

36an' P -AdHunct-

Dept P -CS-4

3EM#4 4

6esult/ 'a%e Creen Smith Aank Assistant Associate


E"aluate the follo)in expressions/ +* ,*

name0 ran'

3 3

36an' P -AdHunct-

Dept P -CS-4

3EM#4 4

fname0 a e

A e R ,,


S4 4

For this expression0 use 6 and S from the Set !heoretic .perations section abo"e* 5*
office R 5@@

name0 ran'


$ggregate 0unctions

&e can also apply 'ggregate functions to attributes and tuples/ o SUM
o o o o


A re ate functions are sometimes )ritten usin the "ro2ection operator or the Script F character/ as in the Elmasri2%a"athe boo'*

$ggregate 0unction &8a%6les

Assume the relation EM# has the follo)in tuples/ 'a%e C77ice De6t Salary

Smith Aones Creen

?@@ ,,@ +D@



Econ 5B@@@ Econ B@@@@ CS Fin DB@@@ D@@@@

MI% 3salary4

Bro)n ?,@ Smith


Find the minimum Salary/ 6esults/ /I')salary, 5B@@@


Find the a"era e Salary/ 6esults/ $FE)salary, B+@@@

ANC 3salary4


Count the number of employees in the CS department/ 6esults/ CC5'T)na%e, ,

C.U%! 3name4

Dept P -CS-

3EM#4 4

Find the total payroll for the Economics department/ 6esults/ S5/)salary, =B@@@

SUM 3salary4

Dept P -Econ-

3EM#4 4

Loin C6eration

Aoin operations brin to ether t)o relations and combine their attributes and tuples in a specific fashion* !he eneric Hoin operator 3called the +heta 3oin is/ It ta'es as ar uments the attributes from the t)o relations that are to be Hoined*

For example assume )e ha"e the EM# relation as abo"e and a separate DE#A6! relation )ith 3Dept0 Main.ffice0 #hone4 / EM#
EM#*Dept P DE#A6!*Dept


!he Hoin condition can be &hen the Hoin condition operator is M then )e call this an (!ui2oin %ote that the attributes in common are repeated*

Loin &8a%6les
Assume )e ha"e the EM# relation from abo"e and the follo)in DE#A6! relation/ De6t CS /ainC77ice ?@? "hone BBB$+,+, BBB$+,5? BBB$?5,+ BBB$<=>D DE#A6! D&"$AT+De6t /ainC77ice CS Econ Econ CS Fin ?@? ,@@ ,@@ ?@? B@+ "hone BBB$+,+, BBB$+,5? BBB$+,5? BBB$+,+, BBB$?5,+

Econ ,@@ Fin Hist

B@+ +@@ EM# 6esults/ 'a%e Smith Aones Creen

Find all information on e"ery employee includin their department info/

emp*Dept P depart*Dept

C77ice &/"+De6t Salary ?@@ ,,@ +D@ CS Econ Econ CS Fin ?B@@@ 5B@@@ B@@@@ DB@@@ D@@@@

Bro)n ?,@ Smith


Find all information on e"ery employee includin their department info )here the employee )or's in an office numbered less than the department main office/ EM# 6esults/
3emp*office Q depart*mainoffice4 3emp*dept P depart*dept4


'a%e C77ice &/"+De6t Salary Smith ?@@ CS ?B@@@

D&"$AT+De6t /ainC77ice CS ?@?

"hone BBB$+,+,

Creen Smith

+D@ B@@

Econ Fin

B@@@@ D@@@@

Econ Fin

,@@ B@+

BBB$+,5? BBB$?5,+

'atural Loin

%otice in the eneric 3!heta4 Hoin operation0 any attributes in common 3such as de/t abo"e4 are repeated* !he Natural 3oin operation remo"es these duplicate attributes* !he natural Hoin operator is/ G &e can also assume usin G that the Hoin condition )ill be M on the t)o attributes in common* Example/ EM# G DE#A6! 6esults/ 'a%e Smith Aones Creen C77ice De6t Salary ?@@ ,,@ +D@ CS ?B@@@ /ainC77ice ?@? ,@@ ,@@ ?@? B@+ "hone BBB$+,+, BBB$+,5? BBB$+,5? BBB$+,+, BBB$?5,+

Econ 5B@@@ Econ B@@@@ CS Fin DB@@@ D@@@@

Bro)n ?,@ Smith B@@

Cuter Loin

In the Aoin operations so far0 only those tuples from both relations that satisfy the Hoin condition are included in the output relation* !he Outer 2oin includes other tuples as )ell accordin to a fe) rules* !hree types of outer Hoins/ +* (eft .uter Aoin includes all tuples in the left hand relation and includes only those matchin tuples from the ri ht hand relation* ,* 6i ht .uter Aoin includes all tuples in the ri ht hand relation and includes ony those matchin tuples from the left hand relation* 5* Full .uter Aoin hand relation* includes all tuples in the left hand relation and from the ri ht


Assume )e ha"e t)o relations/ #E.#(E and ME%U/ #E.#(E/ 'a%e $ge Alice Bill Carl Dina ,+ ,? ,5 +< 0ood Hambur er #i11a Beer Shrimp ME%U/ 0ood #i11a Day Monday

Hambur er !uesday Chic'en #asta !acos &ednesday !hursday Friday


people*food P menu*food

ME%U Day !uesday Monday N455 N455

'a%e $ge 6eo6le+0ood %enu+0ood Alice Bill Carl Dina

,+ ,? ,5 +<

Hambur er #i11a Beer Shrimp

people*food P menu*food

Hambur er #i11a N455 N455 ME%U

#E.#(E 'a%e Bill Alice $ge ,? ,+

6eo6le+0ood %enu+0ood #i11a Hambur er #i11a Hambur er Chic'en #asta !acos ME%U

Day Monday !uesday &ednesday !hursday Friday

N455 N455 N455 N455 N455 N455 N455 N455 N455

#E.#(E 'a%e Alice $ge ,+

people*food P menu*food

6eo6le+0ood %enu+0ood Hambur er Hambur er

Day !uesday

Bill Carl Dina

,? ,5 +<

#i11a Beer Shrimp

#i11a N455 N455 Chic'en #asta !acos

Monday N455 N455 &ednesday !hursday Friday

N455 N455 N455 N455 N455 N455 N455 N455 N455

Cuter 5nion

!he .uter Union operation is applied to partially union compatible relations* .perator is/ G Example/ #E.#(E 'a%e Alice Bill Carl Dina $ge ,+ ,? ,5 +< G ME%U 0ood Day

Hambur er N455 #i11a Beer Shrimp N455 N455 N455

N455 N455 Hambur er Monday N455 N455 #i11a N455 N455 Chic'en N455 N455 #asta N455 N455 !acos !uesday &ednesday !hursday Friday

Ho to %ake Aelational $lgebra Sy%bols in /S Word

&hen doin home)or' assi nments and proHects0 it is "ery helpful to be able to type these relational al ebra symbols into MS &ord or other )or' processor* Since )e mainly use MS &ord or another )ord processor runnin in Microsoft &indo)s0 )e demonstrate them here* Most of the relational al ebra symbols can be produced usin the LSymbolL font* .ne )ay to do this is to use the !3mbol choice on the In)ert menu in MS &ord* !his is sho)n belo)/

!he follo)in dialo box )ill appear/

By default0 the symbols displayed on this screen )ill use the Symbol font* Some symbols such as Hoin and outer Hoin are not a"ailable in this fashion* For these you can copy and paste the raphics in the MS &ord file lin'ed here* All of the relational al ebra symbols are included*

Ae(ie 7or Test :

Your 7irst test ill be held on Thursday Cctober >, J=:: in our regular classroo% at the regular class ti%e 6eriod+

/id Ter% &8a% ill co(er

E"erythin in class up until and includin materials co"ered on the last class before the test* Chapters in Business Database Systems/ +0 ,0 ?0 D0 >0 =0 <0 +@ Exam is closed boo'0 closed notes* All you need to brin is yourself0 a pen and a pencil* %o calculators0 dictionaries0 cell phones0 i#ads0 supercomputers0 scrap paper0 etc* )ill be permitted* #lease arri"e to class at least +@ minutes early so that you can et settled in and be ready for the exam to be in promptly at ,/5@* Materials that )ill %.! be co"ered/ +* MS Access materials

7 For your re"ie)0 )e ha"e co"ered/ To6ic Introduction to databases includin / &hat is a database &hat is a DBMS &hat is contained in a Database System Difference bet)een a file system and a database Brief history of file systems and databases Intro to the Database modelin and desi n process0 etc* Week )notes, Book Cha6ters

Course Introduction %otes*

BDS/ + and ,

Systems analysis and Desi n includin the SD(C and the use of CASE tools* Applications components includin forms0 reports0 Systems Analysis 9ueries0 menus* %otes* Also interface desi n elements* Characteristics of Database Applications* Entity 6elationship Modelin includin E$6 constructs 3Entity0 Attributes0 Identifiers and 6elationships "arious 'inds of relationships includin subtypes and supertypes* Cardinality and de ree of relationships E$6 and the 6elational Model* Includes con"ertin "arious E$6 model constructs to 6elational Models* Con"ersion of )ea' 3ID Dependent4 entities E6 Modelin %otes*

BDS/ ? and <

BDS/ D0 > and <

Con"ertin E6 to 6elations %otes*

BDS/ +@

Con"ersion of "arious relationship types Con"ersion of 6ecursi"e relationships 3relationships of de ree +4 Common E$6 modelin structures* E$6 Model and %ormali1ation* Definition of a 6elation 3D thin s4 #urpose of normali1ation Definin Functional Dependencies Definin 'eys and uni9ueness +%F0 ,%F0 and 5%F* Definitions of normal forms and ho) to con"ert relations*

%ormali1ation notes*

BDS/ =


%o ma'eups )ill be i"en for missed 9ui11es or exams* !he instructor retains all midterm and final exams* Crades )ill not be i"en out "ia e$mail*

File1 test$,htm Date1 $$167 'M 789:89:$$ All materials Copyri ht0 +<<>$,@++ 6ichard Holo)c1a'

Database /anage%ent Syste%s 0unctions

What You'll Learn This Week

!ransaction #rocessin Concurrency Control and (oc'in

o o o

Characteristics of (oc's !)o #hase (oc'in Deadloc'

Database 6eco"ery and Bac'up

o o o

6eprocessin 6ollbac' 2 6ollfor)ard Database Bac'up

For %ext &ee'

Connolly, Begg, Holo c!ak &l%asri#'a(athe )*rd, ed+ Chapter +? Chapters +<0 ,@ and ,+

/ulti5ser Databases

Multiuser database $ more than one user processes the database at the same time Se"eral issues arise/ +* Ho) can )e pre"ent users from interferin )ith each other-s )or' F ,* Ho) can )e safely process transactions on the database )ithout corruptin or losin data F 5* If there is a problem 3e* *0 po)er failure or system crash40 ho) can )e reco"er )ithout loosin all of our data F

Transaction "rocessing

&e need the ability to control ho) transactions are run in a multiuser database* A transaction is a set of read and %rite operations that must either commit or abort* Consider the follo)in transaction that reser"es a seat on an airplane fli ht and chan es the customer/ +* 6ead customer information ,* &rite reser"ation information 5* &rite char es Suppose that after the second step0 the database crashes* .r for some reason0 chan es can not be )ritten*** !ransactions can either reach a co%%it point0 )here all actions are permanently sa"ed in the database or they can abort in )hich case none of the actions are sa"ed* Another )ay to say this is transactions are $to%ic* All operations in a transaction must be executed as a sin le unit $ 5ogical 4nit of ;ork* Consider t)o users0 each executin similar transactions/
E@am/le D1B ?)er $ &ead !alar3 *or em/ 101 -ulti/l3 )alar3 b3 1.03 Erite !alar3 *or em/ 101 ?)er 2 &ead !alar3 *or em/ 101 -ulti/l3 )alar3 b3 1.04 Erite !alar3 *or em/ 101

E@am/le D2B ?)er $ &ead in5entor3 *or "rod "200 ecrement in5entor3 b3 4 Erite in5entor3 *or "rod "200 ?)er 2 &ead in5entor3 *or "rod "200 ecrement in5entor3 b3 F Erite in5entor3 *or "rod "200

First0 )hat should the "alues for salary 3in the first example4 really be F !he DBMS must find a )ay to execute these t)o transactions concurrently and ensure the result is )hat the users 3and desi ners4 intended* !hese t)o are examples of the 5ost 4pdate or Concurrent 4pdate problem* Some chan es to the database can be o"er)ritten* Consider ho) the operations for user-s A and B mi ht be interlea"ed as in example U,* Assume there are +@ units in in"entory for #roduct #,@@/
Time 1 2 3 4 4 8 F 9 H 10 '/eration 2e1in Tran)action T$ 2e1in Tran)action T2 T$ &ead in5entor3 "200 T2 &ead in5entor3 "200 T$ ecrement in5entor3 T2 ecrement in5entor3 T$ Ertie in5entor3 T2 Ertie in5entor3 T$ .ommit T2 .ommit T$ 2e1in &ead("200) &ead("200) "200+"200,2 "200+"200,3 Erite("200) Erite("200) .ommit .ommit T2 2e1in Galue o* "200 10 10 10 10 10 10 9 (dirt3) F (dirt3) F (dirt3) F (clean)

.r somethin similar li'e/

Time 1 2 3 4 4 8 F 9 H 10 '/eration 2e1in Tran)action T$ T$ &ead in5entor3 "200 T$ ecrement in5entor3 T$ Ertie in5entor3 T$ .ommit 2e1in Tran)action T2 T2 &ead in5entor3 "200 T2 ecrement in5entor3 T2 Ertie in5entor3 T2 .ommit T$ 2e1in &ead("200) "200+"200,2 Erite("200) .ommit T2 Galue o* "200 10 10 10 9 (dirt3) 9 (clean) 9 9 9 4 (dirt3) 4 (clean)

2e1in &ead("200) "200+"200,3 Erite("200) .ommit

In the first case0 the incorrect amount 3>4 is )ritten to the database* !his is called the 5ost 4pdate problem because )e lost the update from !A $ it )as o"er)ritten by !,* !he second example )or's because )e let !A )rite the ne) "alue of #roduct #,@@ before !B can read it* Here is another example*
Time 1 '/eration 2e1in Tran)action T$ T$ 2e1in T2 Galue o* "200 10

2 3 4 4 8 F 9 H 10

T$ &ead in5entor3 "200 T$ ecrement in5entor3 T$ Ertie in5entor3 2e1in Tran)action T2 T2 &ead in5entor3 "200 T$ $bort)I&ollbac7 T2 ecrement in5entor3 T2 Ertie in5entor3 T2 .ommit

&ead("200) "200+"200,2 Erite("200) 2e1in &ead("200) $bort "200+"200,3 Erite("200) .ommit

10 10 9 9 9 10 10 4 4


(clean) (dirt3) (clean)

!he reason )e et the )ron final result is becaue !A had not committed before !B )as allo)ed to read a "alue !A had )ritten* !his is called the uncomitted dependency or Dirty read problem* %o) consider a transaction tryin to find a SUM of all units in in"entory )hile another transaction is tryin to update in"entory 3d4 means direty and 3c4 means clean*
Time "400 1 20 2 20 3 20 4 20 4 20 8 20 F 20 9 20 H 20 10 20 11 20 12 20 13 20 '/eration !um 2e1in Tran)action T$ 0 T$ &ead in5entor3 "200 0 T$ !um u/ in5entor3 10 T$ &ead in5entor3 "300 10 T$ !um u/ in5entor3 24 2e1in Tran)action T2 24 T2 &ead in5entor3 "200 24 T2 ecrement in5entor3 24 T2 Ertie in5entor3 24 T$ &ead in5entor3 "400 44 T$ !um u/ in5entor3 44 T2 .ommit 44 T$ .ommit 44 T$ 2e1in &ead("200) !um+!umJ"200 &ead("300) !um+!umJ"300 2e1in &ead("200) "200+"200,3 Erite("200) &ead("400) !um+!umJ"400 .ommit .ommit T2 "200 10 10 10 10 10 10 10 10 "300 14 14 14 14 14 14 14 14

F(d) 14 F(d) 14 F(d) 14 F(c) 14 F(c) 14

!he final sum is not correct* !his happened because !B )as allo)ed to )rite a data item that !A )as tryin to use in its )or'* !his is called the incorrect analysis problem Suppose )e ha"e a transaction that says if #5@@ is reater than #,@@ then decrement #5@@* At the same time another transaction is tryin to update #5@@*

Time "300 1 2 3 4 4 8 F (d) 9 (c) H (c) 10 11 12 13 (d) 14 (c)

'/eration 2e1in Tran)action T$ T$ &ead in5entor3 "200 T$ &ead in5entor3 "300 T2 2e1in Tran)action T2 &ead in5entor3 "300 T2 ecrement in5entor3 T2 Ertie in5entor3 T2 .ommit T$ "300 > "200 )o u/date T$ &ead in5entor3 "200 T$ &ead in5entor3 "300 T$ ecrement in5entor3 T$ Ertie in5entor3 T$ .ommit

T$ 2e1in &ead("200)+10 &ead("300)+14


"200 10 10 10 10 10 10 10 10 10 14 14 14 14 14 14 4 4 4 4 4 4 0 0

2e1in &ead("300) "300+"300,10 Erite("300) .ommit

&ead("200)+10 &ead("300)+4 "300+"300,4 Erite("300) .ommit

10 10 10 10 10

!he t)o read operations that !A performas at time 5 and time ++ et different results* !his is called the non)repeatable read problem 3or fu11y read problem4* If )e insist only one transaction can execute at a time0 in serial order0 then performance )ill be 9uite poor* Concurrency Control is a method for controllin or schedulin the operations in such a )ay that concurrent transactions can be executed* If )e do concurrency control properly0 then )e can maximi1e transaction throughput )hile a"oidin any chance* Transaction through6ut/ !he number of transactions )e can perform in a i"en time period* .ften reported as +ransactions per second or !#S* A roup of t)o or more concurrent transactions are seriali0able if )e can order their operations so that the final result is the same as if )e had run them in serial order 3one after another4* Consider transaction A0 B0 C and D* Each has 5 operations* If executin / A+0 B+0 A,0 C+0 C,0 B,0 A50 B50 C5 has the same result as executin / A+0 A,0 A50 B+0 B,0 B50 C+0 C,0 C5 !hen the abo"e schedule of transactions and operations is seriali1ed*

Concurrency Control and Locking

&e need a )ay to uarantee that our concurrent transactions can be seriali1ed* 5ocking is one such means* Locking is done to data items in order to reser"e them for future operations* A loc' is a lo ical fla set by a transaction to alert other transactions the data item is in use*

Characteristics o7 Locks

(oc's may be applied to data items in t)o )ays/ I%6licit Locks are applied by the DBMS &86licit Locks are applied by application pro rams* (oc's may be applied to/ +* a sin le data item 3"alue4 ,* an entire ro) of a table 5* a pa e 3memory se ment4 3many ro)s )orth4 ?* an entire table B* an entire database !his is referred to as the 5ock granularity

(oc's may be of type types dependin on the re9uirements of the transaction/ +* An &8clusi(e Lock pre"ents any other transaction from readin or modifyin the loc'ed item* ,* A Shared Lock allo)s another transaction to read an item but pre"ents another transaction from )ritin the item*

T o "hase Locking

!he most commonly implemented loc'in mechanism is called +%o "hased 5ocking or J"L* ,#( is a concurrency control mechanism that ensure seriali1ability* ,#( has t)o phases/ Cro)in and shrin'in * +* A transaction ac9uires loc's on data items it )ill need to complete the transaction* !his is called the gro ing 6hase* ,* .nce one loc' is released0 all no other loc' may be ac9uired* !his is called the shrinking 6hase*

Consider our prior example0 this time usin loc's/

Time 1 '/eration 2e1in Tran)action T$ T$ 2e1in T2 "200 10

2 3 4 4 8 F 9 H 10 11 12 13

2e1in Tran)action T2 T$ E@cl. #oc7 "200 T$ &ead in5entor3 "200 T2 E@cl. #oc7 "200 T$ ecrement in5entor3 T$ Ertie in5entor3 T$ &elea)e #oc7 "200 T$ .ommit T2 &ead in5entor3 "200 T2 ecrement in5entor3 T2 Ertie in5entor3 T2 .ommit

2e1in K#("200) &ead("200) enied "200+"200,2 Erite("200) &elea)e("200) .ommit &ead("200) "200+"200,3 Erite("200) .ommit

10 10 10 10 10 9 9 9 9 9 4 4

(dirt3) (dirt3) (clean)

(dirt3) (clean)

%ote that at time B0 !ransaction B is Denied a loc'* So !ransaction B )ill LspinL in place until that loc' on #,@@ is released*


(oc'in can cause problems0 ho)e"er* Consider/

T$ /lace) an e@clu)i5e loc7 on item "1001 T2 /lace) an e@clu)i5e loc7 on item "2002 T$ attem/t) to /lace an e@clu)i5e loc7 on item "2002 T$ /laced into a wait )tate T2 attem/t) to /lace an e@clu)i5e loc7 on item "1001 T2 /laced into a wait )tate ...

!his is called a deadlock* .ne transaction has loc'ed some of the resources and is )aitin for loc's so it can complete* A second transaction has loc'ed those needed items but is a)aitin the release of loc's the first transaction is holdin so it can continue* !)o main )ays to deal )ith deadloc'* +* #re"ent it in the first place by i"in each transaction exclusi"e ri hts to ac9uire all loc's needed before proceedin * ,* Allo) the deadloc' to occur0 then brea' it by abortin one of the transactions*

Database Aeco(ery and Backu6

!here are many situations in )hich a transaction may not reach a commit or abort point* +* An operatin system crash can terminate the DBMS processes ,* !he DBMS can crash 5* !he system mi ht lose po)er ?* A dis' may fail or other hard)are may fail*

B* Human error can result in deletion of critical data*

In any of these situations0 data in the database may become inconsistent or lost* Database Aeco(ery is the process of restorin the database and the data to a consistent state* !his may include restorin lost data up to the point of the e"ent 3e* * system crash4* !)o approaches are discussed here/ 6eprocessin and 6ollbac'26ollfor)ard*


In a Ae6rocessing approach0 the database is periodically bac'ed up 3a database save4 and all transactions applied since the last sa"e are recorded If the system crashes0 the latest database sa"e is restored and all of the transactions are re$ applied 3by users4 to brin the database bac' up to the point Hust before the crash* Se"eral shortcomin s/ +* !ime re9uired to re$apply transactions ,* !ransactions mi ht ha"e other 3physical4 conse9uences 5* 6e$applyin concurrent transactions is not strai ht for)ard*

$uto%ated Aeco(ery ith Aollback # Aoll7or ard

&e apply a similar techni9ue/ Ma'e periodic sa"es of the database 3time consumin operation4* Ho)e"er0 maintain a more intelli ent lo of the transactions that ha"e been applied* !his transaction log Includes before images and after images Be7ore I%age/ A copy of the table record 3or pa e4 of data before it )as chan ed by the transaction* $7ter I%age/ A copy of the table record 3or pa e4 of data after it )as chan ed by the transaction* Aollback/ Undo any partially completed transactions 3ones in pro ress )hen the crash occurred4 by applyin the before images to the database* Aoll7or ard/ 6edo the transactions by applyin the after images to the database* !his is done for transactions that )ere committed before the crash* 6eco"ery process uses both rollbac' and rollfor)ard to restore the database* In the )orst case0 )e )ould need to rollbac' to the last database sa"e and then rollfor)ard to the point Hust before the crash* Check6oints can also be ta'en 3less time consumin 4 in bet)een database sa"es* !he DBMS flushes all pendin transactions and )rites all data to dis' and transaction lo *

Database can be reco"ered from the last chec'point in much less time*

Database Backu6

&hen secondary media 3dis'4 fails0 data may become unreadable* &e typically rely on bac'in up the database to cheaper ma netic tape or other bac'up medium for a copy that can be restored* Ho)e"er0 )hen an DBMS is runnin 0 it is not possible to bac'up its files as the resultin bac'up copy on tape may be inconsistent* .ne solution/ Shut do)n the DBMS 3and thus all applications40 do a full bac'up $ copy e"erythin on to tape* !hen start up a ain* May be infeasible to do often* Most modern DBMS allo) for incremental backups* An Incre%ental backu6 )ill bac'up only those data chan ed or added since the last full bac'up* Sometimes called a delta bac'up* Follo)s somethin li'e/ +* &ee'end/ Do a shutdo)n of the DBMS0 and full bac'up of the database onto a fresh tape3s4* ,* %i htly/ Do an incremental bac'up onto different tapes for each ni ht of the )ee'*

Database Syste% $rchitectures

What You'll Learn This Week

Database System Architectures o !raditional Mainframe Architecture

o o o o o

#ersonal Computer $ Stand$Alone Database File Sharin Architecture Classic Client2Ser"er Architecture !hree$!ier Client2Ser"er Architecture Distributed Database Architecture

Data #artitionin

Data 6eplication

.pen Database Connecti"ity !ri ers and Stored #rocedures &l%asri#'a(athe )*rd ed+, Chapter ,? /c0adden )1th ed+, Chapters = and ++

Connolly#Begg#Holo c!ak )BDS, Chapter + and Chapter +B

-roenke ).th ed+, Chapter ++0 +5 and +?

Database Syste% $rchitectures

!here are a number of database system architectures presently in use* .ne must examine se"eral criteria/ +* &here do the data and DBMS reside F ,* &here are the application pro ram executed 3e* *0 )hich C#U4 F !his may include the user interface* 5* &here are business rules enforced F

Traditional /ain7ra%e $rchitecture

Database 3or files4 resides on a mainframe computer* Applications are run on the same mainframe computer* e* *0 C.B.( pro rams or AC( scripts that access the database* Business rules are enforced in the applications runnin on the mainframe* Multiple users access the applications throu h simple terminals 3e* *0 IBM 5,>@ terminals or N!,,@ terminals4 that ha"e no processin po)er of their o)n* User interface is text$ mode screens* Example/ DB, database and C.B.( application pro rams runnin on an IBM 5<@* $d(antages:
o o o

Excellent security and control o"er applications Hi h reliability $ years of pro"en MF technolo y 6elati"ely lo) incremental cost per user 3Hust add a terminal4


o o o

Unable to effecti"ely ser"e ad"anced user interfaces Users unable to effecti"ely manipulate data outside of standard applications !hat abo"e t)o items can be some)hat miti ated usin modern terminal emulators*

"ersonal Co%6uter 2 Stand2$lone Database

Database 3or files4 reside on a #C $ on the hard dis'* Applications run on the same #C and directly access the database* In such cases0 the application is the DBMS* Business rules are enforced in the applications runnin on the #C* A sin le user accesses the applications* Example/ MS Access runnin on a #C0 or FileMa'er #ro runnin on a Mac* $d(antages:
o o o

User has complete control o"er the data Modern raphical user interface Inte ration )ith other office applications

o o o

Se"erely limited data sharin abilities Difficulty implementin data standards 36esult is many small Lislands of dataL4 Security issues*

0ile Sharing $rchitecture

#Cs are connected to a local area net)or' 3(A%4* A sin le 7ile ser(er stores a sin le copy of the database files* #Cs on the (A% map a dri"e letter 3or "olume name0 or folder4 on the file ser"er* Applications run on each #C on the (A% and access the same set of files on the file ser"er* !he application is also the DBMS* Business rules are enforced in the applications $ Also0 the applications must handle concurrency control* #ossibly by file loc'in * Each user runs a copy of the same application and accesses the same files* Example/ Sharin MS Access files on a file ser"er* $d(antages:
o o o

3limited4 Ability to share data amon se"eral users Costs of stora e spread out amon users Most components are commodity items $ prices fallin

o o

(imited data sharin ability $ a fe) users at most Security is difficult to implement

Classic Client#Ser(er $rchitecture

Client machines/ o 6un o)n copy of an operatin system*

o o

6un one or more applications usin the client machine-s C#U0 memory* Application communicates )ith DBMS ser"er runnin on ser"er machine throu h a Database Driver Database dri"er 3middle)are4 ma'es a connection to the DBMS ser"er o"er a net)or'* Examples of clients/ #Cs )ith MS &indo)s operatin system* Forms and reports de"eloped in/ #o)erBuilder0 MS Access0 Borland Delphi0 .racle De"eloper0 MS Nisual Basic0 Aa"a0 CU or C880 etc*

Ser"er Machines/
o o o

6un o)n copy of an operatin system* 6un a Database Mana ement System that mana es a database* #ro"ides a 5istening daemon that accepts connections from client machines and submits transactions to DBMS on behalf of the client machines* Examples/ Sun Sparc ser"er runnin U%IT operatin system* 6DBMS such as .racle Ser"er0 Sybase0 Informix0 DB,0 etc* #C )ith &indo)s Ser"er operatin system runnin MS SI( Ser"er*


Small portion of soft)are that sits bet)een client and ser"er*

Establishes a connection from the client to the ser"er and passes commands 3e* *0 SI(4 bet)een them* See .DBC belo)* Examples/ For .racle/ SI(S%et 3or %et=4 runnin on both client and ser"er* For Sybase/ Sybase .pen Client and .pen Ser"er*

o o

Business rules may be enforced at/

1. 2. 3.

!he client application $ so called LFat ClientsL* Entirely on the database ser"er $ so called L!hin ClientsL A Mix of both*

Ad"anta es of client2ser"er/
1. 2.

#rocessin of the entire Database System is spread out o"er clients and ser"er* DBMS can achie"e hi h performance because it is dedicated to processin transactions 3not runnin applications4* Client Applications can ta'e full ad"anta e of ad"anced user interfaces such as Craphical User Interfaces*


Disad"anta es of client2ser"er/

Implementation is more complex because one needs to deal )ith middle)are and the net)or'* It is possible the net)or' is not )ell suited for client2ser"er communications and may become a bottlenec'* Additional burden on DBMS ser"er to handle concurrency control0 etc* As more business rule lo ic is pro rammed into the client side applications0 they can become un)ieldy* Stored procedures and tri ers can help in this case*


3. 4.

Example/ .racle 6DBMS runnin on a ser"er* Sybase #o)erBuilder or a Aa"a application runnin on a client #C*

Three2Tier Client Ser(er

Same eneral situation as traditional client2ser"er* Difference is the enforcement of business rules 3applications lo ic4 is done in a LmiddleL layer* Sometimes called Lapplication lo icL ser"er* Another option is to a re ate transactions from multiple users )ith a Transaction /onitor Is L)eb friendlyL* !he )eb bro)ser becomes the user interface on the client* $d(antages:
o o

Centrali1e applications lo ic 3one place to ma'e chan es4 6elie"es clients from ha"in to load up on applications lo ic 3the Lfat clientL approach4* Frees up DBMS ser"er to efficiently process transactions

o o

System complexity $ complex to pro ram and debu Security must be implemented across all layers


.racle Ser"er 6DBMS runnin on a ser"er* BEA !uxedo !ransaction #rocessin System runnin on the LMiddle tierL Sybase$#o)erSoft #o)erBuilder runnin on a client #C*

.racle Ser"er 6DBMS runnin on a ser"er* .racle &eb Applications Ser"er runnin on the LMiddle tierL MS Internet Explorer 3)eb bro)ser4 runnin on a client #C* Sybase Adapti"e Ser"er 6DBMS runnin on a ser"er* Sybase Enterprise Application Ser"er includin the Sybase Aa uar C!S transaction processin system runnin on the LMiddle tierL C88 application runnin on a U%IT )or'station* Microsoft SI( Ser"er runnin on a &indo)s %! Ser"er Microsoft !ransaction Ser"er 3M!S4 runnin on the Middle tier Microsoft Nisual Basic application runnin on the client #C IBM DB, 6DBMS runnin on the bac' end IBM CICS transaction mana ement C.B.( application

Distributed Database $rchitecture

In a distributed database system 3DDS40 multiple Database Mana ement Systems run on multiple ser"ers 3sites4 connected by a net)or'*

Data may be split up amon the different ser"ers or it may be replicated*

Data "artitioning
7 Data may be split up 3or partitioned4 in se"eral )ays/ +* Hori!ontal/ 6o)s in a table are split up across multiple sites* ,* Fertical/ Columns in a table are split across multiple sites* 5* Both "ertical and hori1ontal* 7 Splittin up data can impro"e performance by reducin contention for tables* Custo%er Table Custo%er ID +@@+ +@@, +@@5 +@@? 'a%e Mr* Smith Mrs* Aones Mr* Axe $ddress +,5 (exin ton +, Da"is A"e* City State Bi6 <+,5, <+,5, =+<<, =+<<@ Smith"ille :; Smith"ille :; Street"ille CA

??5 Crinder (n* Broad"ille CA

Mr* Builder DD+ #ar'er 6d*

Hori!ontal "artitioning/ "artition $

.u)tomer I 1001 1002 Name -r. !mith -r). Lone) $ddre)) 123 #e@in1ton 12 a5i) $5e. .it3 !mith5ille !mith5ille !tate >% >% Ci/ H1232 H1232 Ci/ 91HH2 91HH0

"artition 9
.u)tomer I 1003 1004 Name $ddre)) -r. $@e 443 =rinder #n. -r. 2uilder 881 "ar7er &d. .it3 !tate 2road5ille =$ !treet5ille =$

Fertical "artitioning/ "artition $

.u)tI 1001 1002 1003 1004 Name -r. !mith -r). Lone) -r. $@e -r. 2uilder

"artition 9
.u)tI 1001 1002 1003 1004 $ddre)) 123 #e@in1ton 12 a5i) $5e. 443 =rinder #n. 881 "ar7er &d. .it3 !mith5ille !mith5ille 2road5ille !treet5ille !tate >% >% =$ =$ Ci/ H1232 H1232 91HH2 91HH0

Data Ae6lication

Data may also be replicated across multiple sites/ +* Impro"e performance by mo"in a copy of data closer to the users* ,* Impro"e reliability $ if one site fails0 others can continue processin the transactions*

&e need mechanisms in place to ensure multiple copies of data are 'ept consistent* 6ecall in a centrali1ed DB )e had the notion of a commit point* In distributed DB0 )e need to consider committin a transaction that chan es data on multiple sites* Distributed Commit #rotocol such as !)o #hase Commit 3,#C4* Also called a synchronous replication protocol* +* "hase :/ Send a messa e to all sites/ LCan you commit !ransaction TFL All sites that can commit this transaction reply )ith L;L* ,* "hase J/ If all sites reply )ith L;L0 then send a LCommitL messa e to all sites* If any site replies L%oL0 then the transaction is aborted*

,#C is an example of a synchronous replication protocol* In $synchronous re6lication0 )e ta'e snapshots of a master database and propa ate the chan es to other sites on some periodic basis* In eneral0 distributed database systems offer more flexibility0 hi her performance and reater le"els of independence o"er centrali1ed systems* Ho)e"er0 distributed database systems are also much harder to desi n and de"elop0 control and administrate* Security is also more difficult to enforce*

B!&0 for those of you from the U%IT )orld0 simply replace L#CsL )ith LU%IT &or'stationsL in the phrases abo"e*

C6en DataBase Connecti(ity )CDBC,

Middle)are has historically been proprietary* %ote also subtle differences in SI( and ho) it is implemented in "arious DBMS*

Ho) can a sin le client access multiple DBMS ser"ers )ith minimal chan es F .DBC is middle)are soft)are that can connect a client to multiple ser"ers from different "endors* .DBC has t)o main portions that reside on the client/ A Dri"er Mana er and one or more DBMS dri"ers* !he Dri"er Mana er presents a uniform interface to all clients* !his consists of a set of function calls to 9uery0 update and manipulate data on a ser"er A DBMS Dri"er is typically supplied by the indi"idual DBMS "endor and contains routines to con"ert re9uests from the Dri"er Mana er into commands the specific DBMS understands* !ry this/ Nisit se"eral DBMS "endor-s )eb sites and see if they offer an .DBC dri"er that can be do)nloaded to your #C*

Triggers and Stored "rocedures

Triggers are procedures or functions stored in the DBMS and are in"o'ed )hen certain events occur* &(ents include/ Insertin a ne) ro) into a table0 updatin data in a table0 deletin a ro) in a table0 etc* Example/ A tri er may fire after each time an in"entory record is updated* !he tri er )ill automatically insert a ne) .rder record in the .rders table if the 9uantity in in"entory falls belo) a certain le"el*

!ri ers are used to enforce business rules that all applications that use the database must adhere to* #ro rammin tri ers re9uires special attention is paid to ho) transaction execute* !ri ers may cause loc's to be held lon er than expected or may ha"e other side effects* Most maHor DBMS support tri ers* e* *0 .racle supports tri ers )ritten in #(2SI(* IBM DB, supports tri ers )ritten in Hust about any lan ua e such as LCL and Aa"a* Stored "rocedures are similar to tri ers/ !hey are functions and procedures that are stored in the database* Stored procedures may be called by tri ers or by application pro rams* Stored procedures are useful in cases )hen standard applications lo ic must be implemented across all applications* Copies of this code do not need to be distributed to the clients* Also "ery useful )hen a lar e number of database accesses must be done )ith Hust a small result bein passed bac' to the client