Presentation is loading. Please wait.

Presentation is loading. Please wait.

Santa Clara UniversityCOEN 178 Holliday1–1 COEN 178 Database Systems JoAnne Holliday (best way to reach me) Office: Engineering.

Similar presentations


Presentation on theme: "Santa Clara UniversityCOEN 178 Holliday1–1 COEN 178 Database Systems JoAnne Holliday (best way to reach me) Office: Engineering."— Presentation transcript:

1 Santa Clara UniversityCOEN 178 Holliday1–1 COEN 178 Database Systems JoAnne Holliday Email: jholliday@scu.edu (best way to reach me) Office: Engineering 247, (408) 551-1941 Office Hours: Mon,Tues 3:30-4:45 and by appointment Class web page: http://www.cse.scu.edu/~jholliday/ Two midterms, a project and a final exam T.A. – James Dong

2 Santa Clara UniversityCOEN 178 Holliday1–2 Textbooks and Meetings Required: A First Course in Database Systems, by Ullman and Widom (second edition), Prentice Hall, 2002. Recommended: Oracle 8 Programming, A Primer, (fourth edition), by R. Sunderraman, Addison-Wesley Longman, 2000. Class Meetings: Lecture MWF 1:00-2:05pm, Engr 602 Lab: W or F 2:15-5:00 608B

3 Santa Clara UniversityCOEN 178 Holliday1–3 Grading Lab work and instructor discretion: 10% of grade. Project: 15% of grade. 2 Midterms for a total of 40% of grade. Last midterm: 35% of grade.

4 Santa Clara UniversityCOEN 178 Holliday1–4 Project You will build an application using a relational database system (Oracle8i). The project has 2 parts, starting with design and ending up with a complete application. The project should be written in Java and use the JDBC or written in Perl. Java is the preferred language.

5 Santa Clara UniversityCOEN 178 Holliday1–5 Why take this class? This class may seem easy, but there is a theoretical part which many students find difficult – don’t be caught sleeping!! The benefits of accepting data constraints. Of all courses you take at SCU, this may be the one that gets you a job.

6 Santa Clara UniversityCOEN 178 Holliday1–6 Schedule Today: Sept. 19 (M) u Intro, Entity-Relationship Model. u Read Chapter 1 and Sections 2.1-2.2. Sept 21 (W) u Weak Entity Sets, Entity-Relationship Design. u Read Sections 2.3-2.4. Sept 23 (F) u Relational Model, Functional Dependencies. u Read Sections 3.1-3.5.

7 Santa Clara UniversityCOEN 178 Holliday1–7 Syllabus Chapter 1. Overview of database management systems. (1) Chapter 2. ERD’s, principles of modeling data and constraints. (2) Chapter 3. The relational data model, functional dependencies and normal forms. (4) Chapter 5 (5.1-5.2 only). Theoretical background of the relational model. (1) Chapter 6. Queries and Updates. (3) Chapter 7. Constraints and Triggers (2) Chapter 8 (sec 6,7) Transactions and Security. (2) Indexing and the DBA (2)

8 Santa Clara UniversityCOEN 178 Holliday1–8 Definitions A database is a collection of (related) data. Database Management System (DBMS) is the hardware/software package that facilitates the creation and maintenance of a computerized database. In a relational database, the tables are relations, the rows are tuples and there are mathematically well defined operations on relations (relational algebra).

9 Santa Clara UniversityCOEN 178 Holliday1–9 Benefits of a DBMS 1. Manages very large amounts of data. 2. Supports efficient access to data through indexing and a rich query language. 3. Supports concurrent access to data. u Example: bank and its ATM machines. 4. Supports secure, atomic access to very large amounts of data. u Contrast two people editing the same UNIX file – last to write “wins” – with the problem if two people deduct money from the same account via ATM machines at the same time – new balance is wrong whichever writes last.

10 Santa Clara UniversityCOEN 178 Holliday1–10 More Benefits of a DMBS Controls redundancy in data storage Protects against unauthorized access of data Enforces integrity constraints Provides backup and recovery services Enforces user-defined standards Provides data abstraction through schemas.

11 Santa Clara UniversityCOEN 178 Holliday1–11 Relational Model Based on tables, like the Account table: acct #namebalance 12345Sally1000.21 34567Sue 285.48 …… … Today used in most DBMS's. DB schema Account=(acct#,name,balance) and DB instance

