Relational Databases - Amit Bhawnani & Nimesh Shah.

Slides:



Advertisements
Similar presentations
Ver 1,12/09/2012Kode :CCs 111,sistem basisdataFASILKOM Chapter 2: Relational Model Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan.
Advertisements

CS4432: Database Systems II Query Operator & Algebraic Expressions 1.
Relational Algebra – Basis for Relational Query Languages Based on presentation by Juliana Freire.
Chapter 2 Relational Model (part II) Hankz Hankui Zhuo
The Relational Database Model
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Extended.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational.
Database Systems Chapter 6 ITM Relational Algebra The basic set of operations for the relational model is the relational algebra. –enable the specification.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Extended Relational-Algebra-Operations Generalized Projection Outer Join Aggregate Functions.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
SPRING 2004CENG 3521 E-R Diagram for the Banking Enterprise.
MySQL Tutorial (2) Introduction to Database. Banking Example branch (branch-name, branch-city, assets) customer (customer-name, customer-street, customer-city)
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
Midterm 2 Revision Prof. Sin-Min Lee Department of Computer Science San Jose State University.
Relational Algebra. Relational Query Languages n Query = “retrieval program” n Language examples: ù Theoretical : 1. Relational Algebra 2. Relational.
Slides adapted from A. Silberschatz et al. Database System Concepts, 5th Ed. Relational Model Database Management Systems I Alex Coman, Winter 2006.
Relational Model. 2 Structure of Relational Databases Fundamental Relational-Algebra-Operations Additional Relational-Algebra-Operations Extended Relational-Algebra-Operations.
PMIT-6102 Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University.
Relational Algebra Instructor: Mohamed Eltabakh 1.
DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts - 5 th Edition, Oct 5, 2006 Outer Join n An extension of the join operation that avoids loss.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 6 The Relational Algebra.
1 The Relational Model By Elena Ciriani CS157A February 19, 2004 Professor Lee.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
CIS552Relational Model1 Structure of Relational Database Relational Algebra Extended Relational-Algebra-Operations Modification of the Database.
CS 370 Database Systems Lecture 11 Relational Algebra.
3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational Calculus Domain Relational.
Computing & Information Sciences Kansas State University Monday, 08 Sep 2008CIS 560: Database System Concepts Lecture 5 of 42 Monday, 08 September 2008.
Relational Algebra  Souhad M. Daraghma. Relational Query Languages Query languages: Allow manipulation and retrieval of data from a database. Relational.
Relational Model By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany) DIRECTOR ARUNAI ENGINEERING COLLEGE TIRUVANNAMALAI.
Yufis Azhar – Teknik Informatika – UMM.  Aggregation function takes a collection of values (of a single attribute) and returns a single value as a result.
Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Extended.
Chapter 2: Relational Model. 2.2 Chapter 2: Relational Model Structure of Relational Databases Fundamental Relational-Algebra-Operations Additional Relational-Algebra-Operations.
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.
Chapter 6 The Relational Algebra Copyright © 2004 Ramez Elmasri and Shamkant Navathe.
WDM3304 week 6 Table Joins. Primary keys, foreign keys Primary key: A field of a table designated to provide a unique identifier for a specific row of.
Chapter 2: Relational Model. 2.2Unite International CollegeDatabase Management Systems Chapter 2: Relational Model Structure of Relational Databases Fundamental.
Chapter 2: Relational Model II Relational Algebra basics Relational Algebra basics.
Computing & Information Sciences Kansas State University Friday, 26 Jan 2008CIS 560: Database System Concepts Lecture 2 of 42 Friday, 29 August 2008 William.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 6- 1.
2.1 Chapter 2: Relational Model. 2.2 Chapter 2: Relational Model Structure of Relational Databases Fundamental Relational-Algebra-Operations Additional.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Extended.
Advanced Relational Algebra & SQL (Part1 )
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Extended Relational-Algebra-Operations Generalized Projection Aggregate Functions Outer Join.
Database System Concepts, 5 th Ed. Bin Mu at Tongji University Chapter 2: Relational Model.
Computing & Information Sciences Kansas State University Wednesday, 03 Sep 2008CIS 560: Database System Concepts Lecture 3 of 42 Wednesday, 03 September.
ICOM 5016 – Introduction to Database Systems Lecture 6 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,
ASET Relational Algebra continues…. ASET Rename Operation Allows us to name, and therefore to refer to, the results of relational-algebra expressions.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
IS 230Lecture 7Slide 1 Relational Algebra Lecture 8 Text Book – Chapter.
Chapter 3: Relational Model III Additional Relational Algebra Operations Additional Relational Algebra Operations Views Views.
International Computer Institute, Izmir, Turkey Relational Model Asst.Prof.Dr.İlker Kocabaş UBİ502 at
Relational Algebra Instructor: Mohamed Eltabakh 1.
PMIT-6102 Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University.
Query Languages Language in which user requests information from the database. Categories of languages Procedural Non-procedural, or declarative “Pure”
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan Chapter 2: Relational Model.
Module 2: Intro to Relational Model
Relational Model By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany)
Chapter 3: Relational Model III
Chapter 2: Intro to Relational Model
Instructor: Mohamed Eltabakh
Chapter 2: Intro to Relational Model
Chapter 2: Intro to Relational Model
Example of a Relation attributes (or columns) tuples (or rows)
Chapter 2: Intro to Relational Model
Presentation transcript:

