Database Management Systems I Alex Coman, Winter 2006

Slides:



Advertisements
Similar presentations
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Advertisements

Ver 1,12/09/2012Kode :CCs 111,sistem basisdataFASILKOM Chapter 2: Relational Model Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan.
Review for Final Test Indra Budi
Weak Entity Sets An entity set that does not have a primary key is referred to as a weak entity set. The existence of a weak entity set depends on the.
Text-Book Chapters (7 and 8) Entity-Relationship Model
Chapter 4: Immediate SQL Complex Queries Complex Queries Views Views Modification of the Database Modification of the Database Joined Relations Joined.
Slides adapted from A. Silberschatz et al. Database System Concepts, 5th Ed. Database Management Systems I Alex Coman, Winter 2006 Entity-Relationship.
©Silberschatz, Korth and Sudarshan1.1Database System Concepts Chapter 1: Introduction Purpose of Database Systems View of Data Data Models Data Definition.
Databases Revision.
SQL Sangeeta Devadiga CS157A, Fall Outline Background Data Definition Basic Structure Set Operation.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Modification of the Database – Deletion Delete all account records at the Perryridge branch.
©Silberschatz, Korth and Sudarshan1.1Database System Concepts Chapter 1: Introduction Purpose of Database Systems View of Data Data Models Data Definition.
©Silberschatz, Korth and Sudarshan1.1Database System Concepts Chapter 1: Introduction Database Management Systems Purpose of Database Systems View of Data.
SPRING 2004CENG 3521 E-R Diagram for the Banking Enterprise.
Slides adapted from A. Silberschatz et al. Database System Concepts, 5th Ed. SQL - part 2 - Database Management Systems I Alex Coman, Winter 2006.
Slides adapted from A. Silberschatz et al. Database System Concepts, 5th Ed. Entity-Relationship Model Database Management Systems I Alex Coman, Winter.
Chapter 2: Entity-Relationship Model (Continued)
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Reduction of an E-R Schema to Tables A database which conforms to an E-R diagram can be represented.
Slides adapted from A. Silberschatz et al. Database System Concepts, 5th Ed. Relational Model Database Management Systems I Alex Coman, Winter 2006.
Dr. Kalpakis CMSC 461, Database Management Systems Introduction.
Dr. Kalpakis CMSC 661, Principles of Database Systems Overview of core undergraduate material.
Entity-Relationship Model
Chapter 3: SQL Data Definition Language Data Definition Language Basic Structure of SQL Basic Structure of SQL Set Operations Set Operations Aggregate.
CS462: Introduction to Database Systems. ©Silberschatz, Korth and Sudarshan1.2Database System Concepts Course Information Instructor  Kyoung-Don (KD)
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 1: Introduction.
Chapter 4 The Relational Model.
Chapter 3 The Relational Model Transparencies Last Updated: Pebruari 2011 By M. Arief
Database System Concepts, 5th Ed. Chapter 6: Entity-Relationship Model.
ADVANCED DATABASES WITH ORACLE 11g FOR ADDB7311 LEARNING UNIT 1 of 7.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries.
3.1 Chapter 3: SQL Schema used in examples p (omit 3.8.2, , 3.11)
Entity-Relationship Model
Chapter 3: Relational Model  Structure of Relational Databases  Normal forms (chap. 7)  Reduction of an E-R Schema to Relational (Sect. 2.9)  Relational.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan Chapter 6: Entity-Relationship Model.
3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational Calculus Domain Relational.
EXAMPLE. Subclasses and Superclasses Entity type may have sub-grouping that need to be represented explicitly. –Example: Employee may grouped into.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts DB Schema Design: the Entity-Relationship Model What’s the use of the E-R model? Entity Sets.
Relational Model By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany) DIRECTOR ARUNAI ENGINEERING COLLEGE TIRUVANNAMALAI.
Entity-Relationship Model Using High-Level Conceptual Data Models for Database Design Entity Types, Sets, Attributes and Keys Relationship Types, Sets,
Computing & Information Sciences Kansas State University Wednesday, 24 Sep 2008CIS 560: Database System Concepts Lecture 12 of 42 Wednesday, 24 September.
Chapter 8: SQL. Data Definition Modification of the Database Basic Query Structure Aggregate Functions.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping.
Chapter 2 : Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping Constraints Keys E-R Diagram Extended E-R Features Design of.
IS 230Lecture 6Slide 1 Lecture 7 Advanced SQL Introduction to Database Systems IS 230 This is the instructor’s notes and student has to read the textbook.
Entity Relationship Diagram (2)
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan Lecture-03 Introduction –Data Models Lectured by, Jesmin Akhter.
ICOM 5016 – Introduction to Database Systems Lecture 5 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,
Chapter 4: SQL Complex Queries Complex Queries Views Views Modification of the Database Modification of the Database Joined Relations Joined Relations.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Extended.
Computing & Information Sciences Kansas State University Friday, 26 Sep 2008CIS 560: Database System Concepts Lecture 13 of 42 Friday, 26 September 2008.
Database and Information Retrieval System
Computing & Information Sciences Kansas State University Wednesday, 03 Sep 2008CIS 560: Database System Concepts Lecture 3 of 42 Wednesday, 03 September.
Mr.Prasad Sawant, MIT Pune India Introduction to DBMS.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan Lecture-03 Introduction –Data Models Lectured by, Jesmin Akhter.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 4: Intermediate.
IS 230Lecture 7Slide 1 Relational Algebra Lecture 8 Text Book – Chapter.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Mapping Constraints Keys.
Chapter 3: Relational Model III Additional Relational Algebra Operations Additional Relational Algebra Operations Views Views.
Lecture 26 Enterprise Systems Development ( CSC447 ) COMSATS Islamabad Muhammad Usman, Assistant Professor.
©Silberschatz, Korth and Sudarshan 1.1 Database System Concepts قواعد البيانات Data Base قواعد البيانات CCS 402 Mr. Nedal hayajneh E- mail
PMIT-6102 Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University.
CHAPTER 1: INTRODUCTION Purpose of Database Systems View of Data Data Models Data Definition Language Data Manipulation Language Storage Management Database.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 1: Introduction.
Relational Model By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany)
Entity-Relationship Model
Chapter 6: Entity-Relationship Model
Presentation transcript:

