Upload
enock-omari
View
238
Download
0
Embed Size (px)
Citation preview
8/12/2019 ICS 2206 Database System Juja
1/61
ICS 2206 - Database system
Lesson 3: Database models
3.1. Introduction
These are a variety of ways used to organize data within a database. Adatabase model species the rules according to which data are structuredand the associated operations that are permitted. It may also be seen as atechnique for the formal description of data structure, usage constraints andoperations. The facilities available vary from one database to another. Each!"# maintains a particular database model.
3.2. Lesson objectives!y the end of this lesson, the learner will be able to$
escribe database model escribe hierarchical database models escribe networ% database model &elational database model 'b(ect oriented database models3.3. Lesson outline
This lesson is organized as follows).*. Introduction).+. esson ob(ectives).). esson outline).-. ierarchical database model)./. 0etwor% database model).1. 'b(ect oriented database model).2. &elational database model
).3. &evision questions).4. #ummary).*5. #uggested reading
3.. !ierarc"ical database model.A hierarchical database model consists of a collection of records that are connectedto each other through lin%s 6pointers7.The records e8hibit parent child relationship. Aparent record can have several child records but a child record can only have ama8imum of one parent record. This model is suitable for homogenous data.&ecord access in this model must follow a denite path from the root. Theresultant structure resembles an inverted tree.
#dvanta$es o% "ierarc"ical model9i:. ata can be retrieved easily9ii:. ata integrity is easier to manage
Dra&bac's o% t"e "ierarc"ical model
1
&ecord A
&ecord ! &ecord ; &ecord
&ecord E &ecord
8/12/2019 ICS 2206 Database System Juja
2/61
9iii:. =sers must be familiar with the database structure9iv:. There is data redundancy3.(. )et&or' Database *odel
This model is similar to hierarchical model. The records e8hibit parent childrelationship where a parent record can be related to several child recordsand a child record can have lin%s to more than one parent record. Themultiple lin%ages in this model allow the networ% database model to be very>e8ible. This model is suitable for homogenous data. &ecord access does nothave to follow denite path.
#dvanta$es o% a net&or' database model9i:. !ecause it has the many?many relationship, networ% database model can
easily be accessed in any table record in the database9ii:. e8ibilityDisadvanta$e o% a )et&or' Database *odel9i:. i@cult conceptualize and design9ii:. i@culties with alterations of the database because when information
entered can alter the entire database
9iii:. ardware and software overhead3.6. +bject oriented database model
In this model, both data and their relationships are contained in a singlestructure called ob(ect. 'b(ects with similar characteristics will form a class.In this model the database is modeled in form of ob(ects and therelationships. A class is an entity that has a well?dened role in theapplication domain, as well as state, behavior and identity. An ob(ect is aninstance of a class. The state of an ob(ect refers to the attribute types6properties7 and values. The behavior of an ob(ect refers to how an ob(ect
2
&ecordA
&ecord
&ecord!
&ecord;
&ecord
E
&ecord
Customer)o
5roerty)o 5roert#ddress
/entstart
/ent;nis" /ent +&ner)o
;u5)- C- !o8 *+) 0&! *?5+?+5*5
*?5+?+5*+ *+5555
;5*+)
;u5)- C*1 !o8 *+ Thi%a +?5+?+554
+?5+?+5*) +55555
;541
CS4+*7/Customer)o
Customer)ame
;=5)- Uohn "wendwa
+Customer)o
5roerty)o
+&ner)o 5roert#ddress
/entstart /ent;nis" /ent)o
;u5)- C- ;5*+) !o8 *+) 0&! *?5+?+5*5 *?5+?+5*+ &*;u5)- C*1 ;541 !o8 *+ Thi%a +?5+?+554 +?5+?+5*) &+
CS4+*7/Customer)o
Customer)ame
;=5)- Uohn "wendwa
+
8/12/2019 ICS 2206 Database System Juja
23/61
.. /evision uestions9a:. 0ormalize the following invoice to third normal form.
9b:. The following report is how an ine8perienced database developer mightcreate a table. Rour mission is to get into )rd0ormal
8/12/2019 ICS 2206 Database System Juja
24/61
*aina *usic stores7mail: mains"Hmain.co.'e
*ovie issuance reort
Custome
r ID
Last)am
e
*ovieID
*ovie 4itle endor 4yeC"ec' +utDate
/eturn Date
*55* !arns *51"ovie1
!! &A **+55+
*55* !arns *52"ovie2
!! ;'" **+55+
*55* !arns *53"ovie3
A;" ;'" **+55+
*55* !arns *54 "ovie4 A;" ;'"
9c:. To %eep trac% of o@ce furniture, computers, printers, and so on, the
8/12/2019 ICS 2206 Database System Juja
25/61
student)o
#dvisor)o
#dvisor)ame
#dvisor/oom
Class1
Class2
**5+-)- 5*+4 Senga T;)?)) !IT* IT)*+5+)-/ 5*+3 Ban(i%u T;)?)- IT- !IT*
9f:. ene the term normalization with respect to logical design. 9+
"ar%s:9g:. escribe three anomalies that are associated with bad databasedesign. 91 "ar%s:
9h:. =se the form below to normalize it to third normal form.10. Summary
In this lesson you have learnt database normalization. Three normal formswere discussed here. The rst, second and third normal forms. The ob(ectiveof the rst normal form is to divide the =0< data into tables and assign aprimary %ey to each table. The ob(ective of the second normal form is to ta%edata that is partially dependent on the primary %ey and enter that data intoanother table.
8/12/2019 ICS 2206 Database System Juja
26/61
3.-. !"# components3./. ;omponents of atabase manager3.1. !"# products3.2.
8/12/2019 ICS 2206 Database System Juja
27/61
Ei$ure 2: D*S comonents
.(. 4"e comonents o% database mana$er:9i:.#ut"ori?ation Control:;hec%s that the user has necessaryauthorization to carry out the required function.
9ii:. Command 5rocessor:;onverts commands to a logicalsequence of steps.
9iii:. Inte$rity C"ec'er$ ;hec%s the requested operation satisesall necessary integrity constraints such as %ey constraints.
9iv:. uery +timi?er: E8amines the query language statementsand tries to choose the best and most e@cient way to e8ecuting thequery.
8/12/2019 ICS 2206 Database System Juja
28/61
Ei$ure 3: Database mana$er comonents.6. D*S 5roducts
AaB. *icroso%t SL Server
"icrosoft #F #erver is a relational database management system producedby "icrosoft. It supports "icrosoftHs version of #tructured Fuery anguage6#F7. "icrosoft #F #erver is a comprehensive database platform providingenterprise?class data management with integrated business intelligence 6!I7tools. The "icrosoft #oft #F #erver database engine provides secure,reliable storage for both relational and structured data, enabling to build andmanage highly available, performing data applications. "s #F #ervercombines the best in analysis, reporting, integration, and notication. This
enables building and deployment of cost?eective !I solutions .It has closeintegration with "icrosoft Disual #tudio, the "icrosoft '@ce #ystem, and asuite of new development tools, including the !usiness Intelligenceevelopment #tudio.AbB. +racle'racle database server is an ob(ect?relational database managementsystemJ this is the rst database designed for enterprise grid computing. The'racle grid architecture pools large numbers of servers, storage, and
2$
Crogramob(ect code
Fueryprocessor
;atalogmanager
Authorizationcontrol
Integritychec%er
;ommandprocessor
Fuery optimizer
Transactionmanager
#cheduler
!uermanager
&ecoverymanager
Accessmethods
8/12/2019 ICS 2206 Database System Juja
29/61
networ%s into a >e8ible, on?demand computing resource for enterprisecomputing needs.'racle atabase provides a high degree of self?management ? automatingroutine !A tas%s and reducing comple8ity of space, memory, and resourceadministration.
'racle has a number of products and features that provide high availabilityin cases of unplanned downtime or planned downtime. These include
8/12/2019 ICS 2206 Database System Juja
30/61
ACIs for .0ET ;I, Uava, Cython, Cerl, CC, ;QQ, ;, &EOO, CI, ;'!', &C,
8/12/2019 ICS 2206 Database System Juja
31/61
reports, queries and D! code7 can be used against a host of databasebac%ends, including Access itself, #F #erver, 'racle, and any other '!;?compliant product. This approach allows the developer to move a maturedapplicationHs data to a more powerful server without sacricing thedevelopment already in place.
.. Eunctions o% D*S atabase creation 6storing data in a dened database7 using data denition
language &etrieval 6query and reporting7 using data manipulation language.
=pdate 6;hanging the contents of the database7 using data manipulationlanguage.
Crogramming user facilities for system development.
atabase revision and restructuring using data manipulation language.
atabase integrity control using data denition language
Cerformance "onitoring
;oncurrency controlJ controlling simultaneous access to the database
.. /evision uestions9a:. =sing e8amples describe relational management systems 9&!"#:9b:. escribe the steps for selecting a !"# product.9c:. iscuss four components of database manager9d:. #tate and e8plain any four factors considered when selecting a !"#product.
.. SummaryIn this lesson you have learnt about database management systems 9!"#:$components of !"#, how to select !"# products and dierent functions of!"#.
.10. Su$$ested readin$
9*:. #ilberschatz A. and et al 6+55*7, atabase #ystem ;oncepts, "craw?ill.
9+:. arcia?"olina . and et al 6+5557, atabase #ystem$ The complete!oo%, Crentice all.9):. Elmasri &. and 0avathe #6+5557,
8/12/2019 ICS 2206 Database System Juja
32/61
;ompare and contrast logical and physical data models
escribe the features of a physical data model..3. Lesson outline
This lesson is organized as follows$4.*. Introduction
4.+. esson ob(ectives4.). esson outline4.-. enition4./. Chysical database design activities4.1. ogical versus physical data models4.2 &evision questions4.3. #ummary4.4. #uggested reading
.. De;nitionThis is a process of constructing a model of information used in an organizationbased on physical considerations li%e software and hardware. Chysical design isconcerned on how the database is organized as les and what %ind of structures touse for e@ciency of database processing.(. 5"ysical database desi$n activities
This phase includes a number of tas%s$ #elect !"#
#elect storage devices
etermine access methods
esign les and inde8es
etermine database distribution
Croduce the physical model and validate with the usersAaB. Selection o% D*S
A formal procedure is followed to select a suitable !"# product. A number of
factors must be ta%en into account when choosing a !"# product.Eactors considered &"en selectin$ t"e D*S
;osts
8/12/2019 ICS 2206 Database System Juja
33/61
;ost per unit of data
&eliability$ loss on power failure or system crash and physical failure ofthe storage device
AcB. Determine access met"ods
In this step identify specic structures and access methods for the data to
achieve optimum performance for the database system. The access methoddepends on storage structure. #ome of the access methods are$ #equential
Inde8ed sequential
ashingAdB. Desi$n ;les and inde8es
This involves designing a set of tables and constraints on these tables fromthe information given in logical data model. The tables are designed andtheir eld properties specied.
S55LI7/ 4#L7Eield)ame Data
tye
Len$t"
#upplierI 0umber 3#upplier0ame
Te8t /5
Address Te8t /5#treet Te8t /5
+/D7/ 4#L7Eield)ame Data
tyeLen$t"
'rderI Te8t /5
'rder0ame Te8t /5ateprepared
ateTime
#upplierI 0umber 35/+DC4 4#L7
Eield)ame Datatye
Len$t"
CroductI Te8t )5Croduct0ame
Te8t 15
Fuantity 0umber 3
'rderI Te8t /5AeB. Determine database distribution
There is need to consider location and number of users when deciding thedatabase distribution.
8/12/2019 ICS 2206 Database System Juja
34/61
organization has several branches in dierent locations, then a distributeddatabase may be used.
A%B. Construction o% "ysical data model
Chysical data model represents how the model will be built in the database.A physical database model shows all table structures, including column
name, column data type, column constraints, primary %ey, foreign %ey, andrelationships between tables.A$B. Constructin$ "ysical data model
!uilding of physical data models is done as follows$ ;onvert entities into tables. ;onvert relationships into foreign %eys. ;onvert attributes into columns.
8/12/2019 ICS 2206 Database System Juja
35/61
Allows the !"# to manage the creation, access, and modication oftables and their components.
elps in system documentation.
;an be used for reference when designing the database.4yes o% data dictionaries:
9i:. Integrated data dictionary?Its integrated with the !"#. &elationalsystems all have some form of integrated 6e.g., 'racle7.Integrated is usually active, meaning it is automatically updated to re>ect changes inthe database
9ii:. A stand?alone data dictionary? is not directly lin%ed to the database andmust be updated manually.
4able #ttributes 5rimary'ey
Eorei$n'ey
Data tye Eield si?e /euired
5/+DC4 CroductI Res 0o Te8t )5 ResCroduct0ame 0o 0o Te8t 15 0o
Fuantity 0o 0o 0umber 3 0o'rderI 0o Res Te8t /5 0o
S55LI7/ #upplierI Res 0o 0umber 3 Res#upplier0ame 0o 0o Te8t /5 0oAddress 0o 0o Te8t /5 0o#treet 0o 0o Te8t /5 0o
+/D7/ 'rderI Res 0o Te8t /5 Res'rder0ame 0o 0o Te8t /5 0oateCrepared 0o 0o Te8t /5 0o#upplierI 0o Res Te8t )5 0o
Table$ ata dictionary.6. Lo$ical data model versus 5"ysical data model
;omparing the physical data model with the logical data model, we see the
main dierences between the two$ Entity names are now table names.
Attributes are now column names.
ata type for each column is specied. ata types can be dierentdepending on the actual database being used.
.. /evision uestions9a:. escribe the procedure for selecting a database management system
6!"#7.9b:. ;ompare and contrast logical and physical data models.9c:. escribe the process of physical database design.9d:. !rie>y e8plain the following database storage devices.
9e:. E8plain the following database access methods.9i:. ash9ii:. Inde8ed sequential access
9f:. escribe any three functions of a data dictionary.. SummaryIn this lesson you have learnt that physical database design involves a series ofactivities$ selection of !"# and storage devices, choosing access methods,designing les and inde8es, determining database distribution, construction ofphysical data model and a data dictionary.
35
8/12/2019 ICS 2206 Database System Juja
36/61
.. Su$$ested readin$9*:. #ilberschatz A. and et al 6+55*7, atabase #ystem ;oncepts, "craw?
ill.9+:. arcia?"olina . and et al 6+5557, atabase #ystem$ The complete!oo%, Crentice all.
9):. Elmasri &. and 0avathe #6+5557, ow
management10.3. Lesson outline
This lesson is structured as follows$*5.*. Introduction *5.+. esson ob(ectives*5.). esson outline*5.-. Transaction*5./. Transaction properties*5.1. Transaction states*5.2. Transaction e8ecution
*5.3. Interference between concurrent transactions
*5.4. ;oncurrency control*5.*5. oc% based protocols*5.**. Types of loc%s*5. *+. &evision questions*5.*). #ummary*5.*-. #uggested reading
10.. 4ransaction
36
8/12/2019 ICS 2206 Database System Juja
37/61
A transaction is a series of operations carried out by a single user orapplication program that must be treated as a logical unit of wor%. Atransaction transforms the database from one consistent state to anotherconsistent state.78amle
!eginEOE;#F =CATE #ales #ET ;ostY;ostZ*.+
BE&E
8/12/2019 ICS 2206 Database System Juja
38/61
10.. 4ransaction e8ecutions.Transaction e8ecutions can be classied as$
a7 Serial e8ecution: Each operation within a transaction can be e8ecutedatomically. T*NOONTn. This method produces best result but is slow.
b7 5arallel e8ecution$ #everal transactions e8ecuting simultaneously. Bhile itimproves the throughput, resource utilization and response time. !ut toomuch parallelism can lead to wrong results.
10.. Inter%erence bet&een concurrent transactionsThere are many ways in which concurrently e8ecuting transactions can interferewith one answer and so compromise the integrity and consistency of thedatabase.a Lost 9buried udate roblem
This problem occurs when a successfully completed update operation by onetransaction is overwritten by another transaction. ;onsider the e8ample below$
4ime 4ransaction# 4ransactionT* &ead & ?T+ ? &ead &T) Brite & ?T- ? Brite &
Thus transaction ANs update is lost at time T- because transaction ! overwrites itwithout even loo%ing at it 6Bithout reading &7.
78amle: !an% balances4ime 4ransaction # 4ransaction
T* &etrieve &ecord ?T+ ? &etrieve the same record
T) =pdate the record on the basis ofvalues read at T*
?
T- ? =pdate the record on the basis ofvalues read at T+
Solution to lost udate roblem.
3$
S4#/4 4/#)S 7)D4/#)S
#+/4
C+**I4
/+LL#C@
#bort#ctive
5artiallycommitt
ed
Eail #borte
d
Commit
ted
8/12/2019 ICS 2206 Database System Juja
39/61
The lose of transaction ANs update is avoided by preventing transaction ! fromreading the value of & until after transaction ANs update has been completed. Thuswrite loc% & at T*.
b ncommitted deendency 9Dirty readroblemThis is a violation of the integrity constraints governing the database that arisewhen two transactions are allowed to e8ecute concurrently without being
synchronized. 'ne of the transaction will read value being updated by anothertransaction before it has been committed.
4ime
4ransaction#
4ransaction
T* ? Brite &T+ &ead & ?T) ? &'!A;S78amle: an' balances.4ime
4ransaction # 4ransaction
T* ? ;alculate discount as /[ for cost Ssh
*555T+ &ead discount ?T) ? &'!A;S
Transaction A is operating on false assumption that discount 6 5.5/ O *5557 stille8ists\ That is transaction A becomes dependent on uncommitted update at time
T+.
Solution to uncommitted deendency roblem.The problem is avoided by preventing transaction A from reading the value of &until after the decision has been made to commit or abort transaction !Ns eect.
Thus write loc% & at T*.c Inconsistent analysis 9)on-reeatable read roblem.
Transactions that only read the database can obtain inaccurate results if they areallowed to read partial results of incomplete transactions, which are simultaneouslyupdating the database.;onsider two transactions A and ! operating on ban% account records. Transaction Ais transferring an amount *5 from account* to account).Initially account*Y*55, account+Y/5 and account)Y+/.
4ime
4ransaction #
4ransaction
#cc1 #cc2 #cc3 Sum
T* &ead Acc* &ead Acc* *55 /5 +/ 5T+ Acc*?*5 #umQAcc* *55 /5 +/ *55T) Brite Acc* &ead Acc+ 45 /5 +/ *55T- &ead Acc) #umQAcc+ 45 /5 +/ */5
T/ Acc)Q*5 ? 45 /5 )/ */5T1 Brite Acc) ? 45 /5 )/ */5T2 ;ommit &ead Acc) 45 /5 )/ *3/T3 ? #umQAcc) 45 /5 )/ *3/T4 ? ;ommit 45
0otice transaction ! produces an inconsistent analysis of *3/ instead of *2/\Solution to inconsistent analysis roblem
3%
8/12/2019 ICS 2206 Database System Juja
40/61
The inconsistent analysis problem can prevented by loc%ing the transaction doingthe analysis until the updates by transaction A are completed. i.e. &ead loc% & at T*.
d 5"antom read
Chantom reads occur when an insert or delete action is performed against arow that belongs to a range of rows being read by a transaction. ThetransactionHs rst read of the range of rows shows a row that no longer e8istsin the second or succeeding read, as a result of a deletion by a dierenttransaction. #imilarly, as the result of an insert by a dierent transaction, thetransactionHs second or succeeding read shows a row that did not e8ist in theoriginal read.Initially
7m)o
7m)ame
E55* Uames SeenE5*+ Uanet SeenE5*/ Uohn
"organE5+) "aryUohnson
Transaction ! selects all the records where name begins with U at T+.Transaction A inserts a new record at T/.Transaction A$ I0#E&T I0T' E"C'REE 6Emp0o,Emp0ame7 DA=E#6]E55)N,NUanet Uac%sonN7Transaction !$ #EE;TZ
8/12/2019 ICS 2206 Database System Juja
41/61
falls in the range because those operations would rst have to acquire a loc%on the inde8.
10.. Concurrency controlSc"edule: It is a set of operations performed by transactions in the database. Theorder in the schedule is very important.A schedule consists of all or some of the following operations./ead98:"eans reading an item from the database.icting operations if any are in the same order and sbis a serial schedule.
10.10. ConPictin$ oerations
41
8/12/2019 ICS 2206 Database System Juja
42/61
Two operations on the same data item con>ict if at least one of the operations is awrite.4ransaction#
4ransaction
ConPictQ
&ead687 &ead687 0oBrite687 Brite687 Res&ead687 Brite687 ResBrite687 &ead687 Res&ea687 &ead6y7 0oBrite687 Brite6y7 0o&ead6y7 Brite687 0oBrite6y7 &ead687 0o
Seriali?ation o% concurrent transactions.Crocess of managing the e8ecution of a set of transactions in such a way that theirconcurrent e8ecution produces the same end result as if they were run serially. Toeliminate concurrency access problems and to implement atomicity, consistency,
and isolation we need two additional operations 6other than read and write7, whichare called oc% and =nloc%, and are applied on a data item.
10.11. Loc'-ased 5rotocolsA loc% is a mechanism to control concurrent access to a data item. A loc%ingprotocol is a set of rules followed by all transactions while requesting andreleasing loc%s. oc%ing protocols restrict the set of possible schedules. ataitems can be loc%ed in two modes$78clusive 9F mode. ata item can be both read as well as written. O?loc%is requested using loc%?O instruction.S"ared 9S mode. ata item can only be read. #?loc% is requested using
loc%?# instruction. Transaction can proceed only after request is granted.A transaction may be granted a loc% on an item if the requested loc% iscompatible with loc%s already held on the item by other transactions. Anynumber of transactions can hold shared loc%s on an item, but if anytransaction holds an e8clusive on the item no other transaction may hold anyloc% on the item. If a loc% cannot be granted, the requesting transaction ismade to wait till all incompatible loc%s held by other transactions have beenreleased. The loc% is then granted.Loc' 9F: If a transaction T* applies oc% on data item O, then O is loc%edand it is notavailable to any other transaction.
nloc' 9F:T* =nloc%s O. Thus O becomes available to other transactions.
10.12. 4yes o% a Loc'a7 S"ared loc'$ A &ead operation does not change the value of a dataitem. ence a data item can be read by two dierent transactionssimultaneously under share loc% mode. #o only to read adata item T* will do$ Share lock (X), then Read (X), and fnally Unlock (X).
42
8/12/2019 ICS 2206 Database System Juja
43/61
b7 78clusive loc'$ A write operation changes the value of the data item.ence two writeoperations from two dierent transactions or a write from T* and a read fromT+ are notallowed. A data item can be modied only under E8clusive loc%. To modify a
data item T* willdo$ Exclusive lock (X), then Write (X) and fnally Unlock (X).Bhen these loc%s are applied, then a transaction must behave in a specialway. This specialbehavior of a transaction is referred to as well-or!ed.y e8plain the meaning of the A;I properties. ow do
concurrency control and recovery management support the A;Iproperties^
9b:. !rie>y e8plain the meaning of transparency as it relates to computerprocessing. Bhy is transparency important for concurrency control andrecovery management^
9c:. Bhat costs are associated with concurrency control and recoverymanagement^ In what role, database administrator or databaseprogrammer, would you assess these costs^
9d:. Bhat is the ob(ective of concurrency control^ ow is the measure usedin the ob(ective related to waiting time^
9e:. Bhat is a loc%^ !rie>y e8plain the dierences between shared 6#7 ande8clusive 6O7 loc%s^
9f:.Bhat operations are performed by the loc% manager^
9g:. Bhat is a deadloc% and how do most !"#s handle deadloc%s^10.1. Summary
To process transactions concurrently, the database server must e8ecute somecomponent statements of one transaction, then some from other transactions,before continuing to process further operations from the rst. The order in which thecomponent operations of the various transactions are interleaved is called theschedule.Applying transactions concurrently in this manner can result in many possibleoutcomes. #ometimes, the nal state of the database also could have beenachieved had the transactions been e8ecuted sequentially, meaning that onetransaction was always completed in its entirety before the ne8t was started. Aschedule is called seriali?ablewhenever e8ecuting the transactions sequentially, in
some order, could have left the database in the same state as the actual schedule.#erializability is the commonly accepted criterion for correctness. A serializableschedule is accepted as correct because the database is not in>uenced by theconcurrent e8ecution of the transactions.
The isolation level aects a transactionHs serializability. At isolation level ), allschedules are serializable. The default setting is 5.
10.1(. Su$$ested readin$
43
8/12/2019 ICS 2206 Database System Juja
44/61
9*:. "odern atabase "anagement 61th Edition7Uerey A. oer, "ary !.Crescott,
8/12/2019 ICS 2206 Database System Juja
45/61
also involves policing against unauthorized connectivity and distribution ofprivileges. atabase security will also involve granting privileges for specicdatabase access, revo%ing certain privileges from users, ta%ing measures to protectother parts of the database such as underlying database les.
11.(. C"aracteristics o% database securityThere are three main characteristics of database security namely$
9a:. Con;dentiality$ This refers to protection against disclosure toauthorized parties
9b:. Inte$rity:This involves ensuring that data is not accidentally ormaliciously manipulated altered or corrupted.
9c:. #vailability$ This involves ensuring availability, reliability andassurance of continuity of operation.
11.6. Database security t"reatsA database threat refers to anything that can compromise integrity, availability andcondentiality of data. These threats occur due to the following factors.
9i:. !rowsing V This can involve accessing information in the database9ii:. "isuse?This can be due to malice, errors of omission etc
9iii:. Cenetration?This can be caused by unauthorized users9iv:. #ystem >aws?;an be caused by hardware or software errors9v:. ;omponent failures?;aused by malfunctioning of hardware or
software or media9vi:. Tempering?This can be due to attac%s to physical and logical
components9vii:. Eavesdropping? This can be through passive surveillance of
telecommunication channel e.g. tapping and [email protected]:. enial of service?involves preventing or delaying performance.
(amming, tra@c >ooding11.. Countermeasures to database t"reats
;ountermeasures refer to action, process, device or system that can prevent
or mitigate the eects of threats on a database. #ome of thecountermeasures to database threat are described as follows$AaB. 7n%orcin$ inte$rityThis ensures the integrity of the database provides concurrency andserializability of transactions and prevents data corruption. E8amples entityintegrity, referential integrity, domain integrity and user dened integrity.AbB. #ut"entication
Crocess of determining whether a user is who heshe claims to be. It ensuresthat users of the database are authenticated using passwords, strongauthentication 6use something the user has and something the user %nows7,smartcards, biometrics etc.
AcB. 5rivile$esA permission to access a named ob(ect in a prescribed manner. Crivileges can begranted or revo%ed. Crivileges can be system privileges where the user is allowed toperform a particular system action. It can also be a schema ob(ect privileges whichallow the user to perform a particular action on a specic schema ob(ect e.g. aprivilege to delete rows of a particular table.AdB. /oles&oles are used to ease management tas% of assigning a multitude of privileges tousers. &oles are rst created and then given sets of privileges that can be assigned
45
8/12/2019 ICS 2206 Database System Juja
46/61
to users and other roles. =sers can be given multiple roles. #o a role is a set ofprivileges. E8amples connect role, resource role and database administrator role.AeB. 5ro;lesCroles allow administrator to place a specic restrictions and controls on a numberof system resources, password use etc. The proles can be dened, named, andthen assigned to specic users or groups of users. Croles can be system resource
proles which are used to put limits on certain system resources such as ;C= time,number of data bloc%s that can be read per session or program call. ;an also beproduct proles, which are used to prevent users from accessing specic commandsor all commands^A%B. #ccess control
This control can be enforced for operating system as well as databases.
8/12/2019 ICS 2206 Database System Juja
47/61
constraints and rules can be used to validate the data that users try to enter againsta list of acceptable data and defaults can be used to enter data for the users if theyforget.AbB. 7ntity inte$rityThis is the process of ma%ing sure that each record in a table is unique in someway.Crimary %eys are used to enforce entity integrity.
AcB. /e%erential inte$rityThis is the process of protecting related data that is stored in some separate tables.It is possible for an attribute not to have a corresponding value, but it will beimpossible to have an invalid entry. The enforcement of the referential integrity rulema%es it impossible to delete a row in one table whose primary %ey has mandatorymatching foreign %ey values in another table.AdB. ser de;ned Inte$rity=ser?dened integrity allows users to dene specic business rules. E8ampleAge_Y*3.
11.10. /evision uestions9a:. escribe the following classes of database integrity
9i:. Entity integrity9ii:. &eferential integrity9iii:. omain integrity9iv:. =ser dened integrity
9b:. #tate and e8plain any EI7database security threats.9c:.
8/12/2019 ICS 2206 Database System Juja
48/61
ierentiate between heterogeneous and homogenous !
escribe various ways of data storage in a distributed database.1.3. Lesson outline
This lesson is structured as follows$*+. *. Introduction
*+.+. esson ob(ectives*+.). esson outline*+.-. enition*+./. Advantages of a distributed database*+.1. isadvantages of a distributed database*+.2. ata storage in a distributed database*+.3. Types of distributed database*+.4. &evision questions*+.*5. #ummary*+.**. #uggested reading
1.. De;nition
A distributed database is a database in which storage devices are not allattached to a common processing unit such as the ;C=, controlled by adistributed database management system. A distributed database systemconsists of loosely coupled sites that share no physical component.A distributed database management system 6!"#7 is the software thatmanages the ! and provides an access mechanism that ma%es thisdistribution transparent to the users.;onsider the diagram below.
1.(. #dvanta$es o% distributed databasesThe advantages of a distributed database include$ Improved reliability due to data replication. ocal autonomy or site autonomy since each department 6unit7 can
control the data about them.
4$
#ite A #ite !
#ite ;
;ommunicationnetwor%
#ite
8/12/2019 ICS 2206 Database System Juja
49/61
Crotection of valuable data because in case a catastrophic event suchas a re, all of the data would not be in one place, but distributed inmultiple locations.
Improved performance since data is located near the site where theregreatest demand.
Economical since it costs less since centralized processing power in asingle computer hardware is actually e8pensive than separate units inthe distributed system.
"odular growth since systems can be modied, added and removedfrom the distributed database without aecting other modules6systems7.
;ontinuous operation, even if some nodes go o`ine 6depending ondesign7.1.6. Disadvanta$es o% distributed databases
isadvantages of distributed databases include$ ;omple8ity since e8tra wor% must be done by the to ensure that the
distributed nature of the system is transparent. ;ost can be prohibitive because of increased comple8ity and a more
e8tensive infrastructure and labor. There is an increased challenge since the units must be secured, and
they are not centralized. i@cult to maintain integrity since enforcing integrity over a networ%
may require too much of the networ%Hs resources to be feasible. ac% of standards because there are no tools or methodologies to help
users convert a centralized !"# into a distributed !"#. atabase design more comple8 since the design of a distributed
database has to consider fragmentation of data, allocation of
fragments to specic sites and data replication. i@cult to ensure concurrency control.
1.. ses o% distributed databaseA distributed database can provide the following applications "anufacturing "ilitary command control !an%ing ;orporate "I# Airlines otel chains #upermar%et chains
1.. Data stora$e in a distributed databaseThere are mainly two approaches to store a relation r in a distributed
database system$9i:. &eplication9ii:.
8/12/2019 ICS 2206 Database System Juja
50/61
Carallelism is increased when read request is served.
Increases overhead on update operations as each site containing thereplica needed to be updated in order to maintain consistency.
Era$mentation:The table is fragmented into several tablestable*,table+, table )Ltable n in such a way that the actual table
could be reconstructed from the fragments and then the fragmentsare scattered to dierent locations. There are basically two schemes offragmentation$ orizontal fragmentation ? splits the tablerelation by assigning each tuple
of the table to one or more fragments. Dertical fragmentation ? splits the table by decomposing the schema of
the table.1.. 4yes o% distributed database systems
A distributed database can classied as homogenous or heterogeneous.i. !omo$enous distributed database systems.
This is a distributed database system in which all sites have identicalsoftware and are aware of each other and agree to cooperate in processinguser requests. Each site surrenders part of its autonomy in terms of right tochange schema or software. A homogeneous distributed database systemsappears to the user as a single system. The homogeneous system is mucheasier to design and manage. The following conditions must be satised forhomogeneous database$
The data structures used at each location must be same or compatible.
The database management system 6or !"#7 used at each location mustbe same or compatible.
ii. !etero$eneous distributed database systems.
This is a distributed database where dierent sites may use dierent schemaand software. ierence in schema is a ma(or problem for query processingand transaction processing. #ites may not be aware of each other and mayprovide only limited facilities for cooperation in transaction processing. Inheterogeneous systems, dierent nodes may have dierent hardware Gsoftware and data structures at various nodes or locations are alsoincompatible. ierent computers and operating systems, databaseapplications or data models may be used at each of the locations.
8/12/2019 ICS 2206 Database System Juja
51/61
9a:. #tate and e8plain any three security threats in a distributed databasesystems.
9b:. iscuss two types of distributed database systems.9c:. ierentiate between replication and fragmentation with regard to data
storage in distributed database systems.1.11. Summary
In this lesson you have learnt about distributed databases. Be haveobserved that a database need not be stored in a local dis% but can bedistributed in several sites connected by a communication lin%. =sers fromthese sites can access the databases from any site as long a as they cangain access to the networ%. This distribution has its advantages anddisadvantages. There are dierent types distributed databases such asheterogeneous and homogenous !.
1.12. Su$$ested readin$.9*:. "odern atabase "anagement 61th Edition7 Uerey A. oer, "ary !.
Crescott,
8/12/2019 ICS 2206 Database System Juja
52/61
#F stands for structured query language. This is the most common !"#implemented today. This is a standard language used to communicate withrelational databases. It was originally developed by I!" .#F was approvedby A0#I as the standard language in relational databases. #ome of the #Fversions are #F?4+, #F 44 and #F +553.
13.(. SL imlementationAn #F implementation is a particular vendorNs #F product or &!"#.These implementations vary widely though they remain A0#I #F compliant.#ome of the most popular #F vendors include oracle, "icrosoft, Informi8,#ybase and I!" supply the products with a license and so as said to beclosed sources.'ther vendors such as "y#F, Costgre#F and #AC are open source.
13.6. SL commandsThe commands can be classied according to their functions$
9a:. ata denition language 679b:. ata manipulation language6"79c:. ata Fuery language 6F79d:. ata control language6;7
AaB. Data De;nition Lan$ua$e 9DDLThese are statements used to dene, change and remove database ob(ects.
9i:. ;reate database9ii:. ;reate table9iii:. ;reate view9iv:. ;reate user9v:. ;reate inde89vi:. Alter database9vii:. Alter table9viii:. rop database9i8:. rop table98:. rop view98i:. rop user
AiB. C/7#47 D#4##S7$ This statement is used to create a new databasesynta8;&EATE ATA!A#E atatabase name_'78amle;&EATE ATA!A#E #ongs'
AiiB. C/7#47 4#L7$ This statement is used to create a new tableSynta8=se atabase name_;&EAT TA!E table name_6;olumnname* ata type_ 6
8/12/2019 ICS 2206 Database System Juja
53/61
;olumnname+ ata type_ 6
8/12/2019 ICS 2206 Database System Juja
54/61
AviB. D/+5 D#4##S7$ This statement is used to delete the databaseSynta8&'C ATA!A#E atabase name_'
78amle&'C ATA!A#E #ongs'
AviiB. D/+5 4#L7$ This statement is used to delete the table from the database.Synta8=se atabase name_&'C Table name_
78amle
=se #ongs
&'C song
AviiiB. D/+5 I)D7F$ This statement is used to delete the inde8 from the table.Synta8=se atabase name_&'C I0EO tablename.inde8 name_78amle
=se #ongs&'C I0EO song.enre
Ai8B. D/+5 I7< statement$ This statement is used to remove view.
Synta8=se atabase name_&'C DIEB view name_
78amle
=se #ongs&'C DIEB atest songs
A8B. D/+5 S7/$ This statement is used to delete the user from the database.Synta8=se atabase name_&'C =#E& =ser name_ 9;A#;AE:J78amle
=se #ongs&'C =#E& istener ;A#;AEJ
A8iB. #L47/ D#4##S7:This statement is used to change the name of thedatabase.Synta8=se atabase name_
54
8/12/2019 ICS 2206 Database System Juja
55/61
ATE& ATA!A#E atabase name_"odify 0ameY0ew database name_
78amle=se #ongsATE& ATA!A#E #ongs
"odify 0ameY"usicA8iiB. #L47/ 4#L7 statement:This statement is used to change the structure of
the table.Synta8: 4o add a ne& column=se atabase name_ATE& TA!E Table name_A6;olumnPname ataPtype6length77J
78amle=se #ongsATE& TA!E #ongA6Copularity varchar6*5577J
Synta8: 4o delete column=se atabase name_ATE& TA!E Table name_&'C;olumnPname_J78amle: Delete title column
=se #ongsATE& TA!E #ong&'C Title
AbB. SL server: Data maniulation Lan$ua$eata "anipulation anguage 6"7$ These are statements used to insert,update, delete and query data.
9i:. Insert data9ii:. =pdate data9iii:. elete data
9i:. Insert into statement:=sed to insert data into table. It can ta%e two forms$ #pecifying the column names where data will be inserted.
Synta8:=se database name_Insert into table name_6;olumn*, column+,L7DA=E#6Dalue*,Dalue+,L778amle=se #ongsI0#E&T I0T' song 6#ongI, enre, Title, Artist, Rear&eleased7DA=E#
6*+,N&aggaeN,NCrisonerN,Nuc%y ubeN,+5547 #pecifying values to be inserted only.
Synta8:=se database name_Insert into table name_ DA=E#6Dalue*,Dalue+,L7
55
8/12/2019 ICS 2206 Database System Juja
56/61
78amle=se #ongsI0#E&T I0T' song DA=E# 6*+,N&aggaeN,NCrisonerN,Nuc%y ubeN, +5547
/emar':you can also specify which column the data will be inserted.=#E #ongsI0#E&T I0T' song 6#onI,Title7 DA=E# 6*),Hip hopH7
9ii:. date statement:This statement is used to change values in thedatabase table.
Synta8:=CATE Table name_#ET ;olumn*Yvalue*, column+Yvalue+,LBE&E ;riteria
78amle
=se #ongs=CATE song#ET enreYN;lassicalN,Rear&eleaseY+5**BE&E ArtistYNUohn 0gerezaN
9iii:. Delete statement:This statement is used to remove values from thedatabase table.
Synta8:EETE
8/12/2019 ICS 2206 Database System Juja
57/61
#EE;TZ
8/12/2019 ICS 2206 Database System Juja
58/61
To select records then sort them by a specied column.;an be sorted in ascending or descending order.
Synta8:#EE;T ;olumn6s7
8/12/2019 ICS 2206 Database System Juja
59/61
=#E #ongs#EE;T enre, Title, Artist
8/12/2019 ICS 2206 Database System Juja
60/61
S55LI7/Column Data
tye
Len$t"
Descrition
#upplierI Te8t *55 Crimary %ey#upplier0a
me
Te8t *55 escriptor
CroductI Te8t *55 escriptor9c:. =se " statement to insert the following records.5/+DC45roduc
tID5roduct)ame 5rice
C* #ugar /55C+ #alt )55C) Bater )15C- #oap /55C/
8/12/2019 ICS 2206 Database System Juja
61/61
9):. atabase esign$ ;oncepts and Implementation 6"cgrah?ill ;omputer#cience #eries7 io Biederhold "craw?ill ;ollegeJ )rd edition 6*44+7
9-:. atabase #ystem ;oncepts Abraham #ilberschatz, et al "craw?ill#cienceEngineering"athJ - edition 6+55*7.
9/:. atabase "anagement #ystems &aghu &ama%rishnan, et al "craw?
ill ) edition 6+55+7.