Relational Databases - Amit Bhawnani & Nimesh Shah

Topics Relational Model SQL Indexes and execution plans Normalization

Databases vs Flat Files Data independence and efficient access Reduced application development time Data integrity and security Protect data from inconsistency due to multiple concurrent users Security and access control Etc etc

Relational Model Dis-satisfaction with other models such as Network, hierarchical etc Proposed by Edgar. F. Codd in the early seventies Simple and elegant model with a mathematical basis – Set theory and first- order predicate logic.

Relational Model KEY DEFINITIONS

Relation An association between two or more data elements Resembles a “Table” of records. Consider the relation EMPLOYEE represented by the below emp_idnamessndesig_idsalaryjoin_datedept_id 1011ABCa3232x /01/112

Tuples of a Relation Each row here is a tuple Relation is a set of tuples emp_idnamessndesig_idsalaryjoin_datedept_id 1011ABCa3232x /01/112

Cardinality of a RELATION Is the number of tuples in a relation at a point in time Cardinality = 4 emp_idnamessndesig_idsalaryjoin_datedept_id 1011ABCa3232x /01/112

Attributes A tuple consists of attribute values emp_idnamessndesig_idsalaryjoin_datedept_id 1011ABCa3232x /01/112

Arity / Degree Is the number of attributes in a relation Arity / Degree = 6 emp_idnamessndesig_idsalaryjoin_datedept_id 1011ABCa3232x /01/112

Domain Defines the space of possible values for an attribute emp_idnamessndesig_idsalaryjoin_datedept_id 1011ABCa3232x /01/112

Domain - Example Emp_idintegerSet of all 4 digital numbers nameVarhar(50)Set of alpha characters. Max length 50 ssnVarchar(10)Set of alpha numeric characters. Max length 10 desig_idsmallintSet of all designation codes salarydecimalDecimal join_datedate dept_idsmallintSet of all department ids

Relation Schema Consists of name of relation + attributes (along with domain) emp_idnamessndesig_idsalaryjoin_datedept_id 1011ABCa3232x /01/112 Employee

DEFINITION SUMMARY Formal TermsInformal Terms RelationTable Attribute/DomainColumn TupleRow DomainValues in the column Schema of a RelationTable definition

Super Key Uniqueness property: No two tuples share the same value for the key Time-independent emp_idnamessndesig_idsalaryjoin_datedept_id 1011ABCa3232x /01/112 Super Keys: emp_id, name, ssn emp_id_name,ssn_design_d,salary,join_date,dept_id emp_id ssn

Candidate Key Uniqueness property: No two tuples shave the same value for the key Minimality property: None of the attributes of the key can be discarded from the key without destroying the uniqueness property. Time-independent Can be composite emp_idnamessndesig_idsalaryjoin_datedept_id 1011ABCa3232x /01/112

Primary Key One of the candidate keys is chosen to uniquely identify tuples in a relation, such a key is called the primary key. There can be only one primary key per relation Primary key may be a compound key A relation must have a primary key emp_idnamessndesig_idsalaryjoin_datedept_id 1011ABCa3232x /01/112

Alternate Key Any candidate Key which is not a primary key is an alternate key There can be more than one alternate keys for any relation. emp_idnamessndesig_idsalaryjoin_datedept_id 1011ABCa3232x /01/112

Entity Integrity Every Relation must have a primary key No attribute participating in the primary key of a base relation may accept null values Guarantees that each entity will have a unique identity.

Foreign Key Some times a set of attributes in a relation may point to certain tuples in another relation A foreign key is a set of attributes in one relation whose values are required to match one of the values of the primary key of the same or different relation. There can be more than one foreign key in a given relation. emp_idnamessndesig_idsalaryjoin_datedept_id 1011ABCa3232x /01/112 dept_iddept_nameDept_location 2Software Engineering1B Employee Department

Referential Integrity Values of the foreign key – Must be either null or – If non-null, must match with the primary key value of some tuple of the ‘parent’ relation. The reference can be the same relation.

Relational database schema A set S of relation schemas that belong to the same database S is the name of the whole database schema

