Presentation is loading. Please wait.

Presentation is loading. Please wait.

Course logistics © 2002 by Prentice Hall.

Similar presentations


Presentation on theme: "Course logistics © 2002 by Prentice Hall."— Presentation transcript:

1 Course logistics © 2002 by Prentice Hall

2 Book information Database Processing by David Kroenke (8th Edition, Prentice Hall, ISBN ) : Managing and Using MySQL by Reese, Yarger, and King (O'Reilly, ISBN ) : Optional reading: Database Management Systems by Ramakrishnan and Gerhke (McGraw-Hill, ISBN ) : Optional reading: Data Mining by Han and Kamber (Morgan Kaufmann, ISBN ): © 2002 by Prentice Hall

3 Assignments Assignment 1: Entity-Relationship Model, Relational Model, SQL Assignment 2: Database design using ERWin and Oracle Assignment 3: Database design using MySQL Assignment 4: XML, Data Mining, and other advanced topics © 2002 by Prentice Hall

4 Notes on programming All students will do some programming as part of the assignments. For the final project, teams will be formed in ways to include students with diverse backgrounds. © 2002 by Prentice Hall

5 Syllabus - I DK Ch. 1. Introduction to Database Processing
DK Ch. 2. Introduction to Database Development DK Ch. 3. The Entity-Relationship Model DK Ch. 5. The Relational Model and Normalization DK Ch. 6. Database Design Using Entity-Relationship Models READING The ERWin System DK Ch. 8. Foundations of Relational Implementation DK Ch. 9. Structured Query Language RYK Ch. 1 MySQL DK Ch. 16. JDBC, Java Server Pages, and MySQL © 2002 by Prentice Hall

6 Syllabus - II RYK Ch. 3 SQL according to MySQL
DK Ch. 10. Database Application Design DK Ch. 11. Managing Multi-User Databases RYK Ch. 7 Database Design DK Ch. 12. Managing Databases with Oracle (DK Ch. 14). Networks, Multi-Tier Architectures, and XML READING XML and query languages for XML READING Data Mining DK App. A. Data Structures for Database Processing © 2002 by Prentice Hall

7 Introduction to Database Processing
Eighth Edition Chapter 1 David M. Kroenke Introduction to Database Processing © 2002 by Prentice Hall

8 Art or Engineering Database design and development involves both art and engineering Gathering and organizing user requirements is an art Transforming the resulting designs into physical applications involves engineering © 2002 by Prentice Hall

9 Types of Data Stored Today, most newer databases are able to store a large variety of data, including… Scalar data Names, dates, phone numbers Pictures Audio Video © 2002 by Prentice Hall

10 Database Example 1 Mary Richards Housepainting
Self Employed Entrepreneur Single User Database 3 Tables (Customers, Jobs, Source) Data Needs: Track how customers, jobs, and referrals relate Record bid estimates Track referral sources Produce mailing labels © 2002 by Prentice Hall

11 Mary Richards’ Tables SOURCE CUSTOMER JOB © 2002 by Prentice Hall

12 Database Example 2 Treble Clef Music Multi-User database on LAN
3 Tables (Customers, Instruments, Rentals) Data Needs: Track instrument rentals Handle multi-user issues © 2002 by Prentice Hall

13 Treble Clef Form 1 © 2002 by Prentice Hall

14 Treble Clef Form 2 © 2002 by Prentice Hall

15 Treble Clef Form 3 © 2002 by Prentice Hall

16 Database Example 3 State Licensing & Vehicle Registration Bureau
52 Centers, 37 Offices, Hundreds of Users 40 Tables Data Needs: Track drivers licensing issues traffic violations, accidents, arrests, limitations Track auto registration issues revenue, law enforcement Integrate the needs of many departments © 2002 by Prentice Hall

17 Database Example 4 Calvert Island Reservations Centre
Chamber of Commerce Promotional database provides access to data Customer and reservation database processes Data Needs: Store multimedia data (photos, video clips, sound clips) Must be Web / browser accessible Uses Web technologies including HTTP, DHTML, and XML © 2002 by Prentice Hall

18 Comparison Among Database Examples
© 2002 by Prentice Hall

19 Reading assignments 1/16 - Chapters 1 & 2 1/23 - Chapters 3 & 5
2/6 - Chapter 9 + ERWIN docs © 2002 by Prentice Hall

20 Applications versus Database Management Systems (DBMS)
The Database Management System (DBMS) provides functionality above and beyond the storage of information. Users want to see reports, forms, and query results – not simply data As such, application development is crucial to the design and development of the DBMS © 2002 by Prentice Hall

21 In the Beginning, There Were File-Processing Systems
The first business information systems stored information by grouping similar data into separate files. © 2002 by Prentice Hall

22 A File-Processing System
© 2002 by Prentice Hall

23 Problems with File-Processing Systems
Data separated and isolated Data often duplicated Application program dependent Incompatible data files Difficult to understand © 2002 by Prentice Hall

24 Duplication of Data When storing the same data in multiple locations, the likelihood of inconsistency is very high. What is my real name? Table 1: my name is Dan Table 2: my name is Danielle Table 3: my name is Daniel Table 4: my name is Don © 2002 by Prentice Hall

25 The Data in a DBMS Data is integrated Data duplication is reduced
Data is program independent Data is easy to understand © 2002 by Prentice Hall

26 A DMBS © 2002 by Prentice Hall

27 Database is Self-Describing
A database contains a data dictionary A data dictionary is data about the data (metadata) It describes the structure and format of the information contained within the database © 2002 by Prentice Hall

28 The Hierarchy of Data File-Processing DBMS © 2002 by Prentice Hall

29 DBMS –the Past 1970, E.F. Codd Normalization Process Compute Intensive
© 2002 by Prentice Hall

30 DBMS –the Present Ashton - Tate: dBase II, now Borland
Oracle, Focus, Ingress ported down Paradox, Revelation, MDBS, Helix, Foxpro, Access built specifically for microcomputers © 2002 by Prentice Hall

31 DBMS –the Future Trends
Client-Server Applications Integration of Internet Technology Distributed Processing Object-Oriented DBMS © 2002 by Prentice Hall

32 Introduction to Database Development
Database Processing Eighth Edition Chapter 2 David M. Kroenke Introduction to Database Development © 2002 by Prentice Hall

33 The Components of the Database System
The Database Contents The DBMS The Application Programs The Developers The Users The Database © 2002 by Prentice Hall

34 Database System Components
© 2002 by Prentice Hall

35 Database Contents User Data Metadata Indexes Application Metadata
© 2002 by Prentice Hall

36 User Data A table of data is called a relation
Columns are fields or attributes Rows are entities Relations must be structured properly © 2002 by Prentice Hall

37 Metadata Metadata describes the structure and format of the data and the overall database System tables store metadata number of tables and table names number of fields and field names primary key fields field names, data types, and length © 2002 by Prentice Hall

38 Indexes Improve performance Improve accessibility (Overhead data)
© 2002 by Prentice Hall

39 Application Metadata Stores the structure and format of forms reports
queries other application components © 2002 by Prentice Hall

40 The DBMS Design Tools Subsystem Run-Time Subsystem DBMS Engine
© 2002 by Prentice Hall

41 Design Tools Subsystem
Tools to design and develop tables forms queries reports Programming Languages macros languages © 2002 by Prentice Hall

42 Run-Time Subsystem Processes database components created by design tools © 2002 by Prentice Hall

43 DBMS Engine Intermediary between the design tools and run-time subsystems and the data Also handles . . . transaction management locking backup and recovery © 2002 by Prentice Hall

44 Creating the Database Defining the database schema Creating the tables
Defining the relationships among the tables © 2002 by Prentice Hall

45 The Database Schema Defines a database’s structure
Tables - subjects within the database Relationships - one-to-many or 1:N Domains - set of values a column may have Business rules - restrictions on data values © 2002 by Prentice Hall

46 Defining Tables using Microsoft Access
© 2002 by Prentice Hall

47 Defining Relationships Among the Tables using Microsoft Access
© 2002 by Prentice Hall

48 Components of Applications
Forms Queries Reports Menus Application Programs © 2002 by Prentice Hall

49 A Browser Data Entry Form
© 2002 by Prentice Hall

50 A Query in Microsoft Access
© 2002 by Prentice Hall

51 A Report in Microsoft Access
© 2002 by Prentice Hall

52 A Menu in Microsoft Access
© 2002 by Prentice Hall

53 Database Development Approaches
Prototype Top-down development Bottom-up development © 2002 by Prentice Hall

54 Prototype Development
Develop portions of the database and submit to users for feedback, refinement, and enhancement © 2002 by Prentice Hall

55 Top-down Development General requirements to specific requirements
A global perspective © 2002 by Prentice Hall

56 Bottom-up Development
Specific requirements to general requirements Typically faster and less risky © 2002 by Prentice Hall

57 The Data Model A data model defines and graphically depicts the data structure and relationships among the data © 2002 by Prentice Hall

58 Data Modeling Creation
Interviewing users Documenting requirements Building a data model Building a database prototype A process of inference Working backwards © 2002 by Prentice Hall

59 Common Data Models Entity-Relationship Model Semantic Object Model
© 2002 by Prentice Hall

60 The Entity-Relationship Model
Database Processing Eighth Edition Chapter 3 David M. Kroenke The Entity-Relationship Model © 2002 by Prentice Hall

61 Data Modeling Process of creating a logical representation of the structure of the database The most important task in database development © 2002 by Prentice Hall

62 Entity-Relationship Model (E-R Model)
An Entity-Relationship Model (E-R Model) consists of: Entities Attributes Identifiers Relationships © 2002 by Prentice Hall

63 An Entity An entity is an object that can be identified in the users’ work environment & that users want to track. Entities of a given type are grouped into entity classes. © 2002 by Prentice Hall

64 An Entity Example © 2002 by Prentice Hall

65 Attributes An attribute describes a characteristic of an entity
For example An entity: Employee Has attributes: EmployeeName Extension DateOfHire © 2002 by Prentice Hall

66 Identifier An identifier uniquely identifies a row in a table.
For an Employee, the SocialSecurityNumber may serve as the Indentifier. © 2002 by Prentice Hall

67 Relationships A relationship describes how one or more entities are related with each other. © 2002 by Prentice Hall

68 Relationship Cardinality
Entity-Instance Participation in relationships is shown by maximum cardinality minimum cardinality © 2002 by Prentice Hall

69 Maximum Cardinality The maximum cardinality indicates/depicts the maximum number of instances involved in a relationship. Alternatives include 1:1 (one-to-one) 1:N (one-to-many) N:M (many-to-many) © 2002 by Prentice Hall

70 Relationship Examples Showing Maximum Cardinality Alternatives
© 2002 by Prentice Hall

71 Minimum Cardinality The minimum cardinality indicates/depicts whether participation in the relationship is mandatory or optional. Alternatives include 0 (optional) 1 (mandatory) © 2002 by Prentice Hall

72 A Relationship Example Showing Minimum and Maximum Cardinality
© 2002 by Prentice Hall

73 A Recursive Relationship
A recursive relationship is when an entity has a relationship with itself. © 2002 by Prentice Hall

74 Entity-Relationship Diagram (E-R Diagram)
An entity-relationship diagram (E-R Diagram) is a graphical representation of the E-R model using a set of ‘somewhat’ standardized conventions © 2002 by Prentice Hall

75 An Entity-Relationship Diagram (E-R Diagram) Example
© 2002 by Prentice Hall

76 Weak Entity A weak entity is an entity whose instance survival depends (logically) on an associated instance in another entity © 2002 by Prentice Hall

77 Subtype Entities Some entities may have many common attributes and a few unique attributes. The common attributes may be grouped together in a supertype entity and the unique attributes may be grouped together in a subtype entity. © 2002 by Prentice Hall

78 CLIENT with Subtype Entities
© 2002 by Prentice Hall

79 E-R Diagram Computer Assisted Software Engineering (CASE) Tools
Several Computer Assisted Software Engineering (CASE) Tools exist to help create E-R Diagrams and the resulting physical database elements. Products include: IEW IEF DEFT ER-WIN Visio © 2002 by Prentice Hall

80 E-R Diagram Example: Jefferson Dance Club
© 2002 by Prentice Hall

81 E-R Diagram Example: San Juan Charters
© 2002 by Prentice Hall

82 The Semantic Object Model
Database Processing Eighth Edition Chapter 4 David M. Kroenke The Semantic Object Model © 2002 by Prentice Hall

83 What is a Semantic Object Model?
A Semantic Object Model is a data model, similar to the Entity Relationship Diagram. A data model is a logical representation of the data and the data structure © 2002 by Prentice Hall

84 Motivation for Creating Semantic Object Models
Semantic Object Models are used to interpret user data requirements and to graphically depict those requirements. © 2002 by Prentice Hall

85 Components of the Semantic Object Model
Semantic Objects (classes and instances) Attributes Semantic Object Views © 2002 by Prentice Hall

86 The Semantic Object A semantic object is a named collection of attributes that sufficiently describes a distinct identity Each semantic object instance belongs to a semantic object class © 2002 by Prentice Hall

87 Semantic Model Class A class is a collection of attributes that are used to create object instances As such, the class defines how an object instance will look See Figure 4-2a © 2002 by Prentice Hall

88 Semantic Object Instance
A semantic object instance defines one specific occurrence of a class It details the values of the attributes (as defined by the class) See Figure 4-3 © 2002 by Prentice Hall

89 A Class versus an Instance
Semantic Object Class Naming convention: a class is spelled with capital letters E.g., STUDENT, DEPARTMENT Semantic Object Instance Naming convention: an instance is spelled with mixed case letters E.g., CelinaTorski, ManagementDept © 2002 by Prentice Hall

90 Attributes Attributes specify what details/characteristics are collected for each object. Only those attributes that are necessary for users to satisfy their informational needs are stored. © 2002 by Prentice Hall

91 Attribute types Simple Attributes Store a single data element
Group Attributes Composite attributes Semantic Object Attributes Define the relationships among the semantic objects. © 2002 by Prentice Hall

92 Simple Attributes Simple attributes store single data elements
E.g., Figure 4-2a has three simple attributes DepartmentName, PhoneNumber, FaxPhoneNumber © 2002 by Prentice Hall

93 Group Attributes Group attributes are comprised of a group of related simple attributes E.g., Figure 4-2a has one group attribute The CampusAddress consists of 2 simple attributes –Building and OfficeNumber © 2002 by Prentice Hall

94 Semantic Object Attributes
Semantic object attributes define the relationship among the semantic objects Semantic object attributes are often called object links E.g., Figure 4-2a has three group attributes COLLEGE, PROFESSOR, and STUDENT © 2002 by Prentice Hall

95 Attribute Cardinality
Minimum attribute cardinality This value specifies the fewest number of instances allowed Maximum attribute cardinality This value specifies the maximum number of instances allowed How shown –> Minimum.Maximum © 2002 by Prentice Hall

96 Minimum Attribute Cardinality
This value specifies the fewest number of instances allowed 0 = optional (may have none) 1 = mandatory (at least one) Greater than one = at least the specified number of instances are required © 2002 by Prentice Hall

97 Maximum Cardinality This value specifies the maximum number of instances allowed 1 = the attribute may have no more than one instance N = the attribute may have any number of instances A specific number (other than 1) = the attribute may have no more than the specified number of instances © 2002 by Prentice Hall

98 Attribute Cardinalities
E.g., from Figure 4-2b CampusAddress may (min=0) have one (max=1) instance However, each CampusAddress must (min=1) have one (max=1) Building instance PhoneNumber must (min=1) have several (max=N) instances © 2002 by Prentice Hall

99 Paired Attributes Object links (semantic object attributes) must be paired Semantic object models do not allow for one-way object relationships i.e., If ObjectA –> ObjectB, then ObjectB –> ObjectA © 2002 by Prentice Hall

100 Object Instance Identity
How does one instance differentiate itself from other instances? It uses an Object Identifier An object identifier is used to identify a particular instance An object identifier does not need to be unique. © 2002 by Prentice Hall

101 Group Identifier An object identifier that consists of more than one attribute. E.g., {FirstName, LastName} © 2002 by Prentice Hall

102 Identifying the Identifier
The notation ID is used to denote the object identifier For unique identifiers, the ID denotation is underlined (ID) The DEPARTMENT Object, Figure 4-2b, has a unique identifier of DepartmentName © 2002 by Prentice Hall

103 Attribute Domains: Defining the Attributes
An Attribute Domain describes the physical and semantic characteristics of an attribute They describe the purpose and the descriptions for the data values © 2002 by Prentice Hall

104 Physical Attribute Domain
The physical attribute domain describes the physical characteristics of the attributes. Data type E.g., Numeric, String, Date Data length i.e., number of placeholders Data format E.g., SocialSecurityNumber format = 3 digits, a dash, 2 digits, a dash, 4 digits © 2002 by Prentice Hall

105 Semantic Attribute Domain
The Semantic Attribute Domain describes the purpose for collecting the data It describes the distinctiveness of the attribute from all others It indicates the user value of storing the data © 2002 by Prentice Hall

106 An example of Attribute Domain
DepartmentName is defined as “the set of strings of up to seven characters that represent names of departments at Highline University” Physical Domain… “the set of strings of up to seven characters” Semantic Domain… “represent the names of departments at Highline University” © 2002 by Prentice Hall

107 Not everyone wants or needs to see everything… Views
Semantic Object Views are predefined presentations of the semantic objects that serve the requirements of particular users Presenting the objects the way you want © 2002 by Prentice Hall

108 Semantic Object View Figure 4.4 shows the definition of 2 views
© 2002 by Prentice Hall

109 Semantic Object Specifications
© 2002 by Prentice Hall

110 Object Types Simple Objects Composite Objects Compound Objects
Hybrid Objects Association Objects Parent/Subtype Objects Archetype/Version Objects © 2002 by Prentice Hall

111 Simple Objects Simple Objects contain only single-valued , simple or group attributes © 2002 by Prentice Hall

112 Composite Objects Composite Objects contain one or more multi-valued, simple or group attributes © 2002 by Prentice Hall

113 Compound Objects A compound object is an object that is linked to another object A compound object has at least one object attribute (object link) © 2002 by Prentice Hall

114 Hybrid Objects Hybrid objects contain various combinations of composite and compound objects A hybrid object is an object with at least one multi-valued group attribute that includes a semantic object attribute © 2002 by Prentice Hall

115 Association Object Example
An association object is a object that relates two or more objects and stores data about the relationship Figure 4-27b © 2002 by Prentice Hall

116 Parent/Subtype Object
Parent/subtype objects depict that an object class may define different types of instances Figure 4-28 shows that the EMPLOYEE class may be used to create a (parent/supertype) instance Employee or a (subtype) of manager. Manager is a special case of an employee © 2002 by Prentice Hall

117 Archetype/Version Object
An archetype/version object is used when different revisions of the same instance may exist. Figure 4-31 © 2002 by Prentice Hall

118 Semantic Object versus the E-R Model
Orientation The fundamental way in which the data is represented Metadata The details describing the characteristics of the data itself © 2002 by Prentice Hall

119 Orientation E-R Model Semantic Object Model
Represent data in most atomic level Minimal information regarding purpose Semantic Object Model Represent and structure the data in a way that is meaningful to users © 2002 by Prentice Hall

120 Metadata E-R Model Semantic Object Model
Metadata information is not stored on the E-R Model Semantic Object Model The physical attribute domain defines the metadata © 2002 by Prentice Hall

121 The Relational Model and Normalization
Database Processing Eighth Edition Chapter 5 David M. Kroenke The Relational Model and Normalization © 2002 by Prentice Hall

122 The Relational Model Broad, flexible model
Basis for almost all DBMS products E.F. Codd defined well-structured “normal forms” of relations, “normalization” © 2002 by Prentice Hall

123 Components of the Relational Model
A two-dimensional table consisting of rows and columns Tuples The rows (or records) in a relation Attributes The columns (or fields) in a relation © 2002 by Prentice Hall

124 Terminology © 2002 by Prentice Hall

125 Functional Dependency
Functional dependencies are the relationships among the attributes within a relation. If attribute A functional depends on attribute B, then for every instance of B you will know the respective value of A. © 2002 by Prentice Hall

126 Functional Dependency Notation
Major is functionally dependent on SID SID  Major Grade is functionally dependent on the combination of SID and ClassID (SID, ClassID)  Grade © 2002 by Prentice Hall

127 Functional Dependency – an Example
EmployeeNumber  Name EmployeeNumber  Age EmployeeNumber  Sex © 2002 by Prentice Hall

128 A Key A key is a group of one or more attributes that uniquely identifies a tuple © 2002 by Prentice Hall

129 A Combination Key Sometimes more than one attribute will be required to uniquely identify a tuple. If a key consists of more than one attribute, it is called a combination (or composite) key. © 2002 by Prentice Hall

130 Example of a Combination Key
© 2002 by Prentice Hall

131 Normalization Normalization is a process of evaluating and converting a relation to reduce modification anomalies Essentially, normalization detects and eliminates data redundancy © 2002 by Prentice Hall

132 An Anomaly An anomaly is an undesirable consequence of a data modification. © 2002 by Prentice Hall

133 Normal Forms Normal forms are state-classes of relations which identify the level of anomaly-avoidance © 2002 by Prentice Hall

134 Normal Forms Levels 1NF –First Normal Form 2NF –Second Normal Form
3NF –Third Normal Form BCNF –Boyce-Codd Normal Form 4NF –Fourth Normal Form 5NF –Fifth Normal Form DK/NF –Domain/Key Normal Form © 2002 by Prentice Hall

135 First Normal Form (1NF) To be in First Normal Form (1NF) a relation must have only single-valued attributes -- neither repeating groups nor arrays are permitted © 2002 by Prentice Hall

136 Second Normal Form (2NF)
To be in Second Normal Form (2NF) the relation must be in 1NF and each nonkey attribute must be dependent on the whole key (not a subset of the key) © 2002 by Prentice Hall

137 Third Normal Form (3NF) To be in Third Normal Form (3NF) the relation must be in 2NF and no transitive dependencies may exist within the relation. A transitive dependency is when an attribute is indirectly functionally dependent on the key (that is, the dependency is through another nonkey attribute) © 2002 by Prentice Hall

138 Violation of 3NF © 2002 by Prentice Hall

139 Boyce-Codd Normal Form (BCNF)
To be in Boyce-Codd Normal Form (BCNF) the relation must be in 3NF and every determinant must be a candidate key. © 2002 by Prentice Hall

140 Fourth Normal Form (4NF)
To be in Fourth Normal Form (4NF) the relation must be in BCNF and the relation may not contain multi-valued dependencies. © 2002 by Prentice Hall

141 Fifth Normal Form (5NF) The Fifth Normal Form concerns dependencies that are obscure and beyond the scope of this text. © 2002 by Prentice Hall

142 Domain/Key Normal Form (DK/NF)
To be in Domain/Key Normal Form (DK/NF) every constraint on the relation must be a logical consequence of the definition of keys and domains. © 2002 by Prentice Hall

143 DK/NF Terminology Constraint
A rule governing static values of attributes Key A unique identifier of a tuple Domain A description of an attribute’s allowable values © 2002 by Prentice Hall

144 Domain/Key Definition of Example Above 
 DK/NF Example Domain/Key Definition of Example Above  © 2002 by Prentice Hall

145 DK/NF Example © 2002 by Prentice Hall

146 DK/NF Example © 2002 by Prentice Hall

147 Summary of Normal Forms
© 2002 by Prentice Hall

148 Synthesis of Relations
A  B and B  A one-to-one A  B but B not  A many-to-one A not  B and B not  A many-to-many © 2002 by Prentice Hall

149 Summary of Attribute Relationships
© 2002 by Prentice Hall

150 Optimization De-Normalization (a.k.a., Controlled Redundancy)
© 2002 by Prentice Hall

151 Database Design Using Entity-Relationship Models
Database Processing Eighth Edition Chapter 6 David M. Kroenke Database Design Using Entity-Relationship Models © 2002 by Prentice Hall

152 Entities & Relationships
Entities are those things that users want to track Relationships define how entities are associated with each other © 2002 by Prentice Hall

153 Representing an Entity
© 2002 by Prentice Hall

154 Representing a ‘Has-a’ Relationship
1:1 and 1:N relationships are saved by creating foreign keys A foreign key is when you take the primary key from one table (on the one-side) and place it into another table (on the many-side or into the other table for a 1:1 relationship) © 2002 by Prentice Hall

155 Representing a 1:1 Relationship
The foreign key can go on either side BUT it is on one side only © 2002 by Prentice Hall

156 Representing 1:N Relationships
In each of the following examples, the foreign key goes to the right (into the many-side) © 2002 by Prentice Hall

157 Foreign Key Placement ProfessorName goes into the Student table as a Foreign Key © 2002 by Prentice Hall

158 Representing a N:M Relationship
N:M relationships are saved by creating a new table. The primary key of the new table is a combination key composed of the primary keys from each of the tables involved in the relationship. © 2002 by Prentice Hall

159 Representing a M:N Relationship
© 2002 by Prentice Hall

160 An E-R Diagram Example © 2002 by Prentice Hall

161 The Representation of the E-R Diagram Example on previous slide
© 2002 by Prentice Hall

162 Common Relationship Patterns
Tree Simple Networks Complex Networks Bills of Materials © 2002 by Prentice Hall

163 Tree Relationship Pattern
A tree relationship pattern is a form of hierarchy The data structure elements have only one-to-many relationships © 2002 by Prentice Hall

164 A Tree Relationship Example
© 2002 by Prentice Hall

165 Simple Network Relationship Pattern
A simple network relationship pattern data structure has only 1:N relationships. The elements may have more than one parent as long as the parents are of different types © 2002 by Prentice Hall

166 Example of a Simple Network Relationship Pattern
© 2002 by Prentice Hall

167 A Complex Network Relationship Pattern
A complex network relationship pattern is where the data structure has at least one N:M relationship © 2002 by Prentice Hall

168 Example of a Complex Network Relationship Pattern
© 2002 by Prentice Hall

169 Database Design with Semantic Object Models
Database Processing Eighth Edition Chapter 7 David M. Kroenke Database Design with Semantic Object Models © 2002 by Prentice Hall

170 Simple Objects As you may recall from Chapter 4…
Simple Objects contain only single-valued simple or group attributes (see Figure 4-15) © 2002 by Prentice Hall

171 Transforming a Simple Object into a Relation
Figure 7-1 © 2002 by Prentice Hall

172 Composite Objects As you may recall from Chap 4…
Composite Objects contain one or more multi-valued, simple or group attributes (see Figure 4-16a) © 2002 by Prentice Hall

173 Transforming a Composite Object into a Relation
Figure 7-3 © 2002 by Prentice Hall

174 Compound Objects As you may recall from Chapter 4…
A compound object is an object that is linked to another object A compound object has at least one object attribute (object link) © 2002 by Prentice Hall

175 Types of Compound Objects
© 2002 by Prentice Hall

176 Transforming One-to-One Compound Objects into Relations
© 2002 by Prentice Hall

177 Transforming One-to-Many Compound Objects into Relations
© 2002 by Prentice Hall

178 Transforming Many-to-Many Compound Objects into Relations
© 2002 by Prentice Hall

179 Hybrid Objects As you may recall from Chapter 4…
Hybrid objects contain various combinations of composite and compound objects A hybrid object is an object with at least one multi-valued group attribute that includes a semantic object attribute © 2002 by Prentice Hall

180 Transforming Hybrid Objects into Relations
© 2002 by Prentice Hall

181 Cases of Hybrid Object Cardinality
© 2002 by Prentice Hall

182 Association Object Example
As you may recall from Chap 4… An association object is a object that relates two or more objects and stores data about the relationship © 2002 by Prentice Hall Figure 4-26b

183 Transforming Association Objects into Relations
© 2002 by Prentice Hall

184 Parent/Subtype Object
Parent/Subtype objects depict that an object class may define different types of instances Figure 4-28 shows that the EMPLOYEE class may be used to create a (parent/supertype) instance Employee or a (subtype) of manager. Manager is a special case of an employee Figure 4-28 © 2002 by Prentice Hall

185 Transforming Parent/Subtype Objects into Relations
© 2002 by Prentice Hall

186 Archetype/Version Object
An Archetype/Version Object is used when different revisions of the same instance may exist. Figure 4-31 © 2002 by Prentice Hall

187 Transforming Archetype/Version Objects into Relations
© 2002 by Prentice Hall

188 Foundations of Relational Implementation
Database Processing Eighth Edition Chapter 8 David M. Kroenke Foundations of Relational Implementation © 2002 by Prentice Hall

189 Review Relational Model Terminology
Relation is a two-dimensional table Attributes are single valued Each attribute belongs to a domain A domain is a physical and logical description of permittable values No two rows are identical Order is unimportant The row is called a tuple © 2002 by Prentice Hall

190 Data Definition Language (DDL)
In order to create the tables and structures within a database, the DBMS must provide (often using SQL) a data definition language (DDL). The DDL is used to define (i.e., Create, Drop, and Alter) everything in the database… Tables Columns Indexes Users, etc. © 2002 by Prentice Hall

191 Data Manipulation Language (DML)
When thinking about SQL, most people think of the Data Manipulation Language (DML) aspects of the language The DML allows users to insert, delete, modify, and retrieve information Select Delete Insert Update © 2002 by Prentice Hall

192 DML Alternatives A DBMS must provide at least one DML. Several options exist… Query/Update language (e.g., SQL) Query-by-Example Query-by-Form © 2002 by Prentice Hall

193 Query/Update Language
SELECT Name, Age FROM PATIENT WHERE Physician = ‘Levy’ © 2002 by Prentice Hall

194 Query by Form © 2002 by Prentice Hall

195 Application Program Interface (API)
Some applications provide an Application Program Interface (API) The API is a DML typically used by programmers To retrieve or update data contained within the application, a programmer submits requests to the application’s API. © 2002 by Prentice Hall

196 Relational Algebra Relational algebra defines a set of operators that may work on relations. Recall that relations are simply data sets. As such, relational algebra deals with set theory. The operators in relational algebra are very similar to traditional algebra except that they apply to sets. © 2002 by Prentice Hall

197 Relational Algebra Operators
Relational algebra provides several operators: Union Difference Intersection Product Projection Selection Join © 2002 by Prentice Hall

198 Union Operator The union operator adds tuples from one relation to another relation A union operation will result in combined relation This is similar to the logical operator ‘OR’ © 2002 by Prentice Hall

199 Union Operator JUNIOR and HONOR-STUDENT relations and their union:
Example of JUNIOR relation Example HONOR-STUDENT relation Union of JUNIOR and HONOR-STUDENT relations © 2002 by Prentice Hall

200 Difference Operator The difference operator produces a third relation that contains the tuples that appear in the first relation, but not the second This is similar to a subtraction © 2002 by Prentice Hall

201 Difference Operator JUNIOR relation HONOR-STUDENT relation
JUNIOR minus HONOR-STUDENT relation © 2002 by Prentice Hall

202 Intersection Operator
An intersection operation will produce a third relation that contains the tuples that are common to the relations involved. This is similar to the logical operator ‘AND’ © 2002 by Prentice Hall

203 Intersection Operator
JUNIOR relation HONOR-STUDENT relation Intersection of JUNIOR and HONOR-STUDENT relations © 2002 by Prentice Hall

204 Product Operator A product operator is a concatenation of every tuple in one relation with every tuple in a second relation The resulting relation will have n x m tuples, where… n = the number of tuples in the first relation and m = the number of tuples in the second relation This is similar to multiplication © 2002 by Prentice Hall

205 Projection Operator A projection operation produces a second relation that is a subset of the first. The subset is in terms of columns, not tuples The resulting relation will contain a limited number of columns. However, every tuple will be listed. © 2002 by Prentice Hall

206 Selection Operator The selection operator is similar to the projection operator. It produces a second relation that is a subset of the first. However, the selection operator produces a subset of tuples, not columns. The resulting relation contains all columns, but only contains a portion of the tuples. © 2002 by Prentice Hall

207 Join Operator The join operator is a combination of the product, selection, and projection operators. There are several variations of the join operator… Equijoin Natural join Outer join Left outer join Right outer join © 2002 by Prentice Hall

208 Data for Join Examples SID Name Major GradeLevel 123 Jones History JR
158 Parks Math GR 271 Smith 105 Anderson Management SN StudentNumber ClassName PositionNumber 123 H350 1 105 BA490 3 B490 7 © 2002 by Prentice Hall

209 Join Examples Equijoin Natural Join Left Outer Join
© 2002 by Prentice Hall

210 Expressing Queries in Relational Algebra
1. What are the names of all students? STUDENT [Name] 2. What are the student numbers of all students enrolled in a class? ENROLLMENT [StudentNumber] © 2002 by Prentice Hall

211 Expressing Queries in Relational Algebra
3. What are the student numbers of all students not enrolled in a class? STUDENT [SID] – ENROLLMENT [StudentNumber] 4. What are the numbers of students enrolled in the class ‘BD445’? ENROLLMENT WHERE ClassName = ‘BD445’[StudentNumber] © 2002 by Prentice Hall

212 Expressing Queries in Relational Algebra
5. What are the names of the students enrolled in class ‘BD445’? STUDENT JOIN (SID = StudentNumber) ENROLLMENT WHERE ClassName = ‘BD445’[STUDENT.Name] © 2002 by Prentice Hall

213 Expressing Queries in Relational Algebra
6. What are the names and meeting times of ‘PARKS’ classes? STUDENT WHERE Name = ‘PARKS’ JOIN (SID=StudentNumber) ENROLLMENT JOIN (ClassName = Name) CLASS [CLASS.Name, Time] © 2002 by Prentice Hall

214 Expressing Queries in Relational Algebra
7. What are the grade levels and meeting rooms of all students, including students not enrolled in a class? STUDENT LEFT OUTER JOIN (SID = StudentNumber) ENROLLMENT JOIN (ClassName = Name) CLASS [GradeLevel, Room] © 2002 by Prentice Hall

215 Summary of Relational Algebra Operators
© 2002 by Prentice Hall

216 Structured Query Language
Database Processing Eighth Edition Chapter 9 David M. Kroenke Structured Query Language © 2002 by Prentice Hall

217 Structure Query Language
Structure Query Language is known as either Its acronym, SQL, or SEQUEL, the name of the original version of SQL SEQUEL was developed by IBM in the mid-1970s. © 2002 by Prentice Hall

218 SQL, not a Procedural Programming Language
SQL is not a programming language itself, it is a data access language SQL may be embedded in traditional procedural programming languages (like COBOL) © 2002 by Prentice Hall

219 SQL Syntax SQL is not case sensitive.
SELECT field(s) ‘what columns will be retrieved FROM table(s); ‘which table contains the column data e.g., SELECT Name, Phone FROM Student; © 2002 by Prentice Hall

220 The DISTINCT Qualifier
Eliminating duplicate rows on the output… SELECT DISTINCT StateAddress FROM Employee; © 2002 by Prentice Hall

221 The WHERE Clause Reducing the output based on specified criteria…
SELECT StudentName FROM Students WHERE GradePointAverage >= 3.0; © 2002 by Prentice Hall

222 Comparison Operators Equals = Not equals <> Greater than >
Less than < Greater than or equal to >= Less than or equal to <= Within a list of values IN A logical NOT Within a range BETWEEN © 2002 by Prentice Hall

223 IN a List of Values SELECT StudentName FROM Student
WHERE State IN [‘PA’, ‘MA’, ‘CA’]; © 2002 by Prentice Hall

224 The Logical NOT SELECT StudentName FROM Students
WHERE State NOT IN [‘NJ’, ‘NM’, ‘NY’]; WHERE NOT GradePointAverage >= 3.0; © 2002 by Prentice Hall

225 Within a Range of Values
SELECT StudentName FROM Student WHERE StudentID BETWEEN 250 and 300; © 2002 by Prentice Hall

226 Using Wildcard Character Substitutions
The LIKE keyword is used in place of the = sign when you use wildcard characters. The underscore character (_) is a single character substitution The percent character (%) is a multi-character substitution © 2002 by Prentice Hall

227 Using LIKE SELECT StudentID FROM Student WHERE StudentName LIKE ‘K%’;
SELECT PartName FROM Part WHERE PartNumber LIKE ‘_ABC%’; © 2002 by Prentice Hall

228 NULL Means Nothing A NULL character means that nothing has been entered. This is different from a space or a zero. SELECT Name FROM Student WHERE Major IS NULL; © 2002 by Prentice Hall

229 ORDER BY… Sorting Outputs
Sorting in descending order… SELECT StudentID, Name FROM Student ORDER BY Name DESC; Sorting in ascending order… ORDER BY Name ASC; © 2002 by Prentice Hall

230 Built-in Functions Counting number of rows COUNT
Adding the values in a column SUM Averaging the values in a column AVG Finding the maximum value in a column MAX Finding the minimum value in a column MIN © 2002 by Prentice Hall

231 Built-in Functions SELECT Count (*) FROM Student WHERE State = ‘WI’;
SELECT Sum (Amount) FROM SalesReceipt; SELECT Max (Score) FROM Assignments; © 2002 by Prentice Hall

232 Grouping the Output SELECT Name, State FROM Student GROUP BY State;
© 2002 by Prentice Hall

233 Reducing the Groups Displayed
SELECT Name, State FROM Student GROUP BY State HAVING Count (*) > 4; © 2002 by Prentice Hall

234 Sub-Queries SELECT Name FROM Student WHERE SID IN
(SELECT StudentNumber FROM Enrollment WHERE ClassName = ‘MIS445’); © 2002 by Prentice Hall

235 Joining Tables SELECT Student.SID, Student.Name, Enrollment.ClassName
FROM Student, Enrollment WHERE Student.SID = Enrollment.StudentNumber AND Student.State = ‘OH’; © 2002 by Prentice Hall

236 EXISTS SELECT DISTINCT StudentNumber FROM Enrollment A WHERE EXISTS
FROM Enrollment B WHERE A.StudentNumber = B.StudentNumber AND A.ClassName NOT = B.ClassName); © 2002 by Prentice Hall