Database Management Systems I Alex Coman, Winter 2006 Midterm Review Database Management Systems I Alex Coman, Winter 2006

Summary Introduction (Ch. 1) Entity-Relationship Model (Sec. 6.1-6.9) Relational Model and Algebra (Ch. 2) Introduction to SQL (Ch. 3) Advanced SQL (Sec. 4.1-4.5,4.8)

Purpose of Database Systems In the early days, database applications were built directly on top of file systems Drawbacks of using file systems to store data: Data redundancy and inconsistency Difficulty in accessing data Data isolation — multiple files and formats Integrity problems Atomicity of updates Concurrent access by multiple users Security problems Database systems offer solutions to all the above problems

Overall Structure of a DBMS

Database Administrator Coordinates all the activities of the database system; the database administrator has a good understanding of the enterprise’s information resources and needs. Database administrator's duties include: Schema definition Storage structure and access method definition Schema and physical organization modification Granting user authority to access the database Maintenance Specifying integrity constraints Acting as liaison with users Monitoring performance and responding to changes in requirements

Entity-Relatioship Model Design Process characterize the data needs conceptual design (E-R modeling) specification of functional requirements abstract model to implementation (reduction to relational schemas) E-R Modeling entity and entity set relationship and relationship set attributes constraints: keys, cardinality and participation weak entity sets specialization/generalization aggregation Reduction to Relation Schemas

ER Modeling (1) Mapping cardinality constraints Express the number of entities to which another entity can be associated via a relationship set. For a binary relationship: one-to-one, one-to-many, many-to-one, many-to-many Participation constraints Total vs. partial participation Keys for relationship sets The combination of primary keys of the participating entity sets forms a super key of a relationship set Must consider the mapping cardinality of the relationship set when deciding what are the candidate keys

ER Modeling (2) Weak entity set An entity set that does not have a primary key and whose existence depends on the existence of an identifying entity set The primary key of a weak entity set is formed by the primary key of the identifying entity set plus the weak entity set’s discriminator (partial key) “Each geographical location is described by city, province and country and uniquely identified by a location-id. In this context, each 330music store is identified by its address which is unique for a location.” Mapping to relations: location (loc-id,…) stores (loc-id, address,…) has is redundant (why?)

ER Modeling (3) Specialization/generalization A lower-level entity set inherits all the attributes (including the primary key) of the higher-level entity set to which it is linked Lower-level entity sets may have attributes or participate in relationships that do not apply to the higher-level entity set “The preferred customers are uniquely identified by a customer-id, and their names and phone numbers are also available. The preferred customers may belong in one or both of two programs: Fastlane … and Newsletter …” Mapping to relations: customer (cust-id, name,phone) fastlane (cust-id, cc) newsletter (cust-id, email) Alternative representation(is it?): fastlane (cust-id, name,phone, cc) newsletter (cust-id, name, phone, email)

ER Modeling (4) Redundancy of schemas Many-to-one and one-to-many relationship sets that are total on the many-side can be represented by adding an extra attribute to the “many” side, containing the primary key of the “one” side “Each track belongs to a genre (and one genre only) …” Mapping to relations: tracks (track-id, artist, title, length, year, genre-id) genre (genre-id, main, sub, style) has is redundant (why?)