Schema Diagram for the COMPANY

One possible database state for the COMPANY relational database schema

Relational Algebra The basic set of operations for the relational model is known as the relational algebra. These operations enable a user to specify basic retrieval requests. A set of operators (unary and binary) that take relation instances as arguments and return new relations. Laid the foundation for the development of Database standard SQL SQL queries are internally translated into RA expressions. Provides a framework for query optimization.

Selection SELECT Operation SELECT operation is used to select a subset of the tuples from a relation that satisfy a selection condition. Example: To select the EMPLOYEE tuples whose salary is greater than 30,000 the following notation is used:  SALARY > 30,000 (EMPLOYEE)  (R)

Select Operation – Example Relation r ABCD    A=B & D > 5 (r))  A=B (  D > 5 (r)) ABCD   The degree of the new relation is the same. The cardinality is different. Commutative operator

Projection PROJECT Operation This operation selects certain columns from the table and discards the other columns. Example: To list each employee’s first name,last name and salary, the following is used:  FNAME, LNAME,SALARY (EMPLOYEE) The general form of the project operation is  (R) The project operation removes any duplicate tuples.

Project Operation – Example Relation r: ABC  AC  = AC   A,C (r) Output is another relation with a different schema. Non - Commutative

Union UNION Operation The result of this operation, denoted by R  S, is a relation that includes all tuples that are either in R or in S or in both R and S. Duplicate tuples are eliminated. For r  s to be valid. 1. r, s must have the same same number of attributes 2. The attribute domains must be compatible E.g. to find all customers with either an deposit account or a loan account  customer-name (depositor)   customer-name (borrower)

Union Operation – Example Relations r, s: r  s: AB  AB  2323 r s AB 

Chapter 6-32 Difference (or MINUS) Operation The result of this operation, denoted by R - S, is a relation that includes all tuples that are in R but not in S. The two operands must be "type compatible”. Relations r, s: r  s: AB  AB  2323 r s AB 1

Chapter 6-33 CARTESIAN (or cross product) Operation Relations r, s: r x s: AB  1212 AB  CD  E aabbaabbaabbaabb CD  E aabbaabb r s

Composition of Operations Can build expressions using multiple operations Example:  A=C (r x s) r x s  A,D,E (  A=C (r x s)) AB  CD  E aabbaabbaabbaabb ABCDE   20 aabaab

Banking Example branch (branch-name, branch-city, assets) customer (customer-name, customer-street, customer-only) account (account-number, branch-name, balance) loan (loan-number, branch-name, amount) depositor (customer-name, account-number) borrower (customer-name, loan-number)

Example Queries Find all loans of over $1200 Find the loan number for each loan of an amount greater than $1200 Find the names of all customers who have a loan, an account, or both, from the bank Find the names of all customers who have a loan and an account at bank. Find the names of all customers who have a loan at the ABC branch. Find the names of all customers who have a loan at the ABC branch but do not have an account at any branch of the bank.

Intersection INTERSECTION OPERATION The result of this operation, denoted by R  S, is a relation that includes all tuples that are in both R and S. The two operands must be "type compatible" Relations r, s: r  s: AB  AB  2323 r s AB  2

Theta Join Operator Theta join is used to combine related tuples from two or more relations ( specified by the condition theta ), to form a single tuple. The general form of theta join is as follows : R (join condition) S. Tuples whose join attributes are null do not appear in the final result. Theta join where the only comparison operator used is the equals (=) sign, are called equijoins.

Theta Join Operator – Example Relations r, s: AB  CD  aababaabab B D aaabbaaabb E  r AB  CD  aaaabaaaab E  s r (r.b = s.b and r.d = s.d) s

Outer Join An extension of the join operation that avoids loss of information. Computes the join and then adds tuples form one relation that does not match tuples in the other relation to the result of the join.

Outer Join – Example loan loan-numberamount L-170 L-230 L borrower customer-nameloan-number Jones Smith Hayes L-170 L-230 L-155 branch-name Downtown Redwood Perryridge

Outer Join – Example Inner Join loan (loan.loan_number = borrower.loan_number) Borrower loan (loan.loan_number = borrower.loan_number) borrower Left Outer Join loan-numberamount L-170 L customer-name Jones Smith branch-name Downtown Redwood loan-numberamount L-170 L-230 L customer-name Jones Smith null branch-name Downtown Redwood Perryridge

Outer Join – Example Right Outer Join loan borrower loan-numberamount L-170 L-230 L null customer-name Jones Smith Hayes loan-numberamount L-170 L-230 L-260 L null customer-name Jones Smith null Hayes loan borrower Full Outer Join branch-name Downtown Redwood null branch-name Downtown Redwood Perryridge null

Questions ?