237 Entering Data INSERT INTO Enrollment VALUES (400, ‘MIS445’, 44);
© 2002 by Prentice Hall

238 Deleting Data DELETE Student WHERE Student.SID = 100;
© 2002 by Prentice Hall

239 Modifying Data UPDATE Enrollment SET SeatNumber = 44 WHERE SID = 400;
© 2002 by Prentice Hall

240 Overview TcX - Michael Widenius (MySQL) Hughes - David Hughes (mSQL)
Features: Mostly ANSI SQL2 compliant Transactions Stored procedures Auto_increment fields © 2002 by Prentice Hall

241 More features Cross-database joins Outer joins
API: C/C++, Eiffel, Java, PHP, Perl, Python, TCL Runs on Windows, UNIX, and Mac High performance © 2002 by Prentice Hall

242 SQL syntax CREATE TABLE people (name CHAR(10))
INSERT INTO people VALUES (‘Joe’) SELECT name FROM people WHERE name like ‘J%’ © 2002 by Prentice Hall

243 SQL commands SHOW DATABASES SHOW TABLES
Data types: INT, REAL, CHAR(l), VARCHAR(l), TEXT(l), DATE, TIME ALTER TABLE mytable MODIFY mycolumn TEXT(100) ENUM(‘cat’,’dog’,’rabbit’,’pig’) © 2002 by Prentice Hall