12 Santa Clara UniversityCOEN 178 Holliday1–12 The DBMS Marketplace Relational DBMS companies – Oracle, Sybase – are among the largest software companies in the world. IBM offers its relational DB2 system. With IMS, a nonrelational system, IBM is by some accounts the largest DBMS vendor in the world. Microsoft offers SQL-Server, plus Microsoft Access for the cheap DBMS on the desktop, answered by “lite” systems from other competitors. Relational companies also challenged by “object-oriented DB” companies. But countered with “object-relational” systems, which retain the relational core while allowing type extension as in OO systems.

13 Santa Clara UniversityCOEN 178 Holliday1–13 Three Aspects to Studying DBMS's 1. Modeling and design of databases. u Allows exploration of issues before committing to an implementation. 2. Programming: queries and DB operations like update. u SQL = “intergalactic dataspeak.” 3.DBMS implementation. (concurrency control- 2PL, backup and recovery- logging, query optimization)  COEN178 = (1) + (2)

14 Santa Clara UniversityCOEN 178 Holliday1–14 Forming Queries Department DeptManager Data definition language (DDL) creates the schema and metadata CREATE TABLE Account (…..); Data Manipulation Language (DML) Query (SELECT), UPDATE,DELETE In the SQL query language: SELECT Manager FROM Department WHERE Department.Dept = ‘accounting’ Schema is Department = (Dept,Manager)

15 Santa Clara UniversityCOEN 178 Holliday1–15 Host Languages C, C++, Java, Lisp Application prog. Local Vars DBMS Calls to DB Host language is completely general (Turing complete) but gives you no support Query language—less general "non procedural" and optimizable (Memory) (Storage)