ER Design Issues and Decisions Use of entity sets vs. attributes Choice mainly depends on the structure of the enterprise being modeled, and on the associated semantics Use of entity sets vs. relationship sets Possible guideline is to designate a relationship set to describe an action that occurs between entities Binary versus n-ary relationship sets Use n-ary relationship set when it shows more clearly that several entities participate in a single relationship (eg: 330music history). Mapping cardinalities affect ER design Placement of relationship attributes Use of a strong or weak entity set Use of specialization/generalization

E-R Diagram for a Banking Enterprise Mapping to relations (partial): payment (loan-number, payment-number, date, amount) Is loan_payment redundant? account (acc-number, balance) checking (acc-number, overdraft) savings (acc-number, interest) depositor (cust-id, acc-number , access-date)

Relational Model Structure of relational databases a relation is a set of n-tuples (a1, a2, …, an) where each ai  Di R = (A1, …, An ) is a relation schema, where A1,…, An are attributes Fundamental relational-algebra operations select (), project (), union (), set difference (–), Cartesian product (x), rename () Additional relational-algebra operations set intersection (), natural join ( ), division (), assignment () Extended relational-algebra operations generalized projection, aggregate functions, outer join Null values a value does not exist or an unknown value Modification of the database deletion, insertion, update

Cartesian Product vs. Natural Join Relations r, s: A C D A B    10 20 a b   1 2 r s r x s: r s: A B A C D A B C D   1 2    10 20 a b   1 2 10 20 a b

Rename Operation Renaming a relation (or expression)  x (E) returns the expression E under the name X Renaming a relation (or expression) and its attributes If a relational-algebra expression E has arity n, then returns the result of expression E under the name X, and with the attributes renamed to A1 , A2 , …., An .

Aggregate Functions and Operations Aggregation functions: avg, min, max, sum, count take a collection of values and returns a single value as a result Aggregate operation in relational algebra (calligraphic G) G1, G2 …, Gn is a list of attributes on which to group (can be empty) Each Fi is an aggregate function Each Ai is an attribute name use renaming operator or as part of aggregate operation (with as) branch_name g sum(balance) as sum_balance (account)  sum_account(branch_name, sum_balance) (branch_name g sum(balance) (account))

Division Operation Suited to queries that include the phrase “for all” (or “every”). Relations r, s: A B C D E D E    a    a b 1 3 a b 1 s r r  s: A B C   a 

Example (1) Find the accounts held by more than two customers using an aggregate function without using any aggregate functions

Example (2) Find the names of employees who have borrowed all books published by McGraw-Hill. For each publisher, find the names of employees who have borrowed more than five books of that publisher

SQL (1) Data Definition Language (DDL) constructs: create table, drop table, alter table constraints: primary key, unique, not null Basic Query Structure: select … from … where … distinct vs. all rename operation: as tuple variables Set Operations union, intersect, except Aggregate Functions avg, min, max, sum, count group by and having clauses 1

SQL (2) Null Values is null and is not null predicates Nested Subqueries set membership: in, not in set comparison: some, any empty relations: exist, not exist set containment and division: not exist (B except A) to test if B  A absence of duplicates: unique, not unique Complex Queries derived relations with clause 1

SQL (3) Views virtual relations create view, drop view constructs Joined Relations join types: inner join, left/right/full outer join join conditions: natural, on <predicate>, using (A1,…,Ak) Modification of the Database deletion insertion updates case construct 1

Cartesian Product vs. Natural Join Relations r, s: r s A B A C D   1 2    10 20 a b select * from r, s A B A C D select A,B,C,D from r, s where r.a=s.a   1 2    10 20 a b A B C D select * from r natural inner join s   1 2 10 20 a b

Example (1) Find the names of employees who have borrowed all books published by McGraw-Hill.

Example (2) For each publisher, find the names of employees who have borrowed more than five books of that publisher

Advanced SQL (1) SQL Data Types and Schemas Basic: int, char (n), numeric (p,d), float (p), real Advanced: date, time, timestamp, interval, blob, clob User-defined: create type, create domain Integrity Constraints check (P) referential integrity: primary/foreign/unique key assertions Authorization access: read, insert, update, delete modification: resources, drop, alteration, index grant and revoke statements

Advanced SQL (2) Embedded SQL pre-defined statements EXEC SQL statement open, fetch, close operations on cursors Dynamic SQL run-time statements ODBC vs. JDBC APIs connect to database execute SQL statement fetch results prepared statements, metadata features, transactions Advanced SQL Features*

More Examples (1) Find all branches where the total account deposit is less than the average total account deposit at all branches using a nested query in the from clause

More Examples (2) Find all branches where the total account deposit is less than the average total account deposit at all branches using a nested query in the having clause

End