244 SQL commands CREATE DATABASE dbname
CREATE TABLE tname (id NOT NULL PRIMARY KEY AUTO_INCREMENT) CREATE INDEX part_of_name ON customer (name(10)) INSERT INTO tname (c1, …, cn) values (v1, …, vn) © 2002 by Prentice Hall

245 JOINs and ALIASing SELECT book.title, author.name FROM author, book
WHERE books.author = author.id SELECT very_long_column_name AS col FROM tname WHERE col=‘5’ © 2002 by Prentice Hall

246 Loading text files Comma-separated files (*.csv)
LOAD DATA LOCAL INFILE "whatever.csv" INTO TABLE tname © 2002 by Prentice Hall

247 Aggregate queries SELECT position FROM people GROUP by position
SELECT position, AVG (salary) FROM people GROUP BY position HAVING AVG (salary) > © 2002 by Prentice Hall

248 Full text search CREATE TABLE WebCache (
url VARCHAR (255) NOT NULL PRIMARY KEY, ptext TEXT NOT NULL, FULLTEXT (ptext)); INSERT INTO WebCache (url, ptext) VALUES (‘index.html’, ‘Welcome to the University of Michigan’); SELECT url from WebCache WHERE MATCH (ptext) against (‘Michigan’); © 2002 by Prentice Hall

249 Advanced features Transactions Table locking Functions Unions
Outer joins © 2002 by Prentice Hall

250 Installing MySQL on Windows
© 2002 by Prentice Hall

251 Useful pointers Small example: MySQL documentation: (official) MySQL tutorial: Online, interactive tutorials: © 2002 by Prentice Hall

252 use test; CREATE TABLE STATION (ID INTEGER PRIMARY KEY, CITY CHAR(20), STATE CHAR(2), LAT_N REAL, LONG_W REAL); DESCRIBE STATION; INSERT INTO STATION VALUES (13, 'Phoenix', 'AZ', 33, 112); INSERT INTO STATION VALUES (44, 'Denver', 'CO', 40, 105); INSERT INTO STATION VALUES (66, 'Caribou', 'ME', 47, 68); SELECT * FROM STATION; SELECT * FROM STATION WHERE LAT_N > 39.7; © 2002 by Prentice Hall

253 SELECT ID, CITY, STATE FROM STATION; ID CITY STATE ;
WHERE LAT_N > 39.7; CREATE TABLE STATS (ID INTEGER REFERENCES STATION(ID), MONTH INTEGER CHECK (MONTH BETWEEN 1 AND 12), TEMP_F REAL CHECK (TEMP_F BETWEEN -80 AND 150), RAIN_I REAL CHECK (RAIN_I BETWEEN 0 AND 100), PRIMARY KEY (ID, MONTH)); INSERT INTO STATS VALUES (13, 1, 57.4, 0.31); INSERT INTO STATS VALUES (13, 7, 91.7, 5.15); INSERT INTO STATS VALUES (44, 1, 27.3, 0.18); INSERT INTO STATS VALUES (44, 7, 74.8, 2.11); INSERT INTO STATS VALUES (66, 1, 6.7, 2.10); INSERT INTO STATS VALUES (66, 7, 65.8, 4.52); SELECT * FROM STATS; © 2002 by Prentice Hall

254 © 2002 by Prentice Hall SELECT * FROM STATION, STATS
WHERE STATION.ID = STATS.ID; SELECT MONTH, ID, RAIN_I, TEMP_F FROM STATS ORDER BY MONTH, RAIN_I DESC; SELECT LAT_N, CITY, TEMP_F FROM STATS, STATION WHERE MONTH = 7 AND STATS.ID = STATION.ID ORDER BY TEMP_F; SELECT MAX(TEMP_F), MIN(TEMP_F), AVG(RAIN_I), ID GROUP BY ID; SELECT * FROM STATION WHERE 50 < (SELECT AVG(TEMP_F) FROM STATS WHERE STATION.ID = STATS.ID); © 2002 by Prentice Hall

255 CREATE VIEW METRIC_STATS (ID, MONTH, TEMP_C, RAIN_C) AS
SELECT ID, MONTH, (TEMP_F - 32) * 5 /9, RAIN_I * FROM STATS; SELECT * FROM METRIC_STATS; SELECT * FROM METRIC_STATS WHERE TEMP_C < 0 AND MONTH = 1 ORDER BY RAIN_C; UPDATE STATS SET RAIN_I = RAIN_I ; SELECT * FROM STATS; UPDATE STATS SET TEMP_F = 74.9 WHERE ID = 44 AND MONTH = 7; © 2002 by Prentice Hall

256 © 2002 by Prentice Hall SELECT * FROM STATS; COMMIT WORK;
UPDATE STATS SET RAIN_I = 4.50 WHERE ID = 44; ROLLBACK WORK; WHERE ID = 44 AND MONTH = 7; © 2002 by Prentice Hall

257 © 2002 by Prentice Hall DELETE FROM STATS WHERE MONTH = 7
OR ID IN (SELECT ID FROM STATION WHERE LONG_W < 90); DELETE FROM STATION WHERE LONG_W < 90; COMMIT WORK; SELECT * FROM STATION; SELECT * FROM STATS; SELECT * FROM METRIC_STATS; © 2002 by Prentice Hall

258 © 2002 by Prentice Hall http://www.mysql.com/doc/en/Tutorial.html
CREATE TABLE animals ( id MEDIUMINT NOT NULL AUTO_INCREMENT, name CHAR(30) NOT NULL, PRIMARY KEY (id) ); INSERT INTO animals (name) VALUES ("dog"),("cat"),("penguin"), ("lax"),("whale"),("ostrich"); SELECT * FROM animals; CREATE TABLE shop ( article INT(4) UNSIGNED ZEROFILL DEFAULT '0000' NOT NULL, dealer CHAR(20) DEFAULT '' NOT NULL, price DOUBLE(16,2) DEFAULT '0.00' NOT NULL, PRIMARY KEY(article, dealer)); INSERT INTO shop VALUES (1,'A',3.45),(1,'B',3.99),(2,'A',10.99),(3,'B',1.45),(3,'C',1.69), (3,'D',1.25),(4,'D',19.95); SELECT * FROM shop; © 2002 by Prentice Hall