16 Santa Clara UniversityCOEN 178 Holliday1–16 Relational model is good for: Large amounts of data —> simple operations Navigate among small number of relations Difficult Applications for relational model (complex objects and relationships: VLSI Design (CAD in general) CASE Graphical Data CPU ALU ADDER Adder A FA ALU ADDER Bill of Materials or transitive closure

17 Santa Clara UniversityCOEN 178 Holliday1–17 Other Models Where number of "relations" is large, relationships are complex Object Data Model Logic Data Model OBJECT DATA MODEL 1.Complex Objects – Nested Structure (pointers or references) 2.Encapsulation, set of Methods/Access functions 3.Object Identity 4.Inheritance – Defining new classes like old classes Object model: usually find objects via explicit navigation Also query language in some systems

18 Santa Clara UniversityCOEN 178 Holliday1–18 LOGIC (Horn Clause) DATA MODEL Prolog, Datalog if A1 and A2 then B prolog B:- A1 and A2 Functions s(5) = 6 (successor) Predicates with Arguments sum(X,Y,Z) X + Y = Z sum(X,0,X) means X + 0 = X (always true for all X) sum(X,s(Y),s(Z)):-sum(X,Y,Z) means X+(Y+1) = (Z+1) if X + Y = Z More power than relational model Can Compute Transitive Closure edge(X,Y) path(X,Y) :- edge(X,Y) path(X,Z) :- path(X,Y) & edge(Y,Z)

19 Santa Clara UniversityCOEN 178 Holliday1–19 Students Entity/Relationship Diagrams A model where diagrams represent designs. Entity like object, = “thing.” Entity set like class = set of “similar” entities/objects. Attribute = property of entities in an entity set, similar to fields of a struct. In diagrams, entity set  rectangle; attribute  oval. ID namephone major

20 Santa Clara UniversityCOEN 178 Holliday1–20 Relationships Connect two or more entity sets. Represented by diamonds. StudentsCourses Taking

21 Santa Clara UniversityCOEN 178 Holliday1–21 Relationship Set Think of the “value” of a relationship set as a table. One column for each of the connected entity sets. One row for each of the entities, one from each set, that are connected by the relationship. StudentsCourses SallyCOEN178 SallyCOEN111 JoeCOEN178 ……

22 Santa Clara UniversityCOEN 178 Holliday1–22 Multiway Relationships Usually binary relationships (connecting two E.S.) suffice. However, there are some cases where three or more E.S. must be connected by one relationship. Example: relationship among students, courses, TA's (and graders). Possibly, this E/R diagram is OK: StudentsCourses Taking Assisting TA/Graders

23 Santa Clara UniversityCOEN 178 Holliday1–23 Multiway Relationships Works in COEN178, because each TA (or grader) is a TA of all students. Connection student-TA is only via the course. But what if students were divided into sections, with different TAs? u Then, a student in COEN178 would be related to only one of the TA's. Which one? Need a 3-way relationship to tell.

24 Santa Clara UniversityCOEN 178 Holliday1–24 StudentsCoursesTAs AnnCS180Jan SueCS180Pat BobCS180Jan ……… Students Courses TAs Enrolls

25 Santa Clara UniversityCOEN 178 Holliday1–25 Beers-Bars-Drinkers Example Example of complex relationships. nameaddrlicense namemanfnameaddr BeersDrinkers Bars Serves Frequents Likes

26 Santa Clara UniversityCOEN 178 Holliday1–26 Multiplicity of Relationships Representation of Many-One Arrow pointing to “at most one.” Rounded arrow = “exactly one.” Many-many Many-oneOne-one

27 Santa Clara UniversityCOEN 178 Holliday1–27 Example: Drinkers Have Favorite Beers nameaddrlicense namemanfnameaddr BeersDrinkers Bars Serves Frequents Likes Favorite

28 Santa Clara UniversityCOEN 178 Holliday1–28 Many-One Relationships A bar has one best seller – many bars may have the same one. Is the rounded arrow justified? Alternate notation: total participation BarsBeers Best- seller BarsBeers Best- seller

29 Santa Clara UniversityCOEN 178 Holliday1–29 Attributes on Relationships Shorthand for 3-way relationship: BarsBeers Sells price BarsBeers Sells price Prices

30 Santa Clara UniversityCOEN 178 Holliday1–30 A true 3-way relationship. u Price depends jointly on beer and bar. Notice arrow convention for multiway relationships: “all other E.S. determine one of these.” u Not sufficiently general to express any possibility. u However, if price, say, depended only on the beer, then we could use two 2-way relationships: price-beer and beer-bar. u Or better: just make price an attribute of beer.

31 Santa Clara UniversityCOEN 178 Holliday1–31 Converting Multiway to 2-Way Necessary in certain “object-oriented” models. Create a new connecting E.S. to represent rows of a relationship set. u E.g., (Joe's Bar, Bud, $2.50) for the Sells relationship. Many-one relationships from the connecting E.S. to the others. BarsBeers The- Bar Price The- Beer The- Price BBP

32 Santa Clara UniversityCOEN 178 Holliday1–32 Roles Sometimes an E.S. participates more than once in a relationship. Label edges with roles to distinguish. HusbandWife d 1 d 2 d 3 d 4… Drinkers Married husbandwife

33 Santa Clara UniversityCOEN 178 Holliday1–33 Notice Buddies is symmetric, Married not. u No way to say “symmetric” in E/R. Design Question Should we replace husband and wife by one relationship spouse to make it symmetric? Buddy1Buddy2 d 1 d 2 d 1 d 3 d 2 d 1 d 2 d 4… Drinkers Buddies 12

34 Santa Clara UniversityCOEN 178 Holliday1–34 More Design Issues 1. Subclasses. 2. Keys. 3. Weak entity sets.

35 Santa Clara UniversityCOEN 178 Holliday1–35 Subclasses Subclass = special case = fewer entities = more properties. Example: A bank stores records of bank accounts. Savings accounts are a kind of bank account. In addition to the properties (= attributes and relationships) of bank accounts, there is a “interest rate” attribute for savings accounts.

36 Santa Clara UniversityCOEN 178 Holliday1–36 E/R Subclasses Assume subclasses form a tree (no multiple inheritance). isa triangles indicate the subclass relation. name Acc# Accounts Savings a/c rate isa Checking a/c

37 Santa Clara UniversityCOEN 178 Holliday1–37 Multiple Inheritance Theoretically, an E.S. could be a subclass of several other entity sets. nameAcc# Bank account owner Interest instrument Savings A/C isa Certificate of deposit

38 Santa Clara UniversityCOEN 178 Holliday1–38 Problems How to show? A customer can have several loans (or no loans) but each loan is associated with only one (exactly one) customer? A customer can have at most one loan and a loan may be ‘owned’ by several customers? Borrows CustomerLoan

39 Santa Clara UniversityCOEN 178 Holliday1–39 Keys A key is a set of attributes whose values can belong to at most one entity. In E/R model, every E.S. must have a key. u It could have more than one key, but one set of attributes is the “designated” key. In E/R diagrams, you should underline all attributes of the designated key.

40 Santa Clara UniversityCOEN 178 Holliday1–40 Example Suppose acc# is key for Account. acc# is also key for S/A. u In general, key at root is key for all. acc#name Account S/A rate isa

41 Santa Clara UniversityCOEN 178 Holliday1–41 Example: A Multiattribute Key Possibly, the combination of hours + room also forms a key, but we have not designated it as such. dept room Courses numberhours


Download ppt "Santa Clara UniversityCOEN 178 Holliday1–1 COEN 178 Database Systems JoAnne Holliday (best way to reach me) Office: Engineering."

Similar presentations


Ads by Google