259 © 2002 by Prentice Hall CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY, title VARCHAR(200), body TEXT, FULLTEXT (title,body) ); INSERT INTO articles VALUES (NULL,'MySQL Tutorial', 'DBMS stands for DataBase ...'), (NULL,'How To Use MySQL Efficiently', 'After you went through a ...'), (NULL,'Optimizing MySQL','In this tutorial we will show ...'), (NULL,'1001 MySQL Tricks','1. Never run mysqld as root '), (NULL,'MySQL vs. YourSQL', 'In the following database comparison ...'), (NULL,'MySQL Security', 'When configured properly, MySQL ...'); SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('database'); © 2002 by Prentice Hall

260 © 2002 by Prentice Hall # What's the highest item number?
SELECT MAX(article) AS article FROM shop; # Find number, dealer, and price of the most expensive article. SELECT MAX(price) FROM shop; SELECT article, dealer, price FROM shop WHERE price=19.95; ORDER BY price DESC LIMIT 1; # What's the highest price per article? SELECT article, MAX(price) AS price GROUP BY article; © 2002 by Prentice Hall

261 © 2002 by Prentice Hall CREATE TEMPORARY TABLE tmp (
article INT(4) UNSIGNED ZEROFILL DEFAULT '0000' NOT NULL, price DOUBLE(16,2) DEFAULT '0.00' NOT NULL); LOCK TABLES shop READ; INSERT INTO tmp SELECT article, MAX(price) FROM shop GROUP BY article; SELECT shop.article, dealer, shop.price FROM shop, tmp WHERE shop.article=tmp.article AND shop.price=tmp.price; UNLOCK TABLES; DROP TABLE tmp; SELECT article, SUBSTRING( MAX( CONCAT(LPAD(price,6,'0'),dealer) ), 7) AS dealer, 0.00+LEFT( MAX( CONCAT(LPAD(price,6,'0'),dealer) ), 6) AS price FROM shop GROUP BY article; © 2002 by Prentice Hall

262 # find the articles with the highest and lowest price
SELECT FROM shop; SELECT * FROM shop WHERE OR # foreign keys CREATE TABLE person ( id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, name CHAR(60) NOT NULL, PRIMARY KEY (id) ); CREATE TABLE shirt ( style ENUM('t-shirt', 'polo', 'dress') NOT NULL, color ENUM('red', 'blue', 'orange', 'white', 'black') NOT NULL, owner SMALLINT UNSIGNED NOT NULL REFERENCES person(id), © 2002 by Prentice Hall

263 INSERT INTO person VALUES (NULL, 'Antonio Paz');
INSERT INTO shirt VALUES (NULL, 'polo', 'blue', LAST_INSERT_ID()), (NULL, 'dress', 'white', LAST_INSERT_ID()), (NULL, 't-shirt', 'blue', LAST_INSERT_ID()); INSERT INTO person VALUES (NULL, 'Lilliana Angelovska'); (NULL, 'dress', 'orange', LAST_INSERT_ID()), (NULL, 'polo', 'red', LAST_INSERT_ID()), (NULL, 'dress', 'blue', LAST_INSERT_ID()), (NULL, 't-shirt', 'white', LAST_INSERT_ID()); SELECT * FROM person; SELECT * FROM shirt; © 2002 by Prentice Hall

264 © 2002 by Prentice Hall SELECT s.* FROM person p, shirt s
WHERE p.name LIKE 'Lilliana%' AND s.owner = p.id AND s.color <> 'white'; # unions select id, style from shirt where color = 'blue' union select id, style from shirt where color = 'orange' # visits per day CREATE TABLE t1 (year YEAR(4), month INT(2) UNSIGNED ZEROFILL, day INT(2) UNSIGNED ZEROFILL); INSERT INTO t1 VALUES(2000,1,1),(2000,1,20),(2000,1,30),(2000,2,2), (2000,2,23),(2000,2,23); SELECT year,month,BIT_COUNT(BIT_OR(1<<day)) AS days FROM t1 GROUP BY year,month; © 2002 by Prentice Hall

265 Database Application Design
Database Processing Eighth Edition Chapter 10 David M. Kroenke Database Application Design © 2002 by Prentice Hall

266 Functions of a Database Application
© 2002 by Prentice Hall

267 Four Basic Functions of Database Applications
The four basic functions are common to all database applications These basic functions are Create Read Update Delete The (unfortunate) acronym for these functions is CRUD © 2002 by Prentice Hall

268 Format/Materialize Function of a Database Application
The format/materialize function of a database application involves designing the appearance of the database application © 2002 by Prentice Hall

269 Enforce Constraints Function of a Database Application
Database application constraints typically involve validating the format, structure, and/or values of data. © 2002 by Prentice Hall

270 Provide Security and Control Function of a Database Application
In that database applications provide access to many people for many purposes, the application must provide security and control functions. This helps protects the data from being seen and/or modified by unauthorized persons. © 2002 by Prentice Hall

271 Execute Application Logic Function of a Database Application
Database applications satisfy one or more business function. As such, the business logic must be embedded into the database application. These logic rules and procedures constitute the execute application logic function of a database application. © 2002 by Prentice Hall

272 A View A view is a structured list of data attributes from the entities or semantic objects defined in the data model A view can be materialized or formatted as an on-line form or a hard-copy report © 2002 by Prentice Hall

273 A View CRUD Functions –Create
INSERT INTO CUSTOMER (CUSTOMER.Name, CUSTOMER.City) VALUES (NewCust.CUSTOMER.Name, NewCust.CUSTOMER.City) © 2002 by Prentice Hall

274 A View CRUD Functions –Read
SELECT CUSTOMER.CustomerID, CUSTOMER.Name FROM CUSTOMER, WORK WHERE CUSTOMER.CustomerID = WORK.CustomerID © 2002 by Prentice Hall

275 A View CRUD Functions –Update
INSERT INTO CUSTOMER (CUSTOMER.Name, CUSTOMER.City) VALUES (NewCust.CUSTOMER.Name, NewCust.CUSTOMER.City) © 2002 by Prentice Hall

276 A View CRUD Functions –Delete
Cascading deletions depend on relationship cardinality © 2002 by Prentice Hall

277 Form Design A form should...
Reflect the underlying structure of the view Make data associations graphically evident Encourage/Guide appropriate user action/response © 2002 by Prentice Hall

278 Graphical User Interface (GUI) Controls
Drop-down list box A drop-down list box provides a list of items from which the user may choose Option (or radio) button A set of option buttons allow the user to select one of a set of alternatives © 2002 by Prentice Hall

279 Graphical User Interface (GUI) Controls
Check box A check box allows the user to select or deselect the option. Cursor movement/Pervasive Keys Cursor movement defines the behavior of the cursor. The cursor should move naturally through the form. © 2002 by Prentice Hall

280 GUI Example © 2002 by Prentice Hall

281 Report Design The report should...
Reflect the underlying structure of the view Handle implied objects The implied objects are those real-world objects that provide meaning and purpose to the report and to the database application © 2002 by Prentice Hall

282 Enforcing Constraints within a Database Application
Domain constraints Uniqueness Referential integrity constraints Relationship cardinality Business rule Triggers © 2002 by Prentice Hall

283 Uniqueness Constraint
The uniqueness constraint determines if the value within the attribute must be unique for every tuple in the relation. Uniqueness is referred to as “no duplicates” within Microsoft Access © 2002 by Prentice Hall

284 Referential Integrity Constraint
Referential integrity defines the role and treatment of the foreign keys. For a foreign key to exist, the value of the foreign key must appear as a value in the primary key of the associated relation. © 2002 by Prentice Hall

285 Relationship Cardinality Constraint
Minimum relationship cardinality constraint Maximum relationship cardinality constraint © 2002 by Prentice Hall

286 Minimum Relationship Cardinality Constraint
The minimum relationship cardinality constraint defines whether participation in a relationship is mandatory or optional 0 = optional 1 = manditory A fragment is a parent that does not have a required child An orphan is a child that does not have a required parent © 2002 by Prentice Hall

287 Maximum Relationship Cardinality Constraint
The maximum relationship cardinality constraint defines the maximum level of participation in a relationship 1 = at most one N = zero or more © 2002 by Prentice Hall

288 The Relationship Between the Minimum and Maximum Relationship Cardinality Constraints
If the minimum cardinality constraint is optional (0), the maximum relationship cardinality constraint would mean: 1 = zero or one N = zero, one, or more © 2002 by Prentice Hall

289 The Relationship between the Minimum and Maximum Relationship Cardinality Constraints
If the minimum cardinality constraint is mandatory (1), the maximum relationship cardinality constraint would mean: 1 = one N = one or more © 2002 by Prentice Hall

290 Business Rule Constraints
Business rule constraints are those conditions that must be satisfied based on the rules, practices, and operating procedures of the organization. © 2002 by Prentice Hall

291 Triggers Triggers are stored procedures that are invoked based on an action. For instance a stored procedure may be invoked every time a record is added to the system. © 2002 by Prentice Hall

292 Security Functions within a Database Application
Typically, security exists on several levels within a database application To log into the system, the user needs an operating system (e.g., the Windows username/password) To log into the database, the user must supply a username and password To execute the database application, the user must be granted access to the appropriate application files © 2002 by Prentice Hall

293 Horizontal versus Vertical Security Schemes
Horizontal security refers to the practice of restricting access to certain tuples in the database. E.g., you may only see sales data in the NorthEast Vertical security refers to the practice of restricting access to certain columns in the database. E.g., you may only see the name and address fields © 2002 by Prentice Hall

294 Control Functions within a Database Application
Typically control functions are introduced into database applications through menus and by defining transaction boundaries. Using menus, the developer may control the access for a particular user. This access may change throughout a user’s session. Transaction boundaries are defined to coordinate user actions in a multi-user environment. © 2002 by Prentice Hall

295 Managing Multi-User Databases
Database Processing Eighth Edition Chapter 11 David M. Kroenke Managing Multi-User Databases © 2002 by Prentice Hall

296 Multi-User Databases Serving the needs of multiple users and multiple applications adds complexity in… design, development, and migration (future updates) © 2002 by Prentice Hall

297 Multi-User Database Issues include…
Interdependency Changes required by one user may impact others Concurrency People or applications may try to update the same information at the same time © 2002 by Prentice Hall

298 Multi-User Database Issues include… (continued)
Record Retention When information should be discarded Backup/Recovery How to protect yourself from losing critical information © 2002 by Prentice Hall

299 Common Multi-User DBMS
Windows 2000 Access 2000 SQL Server ORACLE UNIX ORACLE Sybase Informix © 2002 by Prentice Hall

300 Role of the Database Administrator
Organizations typically hire a database administrator (DBA) to handle the issues and complexities associated with multi-user databases. A DBA facilitates the development and use of one or more databases. © 2002 by Prentice Hall

301 Data Administrator versus Database Administrator
Handle the database functions and responsibilities for the entire organization. Data administrator responsibilities are discussed in Chapter 17. Database Administrator (DBA) Handle the functions associated with a specific database, including those applications served by the database. This chapter describes the responsibilities of the DBA. © 2002 by Prentice Hall

302 The Characteristics of a DBA
Technical The DBA is responsible for the performance and maintenance of one or more databases. Diplomatic The DBA must coordinate the efforts, requirements, and sometimes conflicting goals of various user groups to develop community-wide solutions. © 2002 by Prentice Hall

303 Technical Skills of the DBA
Managing the database structure Controlling concurrent processing Managing processing rights and responsibilities Developing database security Providing database recovery Managing the database management system (DBMS) Maintaining the data repository © 2002 by Prentice Hall

304 Managing the Database Structure
Managing the database structure includes configuration control and documentation regarding: The allocation of space Table creation Indices creation Storage procedures Trigger creation © 2002 by Prentice Hall

305 Configuration Control
The database configuration must reflect changes in organizational and user requirements Structural changes to the database often effect most, if not all, applications and users Sometimes configuration changes have unanticipated consequences Consequently, broad perspectives, careful analysis, and effective communication are essential. As well, the DBA must be prepared to debug and repair unforeseen issues. © 2002 by Prentice Hall

306 The Need for Documentation
When altering a databases structure, unanticipated issues are inevitable In recording the specific changes, dates, and times, it is easier to determine the root cause of issues and to resolve the issues When historical data is restored, it must be reformatted with all the changes in the database structure since the data was originally saved. © 2002 by Prentice Hall

307 Documentation All structural changes must be carefully documented with the following: Reason for change Who made the changes Specifically what was changed How and when the changes were implemented How were the changes tested and what were the results © 2002 by Prentice Hall

308 Documentation Aids Version Control and Computer Assisted Software Engineering (CASE) tools automate and/or manage many tedious documentation tasks. Printing the data dictionaries after structural changes also helps eliminate many tedious documentation tasks © 2002 by Prentice Hall

309 Controlling Concurrency Processing
Concurrency control ensures that one user’s actions do not adversely impact another user’s actions At the core of concurrency is accessibility. In one extreme, data becomes inaccessible once a user touches the data. This ensures that data that is being considered for update is not shown. In the other extreme, data is always readable. The data is even readable when it is locked for update. © 2002 by Prentice Hall

310 Aspects of Concurrency Control
Rollback/Commit: Ensuring all actions are successful before posting to the database Multitasking: Simultaneously serving multiple users Lost Updates: When one user’s action overwrites another user’s request © 2002 by Prentice Hall

311 Rollback/Commit A database operation typically involves several transactions. These transactions are atomic and are sometimes called logical units of work (LUW). Before an operation is committed to the database, all LUWs must be successfully completed. If one or more LUW is unsuccessful, a rollback is performed and no changes are saved to the database. © 2002 by Prentice Hall

312 Lost Update Problem If two or more users are attempting to update the same piece of data at the same time, it is possible that one update may overwrite another update. Resource locking scenarios are designed to address this problem © 2002 by Prentice Hall

313 Resource Locking A resource lock prevents a user from reading and/or writing to a piece of data The size of the piece of data (e.g., database, table, field) is termed the lock granularity © 2002 by Prentice Hall

314 Types of Resource Locks
Implicit versus Explicit Implicit locks are issued automatically by the DBMS based on an activity Explicit locks are issued by users requesting exclusive rights to the data Exclusive versus Shared An exclusive lock lock prevents others from reading or updating the data A shared lock allows others to read, but not update the data © 2002 by Prentice Hall

315 Two-Phased Resource Locking
Two-phased locking, whereby locks are obtained as they are needed A growing phase, whereby the transaction continues to request additional locks A shrinking phase, whereby the transaction begins to release the locks © 2002 by Prentice Hall

316 Deadlocks As a transaction begins to lock resources, it may have to wait for a particular resource to be released by another transaction. On occasions, two transactions maybe indefinitely waiting on one another to release resources. This condition is known as a deadlock or a deadly embrace. © 2002 by Prentice Hall

317 Avoiding Deadlocks Strategy 1:
Wait until all resources are available, then lock them all before beginning Strategy 2: Establish and use clear locking orders/sequences Strategy 3: Once detected, the DBMS will rollback one transaction © 2002 by Prentice Hall

318 Resource Locking Strategies
Optimistic Locking Read data Process transaction Issue update Look for conflict If conflict occurred, rollback and repeat or else commit Pessimistic Locking Lock required resources Read data Process transaction Issue update Release locks © 2002 by Prentice Hall

319 Consistent Transactions
Consistent transactions are often referred to by the acronym ACID Atomic Consistent Isolated Durable © 2002 by Prentice Hall

320 ACID: Atomic A transaction consists of a series of steps. Each step must be successful for the transaction to be saved. This ensures that the transaction completes everything it intended to do before saving the changes. © 2002 by Prentice Hall

321 ACID: Consistent No other transactions are permitted on the records until the current transaction finishes This ensures that the transaction integrity has statement level consistence among all records © 2002 by Prentice Hall

322 ACID: Isolation Within multi-user environments, different transactions may be operating on the same data. As such, the sequencing of uncommitted updates, rollbacks, and commits continuously change the data content. The 1992 ANSI SQL standards define four isolation levels and specify respective issues. © 2002 by Prentice Hall

323 Summary of Isolation Levels
© 2002 by Prentice Hall

324 ACID: Durable Durable transactions are saved to the data permanently
Interim calculations, views, and sub-queries are temporal rather than durable; that is to say that these temporal results are not saved © 2002 by Prentice Hall

325 Set-at-a-Time Versus Row-at-a-Time
SQL statements act as filters for the entire data set. A cursor may be defined within a SQL statement to point to a particular record. Several types of cursors have been defined. The cursor type defines how the cursor behaves. © 2002 by Prentice Hall

326 Types of Cursors © 2002 by Prentice Hall

327 Database Security Database security strives to ensure…
Only authorized users perform authorized activities at authorized times © 2002 by Prentice Hall

328 Managing Processing Rights and Responsibilities
Processing rights define who is permitted to do what, when The individuals performing these activities have full responsibility for the implications of their actions Individuals are identified by a username and a password © 2002 by Prentice Hall

329 Granting of Processing Rights
Database users are known as an individual and as a member of one or more role Access and processing rights/privileges may be granted to an individual and/or a role Users possess the compilation of rights granted to the individual and all the roles for which they are members © 2002 by Prentice Hall

330 Granting Privileges © 2002 by Prentice Hall

331 Providing Database Recovery
Common causes of database failures… Hardware failures Programming bugs Human errors/mistakes Malicious actions Since these issues are impossible to completely avoid, recovery procedures are essential © 2002 by Prentice Hall

332 Database Recovery Characteristics
Continuing business operations (Fall-back procedures/Continuity planning) Restore from backup Replay database activities since backup was originally made © 2002 by Prentice Hall

333 Fall-back Procedures/ Continuity Planning
The business will continue to operate even when the database is inaccessible The fall-back procedure defines how the organization will continue operations Careful attention must be paid to… saving essential data continuing to provide quality service © 2002 by Prentice Hall

334 Restoring from Backup In the event that the system must be rebuilt or reloaded, the database is restored from the last full backup. Since it is inevitable that activities occurred since the last full backup was made, subsequent activities must be replayed/restored. © 2002 by Prentice Hall

335 Recovery via Reprocessing
This is a brunt-force technique. Simply re-type all activities since the backup was performed. This procedure is costly because of the effort involved in re-entering the data. This procedure is risky in that human error is likely and in that paper record-keeping may not be accurate. © 2002 by Prentice Hall

336 Recovery via Rollback/Rollforward
Most database management systems provide a mechanism to record activities into a log file. © 2002 by Prentice Hall

337 Rollforward Activities recorded in the log files may be replayed. In doing so, all activities are re-applied to the database. This procedure is used to resynchronize restored database data. This procedure is termed a Rollforward. © 2002 by Prentice Hall

338 Rollback Since log files save activities in sequence order, it is possible to undo activities in reserve order that they were originally executed. This is performed to correct/undo erroneous or malicious transaction(s). This procedure is known as a Rollback. © 2002 by Prentice Hall

339 Managing the Database Management System (DBMS)
In addition to controlling and maintaining the users and the data, the DBA must also maintain and monitor the DBMS itself. Performance statistics (performance tuning/optimizing) System and data integrity Establishing, configuring, and maintaining database features and utilities © 2002 by Prentice Hall

340 Maintaining the Data Repository
The data repository contains metadata. Metadata is data about data. The data repository specifies the name, type, size, format, structure, definitions, and relationships among the data. They also contain the details about applications, users, add-on products, etc. © 2002 by Prentice Hall

341 Types of Data Repositories
Active data repository The development and management tools automatically maintain and upkeep the metadata. Passive data repository People manually maintain and upkeep the metadata © 2002 by Prentice Hall

342 Managing Databases with Oracle
Database Processing Eighth Edition Chapter 12 David M. Kroenke Managing Databases with Oracle © 2002 by Prentice Hall

343 What is Oracle? Oracle is the world’s most popular DBMS that…
Is extremely powerful and robust Runs on many different operating systems Can be configured and tailored Operates with most, if not all, add-on products © 2002 by Prentice Hall

344 Oracle Complexity The power and flexibility of Oracle makes it very complex: Installations are difficult The configuration options are numerous System requirements are high System maintenance is complex © 2002 by Prentice Hall

345 The Language of Oracle… SQL Plus
SQL Plus is used in Oracle to: Define the structure of a database and the definition of the data Insert, delete, and modify data Define the behavior of the system through stored procedures and triggers Retrieve data and generate reports © 2002 by Prentice Hall

346 Gaining Access to SQL Plus
To gain access to SQL Plus, you will need a username and password and possibly a host string (depending on your system configuration) When Oracle is first installed, it establishes several default accounts, namely... internal/oracle (a privileged account) sys/change_on_install (a privileged account) system/manager (a privileged account) scott/tiger (a non-privileged account) © 2002 by Prentice Hall

347 Creating the Database Ways to create an Oracle database:
Using SQL Plus Start button –> Programs –> Oracle –OraHome81 –> Applications Development –> SQL Plus Using Oracle’s Database Configuration Assistant Start button –> Programs –> Oracle –OraHome81 –> Database Administration –> Database Configuration Assistant © 2002 by Prentice Hall

348 Entering SQL Plus Commands
The SQL Plus Buffer As a user types commands, the commands are saved into the SQL Plus buffer. The SQL Plus Editor Users may edit or alter SQL Plus commands using a text editor. © 2002 by Prentice Hall

349 SQL Plus Buffer Commands
SQL Plus is not case sensitive (except within quotation marks). List – displays the content of the SQL Plus buffer List n – display line number n and changes the current line number to n Change – performs a search/replace operation for the current line number Semi-colon (;) or slash (/) executes © 2002 by Prentice Hall

350 SQL Plus Editor The SQL Plus Edit command will launch the SQL Plus text editor After the SQL statement is complete and correct, exit the editor To execute the statement, type the slash key (/) at the SQL prompt To retrieve an existing SQL file: SQL> Edit file1.sql © 2002 by Prentice Hall

351 SQL Plus Commands Desc – lists the fields in the specified table
Select – retrieve data Create – create objects Drop – delete objects Alter – change objects Insert – input data Delete – delete data Update – change data © 2002 by Prentice Hall

352 Select Syntax Select field1, field2 From table_a, table_b;
© 2002 by Prentice Hall

353 Create Syntax Create Table tablename (
field1 data_type(size) NOT NULL, field2 data_type (size) NULL); Create Sequence tableID Increment by 1 start with 1000; (this command creates a counter that automatically increments for each new record –does not ensure uniqueness) © 2002 by Prentice Hall

354 Alter Table Syntax Alter Table tablename1
Add Constraint FieldPK Primary Key (Field1, Field2); Alter Table tablename2 Add Constraint FieldFK Foreign Key (Field1, Field2) references tablename1 On Delete Cascade; © 2002 by Prentice Hall

355 Insert Syntax Insert into tablename (fieldID, field2) Values
(fieldID.NextVal, ‘data content’); © 2002 by Prentice Hall

356 Drop Syntax Drop Table tablename; Drop Sequence fieldID;
© 2002 by Prentice Hall

357 Indexes Indexes are used to enforce uniqueness and to enable fast retrieval of data. Create Unique Index fieldIndex on Table(field1, field2); © 2002 by Prentice Hall

358 Changing the Table Structures
Alter Table tablename add field4 datatype (size); Alter Table tablename Drop Column field2; –you will permanently lose the data in field2 Alter Table tablename Modify field3 not null; © 2002 by Prentice Hall

359 Changing the Data… Update Syntax
Update tablename Set field1 = ‘value_a’ Where field3 = value; © 2002 by Prentice Hall

360 Check Constraint Provide a list of valid values or a valid range…
Create Table tablename ( Field1 datatype (size) Not Null, Field2 datatype (size) Null Check (field2 in (‘value_a’, ‘value_b’))); © 2002 by Prentice Hall

361 Check Constraint Alter Table tablename Add Constraint DateChk Check (DateField1 <= DateField2); Alter Table tablename Add Constraint NumRange Check (Field1 Between 180 and 400); Alter Table tablename Drop Constraint constraintname; © 2002 by Prentice Hall

362 Views Displaying the data from the database just the way a user wants it… Create View View1 As Select * From Tablename With Read Only; © 2002 by Prentice Hall

363 PL/SQL Allowing SQL to act more like a programming language.
Row-at-a-time versus set-at-a-time. PL/SQL permits Cursors A stored procedure is a PL/SQL (or other program) stored in the database. A stored procedure may have parameters. © 2002 by Prentice Hall

364 PL/SQL Parameter Types
IN – specifies the input parameters OUT – specifies the output parameters IN OUT – a parameter that may be an input or an output © 2002 by Prentice Hall

365 PL/SQL Code Variables are declared following the AS keyword
The assignment operator is := as follows variable1 := ‘value’ Comments in PL/SQL are enclosed between /* and */ as follows… /* This is a comment */ © 2002 by Prentice Hall

366 PL/SQL Control Structures
FOR variable IN list_of_values LOOP Instructions END LOOP; IF condition THEN BEGIN END; © 2002 by Prentice Hall

367 Saving, Compiling, and Executing PL/SQL Code
The last line in the PL/SQL procedure should be a slash (/). The procedure must be saved to a file To compile the procedure, type the keyword Start, followed by the procedure filename START MyProg.SQL To see any reported errors, type SHOW ERRORS; To execute the procedure type EXEC MyProg (‘parameter1’, ‘parameter2’); © 2002 by Prentice Hall

368 Triggers A trigger is a stored procedure that is automatic invoked by Oracle when a specified activity occurs A trigger is defined relative to the activity which invoked the trigger BEFORE – execute the stored procedure prior to the activity AFTER – execute the stored procedure after the activity INSTEAD OF – execute the stored procedure in lue of the activity © 2002 by Prentice Hall

369 Trigger Example Create or Replace Trigger triggername
Before Insert or Update of fieldname on tablename For Each Row Begin /* instructions */ End; © 2002 by Prentice Hall

370 A Trigger Knows the Old and New Values for Fields
The variable :new.fieldname1 stores the new information for fieldname1 as entered by the user. The variable :old.fieldname1 stores the information in fieldname1 prior to the user’s request. © 2002 by Prentice Hall

371 Activating a Trigger The trigger must be saved to a file
To compile the trigger, type the keyword Start, followed by the trigger filename START MyTrigger.SQL To see any reported errors, type SHOW ERRORS; If no errors were encountered, the trigger is automatically activated © 2002 by Prentice Hall

372 Data Dictionary The data dictionary contains information that Oracle knows about itself… the metadata. It includes information regarding just about everything in the database including the structure and definition of tables, sequences, triggers, indexes, views, stored procedures, etc. The data dictionary table names are stored in the DICT table. © 2002 by Prentice Hall

373 Concurrency Control Since Oracle only reads committed changes, dirty reads and lost updates are avoided Transaction isolation levels: Read Committed Serializable Read-only Explicit Locks © 2002 by Prentice Hall

374 Read Committed Transaction Isolation
Reads may not be repeatable (2 reads may result in 2 data values, based on timing of updates and reads) Phantoms are possible (data from a read may be deleted after the read occurred) Uses exclusive locks Deadlocks are possible and are resolved by rolling-back one of the transactions © 2002 by Prentice Hall

375 Serializable Transaction Isolation
Reads are always repeatable Phantoms are avoided Must issue the following command: Set Transaction Isolation Level Serializable; or Alter Sessions Set Isolation Level Serializable; Coordinates activities in submission order. When this coordination detects difficulties, the application program(s) must intervene. © 2002 by Prentice Hall

376 Read-only Transaction Isolation
An Oracle-only isolation level No inserting, updating, or deleting is permitted © 2002 by Prentice Hall

377 Explicit Locking Not recommended
Oracle does not promote locks. As a result, a table may have many, many locks within it. Oracle manages these locks transparently. Issuing explicit locks may interfere with these transparent locks. © 2002 by Prentice Hall

378 Oracle Security Username and Password is used to manage DBMS access
Users may be assigned to one or more profiles Oracle provides extensive resource limitations and access rights. These restrictions may be applied to users or profiles. The SQL Grant operator provides additional access rights The SQL Revoke operator remove access rights © 2002 by Prentice Hall

379 Backup/Recovery Committed changes are saved to destination Tablespaces. Uncommitted changes are saved in the Rollback Tablespace. Redo Log files save all changes made in the Tablespaces. To start and/or recover from a system failure, the Control Files are read. © 2002 by Prentice Hall

380 Archivelog If Oracle is running in ARCHIVELOG mode, backup copies are made of the redo log files. Otherwise, the redo log files are periodically overwritten with new information. © 2002 by Prentice Hall

381 Types of Failures Application Failure
When a program bug is encountered or when a program does not correctly respond to current system conditions. Instance Failure When Oracle is unable to do what it needs to do. Media Failure When a disk becomes inaccessible to Oracle. © 2002 by Prentice Hall

382 Recovery of an Application Failure
Oracle rolls back uncommitted changes. © 2002 by Prentice Hall

383 Recovery of an Instance Failure
Oracle would be restarted using the following sequence… Read the Control File Restore system to last known valid state Roll forward changes not in system (replay the Redo Log Files) © 2002 by Prentice Hall

384 Recovery from a Media Failure
Restore system from Backup Read the Control File Roll forward changes using the Archive Log Files (from the ARCHIVELOG) Roll forward changes from the on-line Log Files (the most recent versions of the Logs) © 2002 by Prentice Hall

385 Types of Recoveries Consistent Backup
After the restoration, delete all uncommitted activities This ensures consistency, may lose recent changes Inconsistent Backup After the restoration, all uncommitted activities remain © 2002 by Prentice Hall

386 Managing Databases with SQL Server 2000
Database Processing Eighth Edition Chapter 13 David M. Kroenke Managing Databases with SQL Server 2000 © 2002 by Prentice Hall

387 SQL Server versus Oracle
Like Oracle, SQL Server adheres to the standards established by the American National Standards Institute (ANSI). As a result, the products are quite similar. A primary difference between the 2 products is the SQL Server 2000 Graphical Interface. © 2002 by Prentice Hall

388 Launching SQL Server Enterprise Manager
Console Root Microsoft SQL Servers SQL Server Group DBGRV101 Databases Right-Click Click New Database © 2002 by Prentice Hall

389 Invoking the SQL Query Analyzer
From the SQL Server Enterprise Manager: Click Tools Click SQL Query Analyzer © 2002 by Prentice Hall

390 Creating a Table with SQL in the SQL Query Analyzer
Create Table cust (custID Int Primary Key, [Name] Char (50) Not Null, Areacode Char (5) Null Default (206) Check (Areacode In (‘206’, ‘425’, ‘212’)) ) *note: since ‘Name’ is a reserved word, it must be enclosed in square brackets. © 2002 by Prentice Hall

391 Creating a Table Using the Graphical Table Creation Window
Right Click on Tables from the Enterprise Manager Click New Table Fill-in the dialog box © 2002 by Prentice Hall

392 SQL Server Data Types Smalldatetime Smallint Smallmoney Text Tinyint
Char Datetime Decimal Float Image Int Money Numeric Real Smalldatetime Smallint Smallmoney Text Tinyint Varchar © 2002 by Prentice Hall

393 Automatically Incrementing the Primary Key
To automatically increment a Primary Key… Set the Identity Speed The starting value Set the Identity Increment The value that is added each time © 2002 by Prentice Hall

394 User-Defined Data Types
Right-Click on User-Defined Data Types from the Enterprise Manager Select New User-Defined Data Type Complete the dialog box fields © 2002 by Prentice Hall

395 Defining Rules Rules are declarative expressions that limit data values. The general format <rule expression> Any SQL predicate expression is permitted (the limiting expression found in the WHERE clause) Rules serve the same purpose as the Check clauses of Create and Alter statements. However, Rules are not part of the ANSI standard. © 2002 by Prentice Hall

396 Changing Table Structures
The SQL Alter statement may be used to change the structure of a table Or… the Table Design Form may be used to change the structure of a table. © 2002 by Prentice Hall

397 Deleting a Table The SQL Drop statement may be used to delete tables
Or… you may Right-Click on the Table from the Enterprise Manager and select Delete. © 2002 by Prentice Hall

398 Defining Relationships
The SQL Foreign Key constraint may be defined when using a Create or Alter statement to define relationships Or… you may Right-Click on Diagrams from the Enterprise Manager and select New Database Diagram. © 2002 by Prentice Hall

399 Defining Relationships using New Database Diagram
Once invoked, a wizard will guide you through the process of creating the GUI. Once the GUI is created, you may drop-and-drop a Primary Key from one table to another. © 2002 by Prentice Hall

400 Enforcing Referential Integrity
Similar to Microsoft Access, the Enforce Referential Integrity Checkbox must be selected. However, SQL Server provides many more options. © 2002 by Prentice Hall

401 Views The SQL Create View statement may be used to create views in SQL Server. Or… you may create views using the SQL Server GUI. Right-Click on Views in the Enterprise Manager Click New View Complete the dialog box fields © 2002 by Prentice Hall

402 Indexes The SQL Create Index statement may be used to create an Index.
Or… you may Right-Click on the table that contains the column you wish to index Click All Tasks Click Manage Indexes Note… SQL Server automatically creates an Index for all Primary keys and Foreign Keys © 2002 by Prentice Hall

403 Application Logic Programming logic may be depicted using…
SQL (using the SQL Query Analyzer) Embedding application programs written in various programming languages (e.g., Visual Basic, Java, C#, C++, OBDC, Active Data Objects, or JDBC) Write procedures using TRANSACT-SQL. Invoke TRANSACT-SQL code using the SQL Query Analyzer via stored procedures and triggers © 2002 by Prentice Hall

404 Saved Queries SQL Server allows you to save a Query and execute it in the future. © 2002 by Prentice Hall

405 Stored Procedures Using TRANSACT-SQL, you may create stored procedures
The following is an example of how to call a stored procedure: © 2002 by Prentice Hall

406 Triggers Triggers are stored procedures that are automatically called when a specified action occurs © 2002 by Prentice Hall

407 Concurrency Control Concurrency Control behavior is a function of three factors: Transaction Isolation Level Cursor Concurrency Locking Hints © 2002 by Prentice Hall

408 Transaction Isolation Level
From least to most restrictive, the transaction isolation levels are… Read uncommitted Read committed (default) Repeatable read Serializable © 2002 by Prentice Hall

409 Cursor Concurrency The cursor concurrency options are… Read_only
Optimistic Scroll_lock © 2002 by Prentice Hall

410 Locking Hints Locking hints may be placed in SQL Select statements by adding the With parameter after the From clause. Common locking hints include… ReadCommitted ReadUncommitted RepeatableRead Serializable NoLock HoldLock © 2002 by Prentice Hall

411 Invoking a Backup Procedure
Launch the Enterprise Manager Click Databases Right-Click on the database name Select All Tasks Select Backup Database Complete the dialog box © 2002 by Prentice Hall

412 Types of Backups SQL Server supports several types of backups Complete
Differential Transactional log File and filegroup © 2002 by Prentice Hall

413 Recovery Options Recovery is performed at one of three levels: Simple
Full Bulk-Logged © 2002 by Prentice Hall

414 Networks, Multi-Tier Architectures, and XML
Database Processing Eighth Edition Chapter 14 David M. Kroenke Networks, Multi-Tier Architectures, and XML © 2002 by Prentice Hall

415 Networks A network is a collection of computers that communicate with one another using standard sets of rules, called protocols Common Network Environments: Internet Intranet Wireless Network Access © 2002 by Prentice Hall

416 The Internet Internet - a publicly accessible network of networks spanning the globe Uses communications protocol called Transmission Control Program/Internet Protocol (TCP/IP) © 2002 by Prentice Hall

417 Key Dates for the Internet
The Internet was born in the 1960’s by the US armed services and was called ARPANET HTTP: HyperText Transfer Protocol (used to create Web Pages) was created in 1989 by CERN Key HTTP characteristics: Request-based (waits for user action) Stateless (does not sequence or remember activities) © 2002 by Prentice Hall

418 HTTP: Stateless Property
In applications development, you may often wish to save the application state. Several Internet tools exist to help accomplish this: Microsoft Internet Information Server (IIS) Microsoft Active Server Pages (ASP) Java Servlets with Java ServerPages (JSP) © 2002 by Prentice Hall

419 The Intranet Some organizations use Internet technologies to create their own privately accessible network called an intranet. If a connection to the Internet does exists, it does so through a firewall An intranet is almost always faster than the Internet © 2002 by Prentice Hall

420 Firewall Firewall - a security gateway that protects an organization from unauthorized access via the Internet Consists of software and sometimes hardware components © 2002 by Prentice Hall

421 Wireless Network Access
Due to less reliability, inferior screen displays, and slower transfer rates, the traditional wired protocols are not appropriate for wireless environments. A few protocols have been developed which allow wireless devices to communicate via the Internet: Wireless Application Protocol (WAP) Wireless Markup Language (WML) © 2002 by Prentice Hall

422 Multi-tier Architectures
Tiers are the number of computers (serving a like function) that a user must use to satisfy his/her request. Common tiers include Web server and database server. © 2002 by Prentice Hall

423 A Three-Tier Architecture
© 2002 by Prentice Hall

424 Functions of Tiers © 2002 by Prentice Hall

425 Processing at the Different Tiers
Since each tier serves a different function, each tier may have a different operating system and different application software offerings. © 2002 by Prentice Hall

426 Processing Client Processing
Using the browser (e.g., Netscape Navigator) Server Processing Using Server Software (e.g., ASP) © 2002 by Prentice Hall

427 Windows 2000 Web Server Languages
JavaScript VBScript Perl ActiveX Control Java © 2002 by Prentice Hall

428 Standards & Languages Common With MS Web Server
© 2002 by Prentice Hall

429 Unix/Linux Web Server Environment
JavaScript Java Applets Java Servlets Java Server Pages Perl Java CGI © 2002 by Prentice Hall

430 N-Tier Processing The 3-Tier architecture may be extended to include additional tiers. This produces a distributed processing model using various servers on the Internet © 2002 by Prentice Hall

431 Markup Languages Markup Languages are used to specify the appearance and behavior of Web Pages Markup Language flavors: HTML – a subset of the SGML DHTML RDS/ADO XML © 2002 by Prentice Hall

432 HTML HyperText Markup Language PROS Simple Standardized CONS
Static content Limited connectivity Mixed structure/content © 2002 by Prentice Hall

433 DHTML Dynamic HyperText Markup Language
Encapsulates the entire HTML command set Provides access to objects on the page using the Document Object Model (DOM) Allows for Cascading Style Sheets (CSS) © 2002 by Prentice Hall

434 Data Services Data services allow Web pages to exchange data with databases RDS is a set of ObjectX controls The data exchanges must be relatively simple ADO is a set of ActiveX Data Controls These data exchanges may be more complex © 2002 by Prentice Hall

435 Extensible Markup Language –XML
XML clearly separates content from structure and allows developers to easily define their own elements. Rather than hard-coding Web pages, you create rules that govern how the document should look. Then merge the structure and the content files. So, the very nature of XML is dynamic. © 2002 by Prentice Hall

436 Document Type Declaration –DTD
A DTD defines the data content and may provide the data values While a DTD is desirable, it is not mandatory XML documents using DTDs are termed type-valid documents XML documents not using DTDs are termed not-type-valid documents © 2002 by Prentice Hall

437 XML & CSS Similar to DHTML, Cascading Style Sheets (CSS) may be used with XML documents to present a consistent, standardized Web site. © 2002 by Prentice Hall

438 Extensible Style Language Transformation –XMLT
XMLT is used to transform one document into another document © 2002 by Prentice Hall

439 XML Schema XML Schema is the next generation of DTD
The schema itself is an XML document A W3 standard is currently being developed A document that conforms to an XML Schema is termed schema-valid. © 2002 by Prentice Hall

440 XML Schema Concepts Simple Elements Consist of a single content value
Complex Elements Consist of multiple content values © 2002 by Prentice Hall

441 XML Namespaces Namespaces define where to look for files
An XML document may have: Up to one default namespace Many labeled namespaces Naming conventions: Must be unique within all schemas Typically resembles a URL, but is not a URL © 2002 by Prentice Hall

442 Wireless Application Protocol (WAP)
WAP has been developed to facilitate Web development for wireless devices such as Personal Data Assistants (PDA) or cellular phones © 2002 by Prentice Hall

443 WAP Server A WAP Server transforms XML documents into Wireless Markup Language (WML) – WML is a subset of XML A WML Scripting Language also exists © 2002 by Prentice Hall

444 XML and Database Applications
Any document that can process a DTD or XML Schema document can correctly interpret any arbitrary database view XML can easily process multiple multi-valued paths (several SQL statements would be required) © 2002 by Prentice Hall

445 XML and Database Applications
The separation of structure and content allows for: The same data to be displayed in many different ways The same structure (report) may be regenerated many times with different/updated data. Permits document validation checking © 2002 by Prentice Hall

446 OASIS Document structures may be published and made publicly available
Organization for the Advancement of Structured Information Standards (OASIS): A clearinghouse for XML publications and schema standards © 2002 by Prentice Hall

447 DBMS Integration of XML
Oracle XML DOM parser Xpath XSQL SQL Server ADO ASP © 2002 by Prentice Hall

448 Web-based databases © 2002 by Prentice Hall

449 Types of databases Textual databases Semi-structured databases
© 2002 by Prentice Hall

450 Indexing textual data Inverted files Boolean queries Signature files
Signature S1 matches signature S2 if S2&S1=S2 © 2002 by Prentice Hall

451 XML-QL © 2002 by Prentice Hall

452 XML-QL Two slides from Johannes Gehrke, Cornell University
<IMG SRC=“xysq.gif” ALT=“(x+y)^2”> <apply> <power/> <apply> <plus/> <ci>x</ci> <ci>y</ci> </apply> <cn>2</cn> </apply> WHERE <BOOK> <NAME><LAST>$1</LAST></NAME> </BOOK> in “ CONSTRUCT <RESULT> $1 </RESULT> © 2002 by Prentice Hall

453 XML-QL (continued) WHERE <BOOK> $b <BOOK> IN “ <AUTHOR> $n </AUTHOR> <PUBLISHED> $p </PUBLISHED> in $e CONSTRUCT <RESULT> <PUBLISHED> $p </PUBLISHED> WHERE <LAST> $l </LAST> IN $n CONSTRUCT <LAST> $l </LAST> </RESULT> © 2002 by Prentice Hall

454 XML-QL (continued) <!ELEMENT book (author+, title, publisher)>
<!ATTLIST book year CDATA> <!ELEMENT article (author+, title, year?, (shortversion|longversion))> <!ATTLIST article type CDATA> <!ELEMENT publisher (name, address)> <!ELEMENT author (firstname?, lastname)> © 2002 by Prentice Hall

455 XML-QL (continued) WHERE <book>
<publisher><name>Addison-Wesley</name></publisher> <title> $t</title> <author> $a</author> </book> IN " CONSTRUCT $a © 2002 by Prentice Hall

456 XML-QL (continued) WHERE <book>
<publisher><name>Addison-Wesley</></> <title> $t</> <author> $a</> </> IN " CONSTRUCT $a © 2002 by Prentice Hall

457 XML-QL (continued) WHERE <book>
<publisher><name>Addison-Wesley</></> <title> $t</> <author> $a</> </> IN " CONSTRUCT <result> </> © 2002 by Prentice Hall

458 XML-QL (continued) <bib> <book year="1995">
<!-- A good introductory text --> <title> An Introduction to Database Systems </title> <author> <lastname> Date </lastname> </author> <publisher> <name> Addison-Wesley </name > </publisher> </book> <book year="1998"> <title> Foundation for Object/Relational Databases: The Third Manifesto </title> <author> <lastname> Darwen </lastname> </author> </bib> © 2002 by Prentice Hall

459 XML-QL (continued) <result>
<author> <lastname> Date </lastname> </author> <title> An Introduction to Database Systems </title> </result> <title> Foundation for Object/Relational Databases: The Third Manifesto </title> <author> <lastname> Darwen </lastname> </author> © 2002 by Prentice Hall

460 XML-QL (continued) WHERE <book > $p</> IN " <title > $t</>, <publisher><name>Addison-Wesley</>> IN $p CONSTRUCT <result> <title> $t </> WHERE <author> $a </> IN $p CONSTRUCT <author> $a</> </> © 2002 by Prentice Hall

461 XML-QL (continued) <result>
<title> An Introduction to Database Systems </title> <author> <lastname> Date </lastname> </author> </result> <title> Foundation for Object/Relational Databases: The Third Manifesto </title> <author> <lastname> Darwen </lastname> </author> © 2002 by Prentice Hall

462 XML-QL (continued) WHERE <article> <author>
<firstname> $f </> // firstname $f <lastname> $l </> // lastname $l </> </> CONTENT_AS $a IN " <book year=$y> <firstname> $f </> // join on same firstname $f <lastname> $l </> // join on same lastname $l </> IN " y > 1995 CONSTRUCT <article> $a </> © 2002 by Prentice Hall

463 XML-QL (continued) © 2002 by Prentice Hall

464 XML-QL (continued) <!ATTLIST person ID ID #REQUIRED>
<!ATTLIST article author IDREFS #IMPLIED> © 2002 by Prentice Hall

465 XML-QL (continued) <person ID="o123">
<firstname>John</firstname> <lastname>Smith<lastname> </person> <person ID="o234"> . . . <article author="o123 o234"> <title> ... </title> <year> 1995 </year> </article> © 2002 by Prentice Hall

466 XML-QL (continued) © 2002 by Prentice Hall

467 XML-QL (continued) WHERE <article author=$i>
WHERE <article><author><lastname> $n</></></> IN "abc.xml” WHERE <article author=$i> <title> </> ELEMENT_AS $t </>, <person ID=$i> <lastname> </> ELEMENT_AS $l </> CONSTRUCT <result> $t $l</> © 2002 by Prentice Hall

468 Scalar values <title>A Trip to <titlepart> the Moon </titlepart></title> NOT! <title><CDATA> A Trip to </CDATA><titlepart><CDATA> the Moon</CDATA></titlepart></title> YES © 2002 by Prentice Hall

469 Tag variables WHERE <$p> <title> $t </title>
<year>1995</> <$e> Smith </> </> IN " $e IN {author, editor} CONSTRUCT <$p> </> © 2002 by Prentice Hall

470 Transforming data <!ELEMENT book (author+, title, publisher)>
<!ATTLIST book year CDATA> <!ELEMENT article (author+, title, year?, (shortversion|longversion))> <!ATTLIST article type CDATA> <!ELEMENT publisher (name, address)> <!ELEMENT author (firstname?, lastname)> <!ELEMENT person (lastname, firstname, address?, phone?, publicationtitle*)> © 2002 by Prentice Hall

471 Transforming data (cont’d)
WHERE <$> <author> <firstname> $fn </> <lastname> $ln </> </> <title> $t </> </> IN " CONSTRUCT <person ID=PersonID($fn, $ln)> <firstname> $fn </> <publicationtitle> $t </> © 2002 by Prentice Hall

472 Integrating data from different sources
WHERE <person> <name></> ELEMENT_AS $n <ssn> $ssn</> </> IN " <taxpayer> <income></> ELEMENT_AS $i </> IN " CONSTRUCT <result> $n $i </> © 2002 by Prentice Hall

473 Query blocks WHERE <$e> <title> $t </>
<year> 1995 </> </> CONTENT_A $p IN " CONSTRUCT <result ID=ResultID($p)> <title> $t </> </> { WHERE $e = "journal-paper", <month> $m </> IN $p CONSTRUCT <result ID=ResultID($p)> <month> $m </> </> } { WHERE $e = "book", <publisher>$q </> IN $p CONSTRUCT <result ID=ResultID($p)> <publisher>$q </> </> © 2002 by Prentice Hall

474 WSQ © 2002 by Prentice Hall

475 Web-supported queries
SIGMOD2000 (Goldman and Widom) WebPages (SearchExp,T1,T2,…,Tn,URL,Rank, Date) SELECT NAME, COUNT FROM STATES, WEBCOUNT WHERE NAME = T1 ORDER BY COUNT DESC © 2002 by Prentice Hall

476 KDD: Data Mining © 2002 by Prentice Hall

477 The big problem Billions of records
A small number of interesting patterns “Data rich but information poor” © 2002 by Prentice Hall

478 Data mining Knowledge discovery Knowledge extraction
Data/pattern analysis © 2002 by Prentice Hall

479 Types of source data Relational databases Transactional databases
Web logs Textual databases © 2002 by Prentice Hall

480 Association rules 65% of all customers who buy beer and tomato sauce also buy pasta and chicken wings Association rules: X Y © 2002 by Prentice Hall

481 Association analysis IF 20 < age < 30 AND
20K < INCOME < 30K THEN Buys (“CD player”) SUPPORT = 2%, CONFIDENCE = 60% © 2002 by Prentice Hall

482 Basic concepts Minimum support threshold Minimum confidence threshold
Itemsets Occurrence frequency of an itemset © 2002 by Prentice Hall

483 Association rule mining
Find all frequent itemsets Generate strong association rules from the frequent itemsets © 2002 by Prentice Hall

484 Support and confidence
Support (X) Confidence (X  Y) = Support(X+Y) / Support (X) © 2002 by Prentice Hall

485 Example TID List of items IDs T100 I1, I2, I5 T200 I2, I4 T300 I2, I3
I1, I2, I3, I5 T900 I1, I2, I3 © 2002 by Prentice Hall

486 Example (cont’d) Frequent itemset l = {I1, I2, I5}
I1 AND I2  I C = 2/4 = 50% I1 AND I5  I2 I2 AND I5  I1 I1  I2 AND I5 I2  I1 AND I5 I3  I1 AND I2 © 2002 by Prentice Hall

487 Example 2 TID date items T100 10/15/99 {K, A, D, B} T200
{D, A, C, E, B} T300 10/19/99 {C, A, B, E} T400 10/22/99 {B, A, D} min_sup = 60%, min_conf = 80% © 2002 by Prentice Hall

488 Correlations Corr (A,B) = P (A OR B) / P(A) P (B)
If Corr < 1: A discourages B (negative correlation) (lift of the association rule A  B) © 2002 by Prentice Hall

489 Contingency table Game ^Game Sum Video 4,000 3,500 7,500 ^Video 2,000
2,500 6,000 10,000 © 2002 by Prentice Hall

490 Example P({game}) = 0.60 P({video}) = 0.75 P({game,video}) = 0.40
P({game,video})/(P({game})x(P({video})) = 0.40/(0.60 x 0.75) = 0.89 © 2002 by Prentice Hall

491 Example 2 hotdogs ^hotdogs Sum hamburgers 2000 500 2500 ^hamburgers
1000 1500 3000 5000 © 2002 by Prentice Hall

492 Classification using decision trees
Expected information need I (s1, s2, …, sm) = pi log (pi) s = data samples m = number of classes S © 2002 by Prentice Hall

493 RID Age Income student credit buys?
1 <= 30 High No Fair 2 Excellent 3 Yes 4 > 40 Medium 5 Low 6 7 8 9 10 11 12 13 14 no excellent © 2002 by Prentice Hall

494 Decision tree induction
I(s1,s2) = I(9,5) = = - 9/14 log 9/14 – 5/14 log 5/14 = = 0.940 © 2002 by Prentice Hall

495 Entropy and information gain
S S1j + … + smj E(A) = I (s1j,…,smj) s Entropy = expected information based on the partitioning into subsets by A Gain (A) = I (s1,s2,…,sm) – E(A) © 2002 by Prentice Hall

496 Entropy Age <= 30 s11 = 2, s21 = 3, I(s11, s21) = 0.971
Age in s12 = 4, s22 = 0, I (s12,s22) = 0 Age > 40 s13 = 3, s23 = 2, I (s13,s23) = 0.971 © 2002 by Prentice Hall

497 Entropy (cont’d) E (age) = 5/14 I (s11,s21) + 4/14 I (s12,s22) + 5/14 I (S13,s23) = 0.694 Gain (age) = I (s1,s2) – E(age) = 0.246 Gain (income) = 0.029, Gain (student) = 0.151, Gain (credit) = 0.048 © 2002 by Prentice Hall

498 Final decision tree age student credit yes no yes no yes > 40
student credit yes no yes excellent fair no yes no yes © 2002 by Prentice Hall

499 Other techniques Bayesian classifiers
X: age <=30, income = medium, student = yes, credit = fair P(yes) = 9/14 = 0.643 P(no) = 5/14 = 0.357 © 2002 by Prentice Hall

500 Example P (age < 30 | yes) = 2/9 = P (age < 30 | no) = 3/5 = P (income = medium | yes) = 4/9 = P (income = medium | no) = 2/5 = P (student = yes | yes) = 6/9 = P (student = yes | no) = 1/5 = P (credit = fair | yes) = 6/9 = P (credit = fair | no) = 2/5 = 0.400 © 2002 by Prentice Hall

501 Example (cont’d) P (X | yes) = 0.222 x 0.444 x 0.667 x 0.667 = 0.044
P (X | no) = x x x = 0.019 P (X | yes) P (yes) = x = 0.028 P (X | no) P (no) = x = 0.007 Answer: yes/no? © 2002 by Prentice Hall

502 More types of data mining
Classification and prediction Cluster analysis Outlier analysis Evolution analysis © 2002 by Prentice Hall

503 XQuery © 2002 by Prentice Hall

504 Background Successor to XML-QL, YAML, Lorel, Quilt
Supported by the W3C Draft only © 2002 by Prentice Hall

505 DTD <!ELEMENT bib (book* )>
<!ELEMENT book (title, (author+ | editor+ ), publisher, price )> <!ATTLIST book year CDATA #REQUIRED > <!ELEMENT author (last, first )> <!ELEMENT editor (last, first, affiliation )> <!ELEMENT title (#PCDATA )> <!ELEMENT last (#PCDATA )> <!ELEMENT first (#PCDATA )> <!ELEMENT affiliation (#PCDATA )> <!ELEMENT publisher (#PCDATA )> <!ELEMENT price (#PCDATA )> © 2002 by Prentice Hall

506 Sample database © 2002 by Prentice Hall <bib>
<book year="1994"> <title>TCP/IP Illustrated</title> <author> <last>Stevens</last> <first>W.</first> </author> <publisher>Addison-Wesley</publisher> <price> 65.95</price> </book> <book year="1992"> <title>Advanced Programming in the Unix environment</title> <price>65.95</price> <book year="2000"> <title>Data on the Web</title> <last>Abiteboul</last> <first>Serge</first></author> <last>Buneman</last> <first>Peter</first> <last>Suciu</last> <first>Dan</first> <publisher>Morgan Kaufmann Publishers</publisher> <price>39.95</price> </bib> © 2002 by Prentice Hall

507 Sample query <bib> {
for $b in document(" where $b/publisher = "Addison-Wesley“ and > 1991 return <book year="{ }"> { $b/title } </book> } </bib> © 2002 by Prentice Hall

508 Expected result <bib> <book year="1994">
<title>TCP/IP Illustrated</title> </book> <book year="1992"> <title>Advanced Programming in the Unix environment</title> </bib> © 2002 by Prentice Hall

509 Pointers and Demos http://www.w3.org/TR/xquery/
© 2002 by Prentice Hall

510 Data Mining (continued)
© 2002 by Prentice Hall

511 arff files @relation weather
@attribute outlook {sunny, overcast, rainy} @attribute temperature real @attribute humidity real @attribute windy {TRUE, FALSE} @attribute play {yes, no} @data sunny,85,85,FALSE,no sunny,80,90,TRUE,no overcast,83,86,FALSE,yes rainy,70,96,FALSE,yes rainy,68,80,FALSE,yes rainy,65,70,TRUE,no overcast,64,65,TRUE,yes sunny,72,95,FALSE,no sunny,69,70,FALSE,yes rainy,75,80,FALSE,yes sunny,75,70,TRUE,yes overcast,72,90,TRUE,yes overcast,81,75,FALSE,yes rainy,71,91,TRUE,no © 2002 by Prentice Hall

512 Predictive models Inputs (e.g., medical history, age)
Output (e.g., will patient experience any side effects) Some models are better than others © 2002 by Prentice Hall

513 Operating curves success optimal practical random failure most likely
least likely © 2002 by Prentice Hall

514 Principles of data mining
Training/test sets Error analysis and overfitting Cross-validation Supervised vs. unsupervised methods error test training input size © 2002 by Prentice Hall

515 Representing data Vector space credit pay off default salary
© 2002 by Prentice Hall

516 Decision surfaces credit pay off default salary
© 2002 by Prentice Hall

517 Decision trees credit pay off default salary © 2002 by Prentice Hall

518 Linear boundary credit pay off default salary © 2002 by Prentice Hall

519 kNN models Assign each element to the closest cluster Demos:
© 2002 by Prentice Hall

520 Other methods Decision trees Neural networks Support vector machines
Demos © 2002 by Prentice Hall

521 arff files @relation weather
@attribute outlook {sunny, overcast, rainy} @attribute temperature real @attribute humidity real @attribute windy {TRUE, FALSE} @attribute play {yes, no} @data sunny,85,85,FALSE,no sunny,80,90,TRUE,no overcast,83,86,FALSE,yes rainy,70,96,FALSE,yes rainy,68,80,FALSE,yes rainy,65,70,TRUE,no overcast,64,65,TRUE,yes sunny,72,95,FALSE,no sunny,69,70,FALSE,yes rainy,75,80,FALSE,yes sunny,75,70,TRUE,yes overcast,72,90,TRUE,yes overcast,81,75,FALSE,yes rainy,71,91,TRUE,no © 2002 by Prentice Hall

522 Weka http://www.cs.waikato.ac.nz/ml/weka Methods: rules.ZeroR
bayes.NaiveBayes trees.j48.J48 lazy.IBk trees.DecisionStump © 2002 by Prentice Hall

523 kMeans clustering java weka.clusterers.SimpleKMeans -t data/weather.arff © 2002 by Prentice Hall

524 More useful pointers http://www.kdnuggets.com/
© 2002 by Prentice Hall

525 Chapter 15 ODBC, OLE DB, ADO, and ASP Database Processing
Eighth Edition Chapter 15 David M. Kroenke ODBC, OLE DB, ADO, and ASP © 2002 by Prentice Hall

526 Internet Application Data Needs
© 2002 by Prentice Hall

527 The Role of Standards Without standardized database interfaces, integrating diverse data would be extraordinarily difficult. Standardized interfaces include: ODBC, OLE DB, ADO, and ASP © 2002 by Prentice Hall

528 Open Database Connectivity (ODBC)
ODBC is an interface by which programs can access SQL databases in a DBMS-independent manner This allows programmers to avoid having to learn each individual DBMS product It also allows programs to be developed without concern to the particular relational DBMS product © 2002 by Prentice Hall

529 ODBC Role © 2002 by Prentice Hall

530 ODBC Terminology Data Source Driver Manager Driver
The database, its associated DBMS, operating system, and network platform Driver Manager Intermediary between the application and DBMS drivers Driver Processes ODBC requests and submits SQL statements to a data source © 2002 by Prentice Hall

531 ODBC Conformance At one extreme, you want simplicity and ease of compliance. At the other extreme, you want the full power of the DBMS which makes it more complex. © 2002 by Prentice Hall

532 Driver’s Application Program Interface (API)
A driver’s API is a set of functions that the application can call to receive services. APIs are used to define the ODBC Conformance Levels © 2002 by Prentice Hall

533 Summary of ODBC Conformance Levels
© 2002 by Prentice Hall

534 SQL Conformance Levels
Similar to the ODBC conformance levels, degree of compliance have been established for SQL © 2002 by Prentice Hall

535 Summary of SQL Conformance Levels
© 2002 by Prentice Hall

536 ODBC Data Source To access an ODBC database, a data source must be defined The data source identifies the database location and the DBMS Data sources are defined by the extent to which the ODBC is available to others © 2002 by Prentice Hall

537 ODBC Types File Data Source System Data Source User Data Source
The ODBC data is available to multiple users from different systems System Data Source The ODBC data is available to all users on the local system User Data Source The ODBC data is only available to the user who created it © 2002 by Prentice Hall

538 Object Linking and Embedding Database (OLE DB)
OLE DB provides an object-oriented interface to data of almost any type OLE DB supports processing from non-relational database and from ODBC interfaces OLE DB objects may provide access to a programs native libraries (thereby providing exposure for those libraries/functions) © 2002 by Prentice Hall

539 OLE DB Role © 2002 by Prentice Hall

540 OLE DB Goals © 2002 by Prentice Hall

541 Object Terminology Abstraction - a generalization of something
Method - actions that an object can perform Property - a characteristic of an abstraction Collection - an object that contains other objects © 2002 by Prentice Hall

542 Active Data Object (ADO)
ADO Controls allow programmers to access OLE DB objects from just about any programming language A simple object model for OLE DB Is Microsoft’s data access standard Data access objects are the same for all types of OLE DB data © 2002 by Prentice Hall

543 Role of ADO © 2002 by Prentice Hall

544 ADO Object Model © 2002 by Prentice Hall

545 Active Server Pages (ASP)
ASP contains DHTML, XML, and/or scripting language statements (usually VBScript) ASP may be created using a text editor. However, tools such as Microsoft FrontPage simplify their creation. © 2002 by Prentice Hall

546 Internet Information Server (IIS)
IIS is a web server built into Windows 2000 professional and Windows NT IIS recognized .asp extensions as input to the ASP program <% statement(s) %> are statement(s) processed on the web server computer. Otherwise the code is interpreted by the user’s browser © 2002 by Prentice Hall

547 JDBC, Java Server Pages, and MySQL
Database Processing Eighth Edition Chapter 16 David M. Kroenke JDBC, Java Server Pages, and MySQL © 2002 by Prentice Hall

548 Open-Source Software Each of the following are open-source programs that will run in open environments (e.g., Unix and Linux) and many proprietary systems (e.g., Windows): JDBC (not an acronym) Java Server Pages (JSP) using Apache/Tomcat MySQL (an open-source DBMS developed by Mark Mathews) © 2002 by Prentice Hall

549 JDBC JDBC allows you to connect to many different databases
For a listing of drivers see The MySQL open-source driver (developed by Mark Mathews) and may be downloaded from: © 2002 by Prentice Hall

550 JDBC Driver Types Type 1 JDBC-ODBC bridge drivers Type 2
Connects to the native API of the DBMS Type 3 Translates JDBC into DBMS-independent network protocol Type 4 Translates JDBC into DBMS-specific network protocol © 2002 by Prentice Hall

551 Machine-Independent Bytecode
Java was designed to be portable. Java is not compiled into machine language It is compiled into machine-independent bytecode. Bytecode is interpreted by the Java virtual machine (a program that is needed to run Java programs) © 2002 by Prentice Hall

552 Java Performance While bytecode provides portability, since it must be interpreted, it is not as fast as code that has been translated into machine language © 2002 by Prentice Hall

553 Java Applet An applet is Java bytecode that is designed to run on a client Applet bytecode is sent to the client machine using HTTP. It is read and interpreted by the Web browser. Most, if not all, Web browsers now run the Java virtual machine © 2002 by Prentice Hall

554 Java Servlet A servlet is a Java program invoked via HTTP on the Web server. The servlet uses the Java virtual machine running on the server. © 2002 by Prentice Hall

555 JDBC Driver Types mappings
Applet Servlet Type 1 Use ODBC, single-tier architectures only. Type 2 Generally, only supports single-tier architectures Type 3 Yes, supports n-tier architectures Type 4 Yes, supports n-tier architectures (faster than Type 3) © 2002 by Prentice Hall

556 Using JDBC The connection string information for JDBC is embedded in the Java code via the JDBC driver. To successfully connect the bytecode must… Load the driver Establish a connection to the database Create a statement Processing the statement © 2002 by Prentice Hall

557 Loading the Driver The directory containing the driver library must be part of the CLASSPATH for the Java compiler and the Java virtual machine. While there are several ways to load the drivers, the following is one of the most reliable… Class.forName(“nameofdriver”).newInstance(); © 2002 by Prentice Hall

558 Establishing a Connection to the database
Create an object that has a connection to the database… Connection Conn = DriverManager.getConnection(“connectionString”); e.g., DriverManager.getConnection (“jdbc:mysql://localhost/db1? user=abc&password=pwd”) © 2002 by Prentice Hall

559 Details Regarding the JDBC Connection String
connectionString has three parts (each part delimited with a colon)… Part 1: jdbc: Part 2: a keyword that identifies the DBMS e.g., mysql: Part 3: a URL for the database e.g., //localhost/db1?user=abc&password=pwd © 2002 by Prentice Hall

560 Creating a Statement A statement is created by instantiating a new Statement object Statement Stmt = Conn.createStatement(); © 2002 by Prentice Hall

561 Processing the Statement
The driver’s API documentation will provide details on what statements are available. However, the core statements are standard. Note: a driver’s API is a set of functions that the program may call to receive services. © 2002 by Prentice Hall

562 Processing the Statement –Examples
ResultSet RS = Stmt.executeQuery (“select * from tab”); int result = Stmt.executUpdate (“update tab set name=‘abc’ where id = 1”); © 2002 by Prentice Hall

563 Java Server Pages (JSP)
Java Server Pages (JSP) provide a means of creating dynamic Web pages using HTTP, XML, and Java. JSP only allows for Java coding, ASP (as you may recall) only allows for JavaScript or VBScript coding. © 2002 by Prentice Hall

564 JSP Inherits the Power and Portability of Java
Since Java is powerful and platform-independent so is JSP. JSP Specifications are located at: © 2002 by Prentice Hall

565 JSP and Servlets JSP are transformed into standard Java code, then they are compiled into bytecode (just like a regular Java program) © 2002 by Prentice Hall

566 JSP –subclasses of HttpServlet class
JSP are subclasses of the HttpServlet class Consequently, due to inheritance, you may embed Java code enclosed by <% and %> directly into JSP. © 2002 by Prentice Hall

567 Web Server Applications
To run JSP, the Web server must implement: Java servlet 2.1+ and Java Server Pages 1.0+ © 2002 by Prentice Hall

568 Apache Tomcat A common Web server application which includes these is Apache Tomcat: Tomcat may be run in conjunction with Apache (in a production environment) or standalone (in a development environment) © 2002 by Prentice Hall

569 MySQL MySQL is an open-source DBMS product that runs on Unix, Linux, and Windows. While MySQL is extremely inexpensive and provides many capabilities, it is not as powerful as commercial products, such as Oracle and SQL Server. © 2002 by Prentice Hall

570 MySQL MySQL provides quick and efficient query handling.
The product allows you to create users, databases, tables, auto incrementing fields, etc. © 2002 by Prentice Hall

571 JDBC Connections In some situations (like when using MySQL) the localhost host designator may not work as intended. The issue is rooted in how the DBMS interpret the localhost parameter. If it attempts to use sockets rather than TCP/IP (as JDBC expects), the connection will not be established. © 2002 by Prentice Hall

572 JDBC localhost Workaround
A work-around allows you to grant access to the for the specific account The wildcard % states that the database may be accessed from any host Alternatively, you may supply the specific IP address for your local machine –this provides better security © 2002 by Prentice Hall

573 Sharing Enterprise Data
Database Processing Eighth Edition Chapter 17 David M. Kroenke Sharing Enterprise Data © 2002 by Prentice Hall

574 Enterprise Database Processing Architectures
Many organizations have a variety of database architectures. Enterprise database processing is concerned with the challenges associated with merging these different architectures into a single view of the organizational data. © 2002 by Prentice Hall

575 Database Processing Architectures
Teleprocessing Systems Client-Server Systems File-Sharing Systems Distributed Database Systems © 2002 by Prentice Hall

576 Teleprocessing Systems
All processing is done by one computer. Users may use dumb terminals to transmit information to the centralized computer. © 2002 by Prentice Hall

577 Relationship of Programs in a Teleprocessing System
© 2002 by Prentice Hall

578 Client-Server Systems
Client-Server processing is a form of cooperative computing. Client computers and servers, using a network, share the computing burden. DBMS functionality is provided by one computer, typically the server. © 2002 by Prentice Hall

579 Client-Server Architecture
© 2002 by Prentice Hall

580 File-Sharing Systems Files are shared between servers and client computers. The server does not provide DBMS functionality. © 2002 by Prentice Hall

581 File-Sharing Architecture
© 2002 by Prentice Hall

582 Distributed Database Systems
Distributed Databases store portions of the database on multiple systems that are interconnected using a network. As such, no one system contains the entire database. © 2002 by Prentice Hall

583 Distributed Database Architecture
© 2002 by Prentice Hall

584 Data Partitioning Vertical Fragment Horizontal Fragment
This refers to a table that is divided based on columns Horizontal Fragment This refers to a table that is divided based on the values of the data Mixed Partitions These systems have both Vertical and Horizontal fragments © 2002 by Prentice Hall

585 Data Replication Data replication is when the DBMS maintains multiple copies of the same database on different computers. © 2002 by Prentice Hall

586 Types of Distributed Databases
Partitioned, non-replicated Non-partitioned, replicated Partitioned, replicated © 2002 by Prentice Hall

587 Distributed Database Criteria
Parallelism Independence Flexibility Availability Cost/Complexity Control Security © 2002 by Prentice Hall

588 Downloading Data Data may be pulled from a server-based DBMS and downloaded to a client. © 2002 by Prentice Hall

589 Issues in Downloading Data
Coordination Consistency Access Control Computer Crime © 2002 by Prentice Hall

590 On Line Analytic Processing (OLAP)
OLAP (oh-lap) is an on-line system that analyzes and presents data in a particular manner. The data categories are called axes or dimensions. This is termed an OLAP Cube. There are no limits on the number of axes. If a large number of axes are used, it is termed an OLAP Hypercube © 2002 by Prentice Hall

591 OLAP Terminology © 2002 by Prentice Hall

592 Relational Source Data for an OLAP Cube
© 2002 by Prentice Hall

593 An OLAP Cube © 2002 by Prentice Hall

594 Data Warehouse A data warehouse is a store of enterprise data (and procedures) that is designed to facilitate management decision making A data warehouse includes data, tools, procedures, training, personnel, and other resources that are required or that make decision making easier The data comes from many different sources and may output to many different sources © 2002 by Prentice Hall

595 Data Warehouse © 2002 by Prentice Hall

596 Data Warehouse Components
© 2002 by Prentice Hall

597 Categories of Data Warehouse Requirements
© 2002 by Prentice Hall

598 Data Warehouse Challenges
Inconsistent Data Tool Integration Missing Warehouse Data Management Tools Ad Hoc Nature of Requirements © 2002 by Prentice Hall

599 Data Mart A data mart is a facility akin to a data warehouse but for a much smaller domain The goal of the data mart is to provide the functionality of a data warehouse within a limited domain © 2002 by Prentice Hall

600 Data Administration Data is an critical and expensive to acquire resource to an organization. As such, careful administrative procedures and controls are required. © 2002 by Prentice Hall

601 Data Administration Challenges
© 2002 by Prentice Hall

602 Data Administration Functions
© 2002 by Prentice Hall

603 Object-Oriented Database Processing
Eighth Edition Chapter 18 David M. Kroenke Object-Oriented Database Processing © 2002 by Prentice Hall

604 Object Oriented DBMS (OODBMS)
Object Oriented DBMS (OODBMS) provide the ability to persistently store objects created in Object Oriented programming languages like Java, C#, and C++ © 2002 by Prentice Hall

605 Why not use a Traditional Relational DBMS?
The traditional Relational DBMS stores data in tables, rows, and columns Objects have several complex structures that cannot be represented in tables, rows, or columns. These structures include executable statements (i.e., methods) and pointers © 2002 by Prentice Hall

606 OODBMS has Not Caught-On
Recognizing that OODBMS is relatively new, very complicated, and very expensive, the technology has not been overly successful. © 2002 by Prentice Hall

607 How are the Relational Database (RDBMS) Manufacturers Responding?
The manufacturers of RDBMS are incorporating additional features to allow for the storage of more complex items. Oracle has been particularly active in incorporating these features. The term object-relational DBMS has been coined to describe this classification of DBMS. © 2002 by Prentice Hall

608 Object Oriented Programming (OOP)
Object Oriented Programming (OOP) involves a new way of thinking about programming structures. In OOP, the data and instructions are combined into objects. In traditional programming, the data and instructions are disjointed. © 2002 by Prentice Hall

609 OOP Terminology Encapsulated Encapsulated Structure Interface
complete unto itself Encapsulated Structure an OOP object that has both attributes (properties) and methods Interface external appearance of an object © 2002 by Prentice Hall

610 OOP Terminology Implementation Inheritance Polymorphism
the encapsulated internals of an object Inheritance automatically assuming the attributes and methods of another object at a higher class Polymorphism situation in which one name can be used to invoke different functions © 2002 by Prentice Hall

611 OOP Terminology Object Class Object Class Library Object
the logical structure of an object (name, attributes, methods) Object Class Library a group of object classes Object an instance of an object class Transient vs. Persistent volatile (i.e., temporal) vs. permanent © 2002 by Prentice Hall

612 OOP Example © 2002 by Prentice Hall

613 Object Persistence To make an object persistent, the data and structure embedded in the object must be stored. © 2002 by Prentice Hall

614 Object Persistence Example
© 2002 by Prentice Hall

615 Swizzling Swizzling is the process of transforming permanent identifiers into in-memory addresses © 2002 by Prentice Hall

616 Tasks for Object Persistence
© 2002 by Prentice Hall

617 Application Development Tasks for Object Persistence using Various Architectures
© 2002 by Prentice Hall

618 Object Persistence using Oracle
Oracle saves objects in one of four types: Column Objects Variable Length Arrays Nested Tables Row Objects © 2002 by Prentice Hall

619 Oracle’s Column Object
Create Type obj_name as Object ( aname Varchar2(15), aphone Char (10), asalary Number); © 2002 by Prentice Hall

620 Oracle’s Variable Length Array
Create Type apt_unit As Object ( aptnbr char (5), nbrbeds int); Create Type aptlist1 As Varray(20) of apt_unit; © 2002 by Prentice Hall

621 Oracle’s Nested Tables
Create Type apt_unit As Object ( aptnbr char (5), nbrbeds int); Create Type aptlist2 As Table of apt_unit; © 2002 by Prentice Hall

622 Oracle’s Row Objects Create Type obj_apt As Object (
aptname varchar2 (15), aptnbr number); Create Table apartments Of obj_apt; © 2002 by Prentice Hall

623 OODBMS Advantages and Disadvantages
© 2002 by Prentice Hall

624 ODBMS Standards SQL3 an extension to SQL92 that includes support for OODBMS Abstract data type (ADT) user-defined structure that is equivalent to an OOP object © 2002 by Prentice Hall

625 Object Data Management Group’s ODMG-93 Report
The Object Data Management Group (ODMG), a consortium of object database vendors and experts, developed a definition of interfaces for object data management products (ODMG-93). © 2002 by Prentice Hall

626 Key Elements of the ODMG Object Model
© 2002 by Prentice Hall

627 ODMG Relationship Operations
© 2002 by Prentice Hall


Download ppt "Course logistics © 2002 by Prentice Hall."

Similar presentations


Ads by Google