Relational Database Design UNIT II 1. 2 Advantages of Using Database Systems Centralized control of a firm’s data Redundancy can be reduced (avoid keeping.

Slides:



Advertisements
Similar presentations
The Relational Model Much of the material presented in these slides was developed by Dr. Ramon Lawrence at the University of Iowa.
Advertisements

Chapter 3 : Relational Model
©Silberschatz, Korth and Sudarshan6.1Database System Concepts Chapter 6: Integrity (and Security) Domain Constraints Referential Integrity Assertions Triggers.
Chapter 3 The Relational Model Transparencies © Pearson Education Limited 1995, 2005.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Basic (Flat) Relational Model.
Systems Development Life Cycle
© 2005 by Prentice Hall 1 Chapter 5: Logical Database Design and the Relational Model Modern Database Management 7 th Edition Jeffrey A. Hoffer, Mary B.
Chapter 3. 2 Chapter 3 - Objectives Terminology of relational model. Terminology of relational model. How tables are used to represent data. How tables.
1 © Prentice Hall, 2002 Chapter 5: Logical Database Design and the Relational Model Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B.
1 Minggu 2, Pertemuan 3 The Relational Model Matakuliah: T0206-Sistem Basisdata Tahun: 2005 Versi: 1.0/0.0.
The Relational Model 1 Prof. Sin-Min Lee Department of Mathematics and Computer Science Prof. Sin-Min Lee Department of Computer Science.
1 Pertemuan 04 MODEL RELASIONAL Matakuliah: >/ > Tahun: > Versi: >
Relational Database Management System A type of database in which records are stored in relational form is called relational database management system.
Michael F. Price College of Business Chapter 6: Logical database design and the relational model.
Database Architecture The Relational Database Model.
Chapter 6: Integrity Objective Key Constraints (Chapter 2) Cardinality Constraints (Chapter 2) Domain Constraints Referential Integrity Assertions Triggers.
CSC271 Database Systems Lecture # 6. Summary: Previous Lecture  Relational model terminology  Mathematical relations  Database relations  Properties.
Chapter 6: Integrity and Security Thomas Nikl 19 October, 2004 CS157B.
©Silberschatz, Korth and Sudarshan6.1Database System Concepts Chapter 6: Integrity and Security Domain Constraints Referential Integrity Assertions Triggers.
Lecture 2 The Relational Model. Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical relations.
Chapter 4 The Relational Model Pearson Education © 2014.
Module Title? DBMS E-R Model to Relational Model.
Relational Model Session 6 Course Name: Database System Year : 2012.
Chapter 4 The Relational Model.
Chapter 3 The Relational Model Transparencies Last Updated: Pebruari 2011 By M. Arief
Acc 409 Database Concepts.
Content Resource- Elamsari and Navathe, Fundamentals of Database Management systems.
Database Management System Lecture 6 The Relational Database Model – Keys, Integrity Rules.
RAJIKA TANDON DATABASES CSE 781 – Database Management Systems Instructor: Dr. A. Goel.
Database Management COP4540, SCS, FIU Relational Model Chapter 7.
Chapter 3 The Relational Model. 2 Chapter 3 - Objectives u Terminology of relational model. u How tables are used to represent data. u Connection between.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
1 The Relational Database Model. 2 Learning Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical.
9/7/2012ISC329 Isabelle Bichindaritz1 The Relational Database Model.
1.1 CAS CS 460/660 Relational Model. 1.2 Review E/R Model: Entities, relationships, attributes Cardinalities: 1:1, 1:n, m:1, m:n Keys: superkeys, candidate.
The Relational Model Pertemuan 03 Matakuliah: M0564 /Pengantar Sistem Basis Data Tahun : 2008.
Relational Database. Database Management System (DBMS)
1 © Prentice Hall, 2002 Chapter 5: Logical Database Design and the Relational Model Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B.
The University of Akron Dept of Business Technology Computer Information Systems The Relational Model: Concepts 2440: 180 Database Concepts Instructor:
CSE314 Database Systems Lecture 3 The Relational Data Model and Relational Database Constraints Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
The relational model A data model (in general) : Integrated collection of concepts for describing data (data requirements). Relational model was introduced.
1 ER Modeling BUAD/American University Mapping ER modeling to Relationships.
The Relational Model. 2 Relational Model Terminology u A relation is a table with columns and rows. –Only applies to logical structure of the database,
Logical Database Design and the Relational Model.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 5 (Part a): Logical Database Design and the Relational Model Modern Database Management.
CHAPTER 2 : RELATIONAL DATA MODEL Prepared by : nbs.
The Relational Model © Pearson Education Limited 1995, 2005 Bayu Adhi Tama, M.T.I.
Chapter 4, Part A: Logical Database Design and the Relational Model
Lecture 4: Logical Database Design and the Relational Model 1.
Chapter 3 The Relational Model. Objectives u Terminology of relational model. u How tables are used to represent data. u Connection between mathematical.
Chapter 4 The Relational Model Pearson Education © 2009.
1 The Relational Data Model David J. Stucki. Relational Model Concepts 2 Fundamental concept: the relation  The Relational Model represents an entire.
©Silberschatz, Korth and Sudarshan6.1Database System Concepts Chapter 6: Integrity Constraints Domain Constraints Referential Integrity Assertions Triggers.
Chapter 71 The Relational Data Model, Relational Constraints & The Relational Algebra.
Database Constraints Ashima Wadhwa. Database Constraints Database constraints are restrictions on the contents of the database or on database operations.
Logical Database Design and the Rational Model
Database Constraints Ashima Wadhwa.
Chapter 6: Integrity (and Security)
Chapter 4 Logical Database Design and the Relational Model
Chapter 4: Logical Database Design and the Relational Model
Chapter 5: Logical Database Design and the Relational Model
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
CHAPTER 4: LOGICAL DATABASE DESIGN AND THE RELATIONAL MODEL
The Relational Model Transparencies
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
INSTRUCTOR: MRS T.G. ZHOU
Presentation transcript:

Relational Database Design UNIT II 1

2 Advantages of Using Database Systems Centralized control of a firm’s data Redundancy can be reduced (avoid keeping copies of the same data in many places) Inconsistency can be avoided to some extent (updating occurs at one place instead of many places)

3 The data can be shared Security restrictions can be applied (passwords) Integrity of data can be maintained (e.g., an instructor has to exist before being assigned to teach a class) Advantages of Using Database Systems (cont’d)

Relational Data Model 4

5Relation Definition: A relation is a named, two-dimensional table of dataDefinition: A relation is a named, two-dimensional table of data Table consists of rows (records) and columns (attribute or field)Table consists of rows (records) and columns (attribute or field) Requirements for a table to qualify as a relation:Requirements for a table to qualify as a relation: –It must have a unique name –Every attribute value must be atomic (not multivalued, not composite) –Every row must be unique (can’t have two rows with exactly the same values for all their fields) –Attributes (columns) in tables must have unique names –The order of the columns must be irrelevant –The order of the rows must be irrelevant

6 The table representation of an entity set An entity set is usually represented as a table in the database. The name of the table is the same name as the entity set. For example: SSNName Street City Brown2404 MaileHonolulu Yang809 Dole St.Honolulu Gregson211 Main St.Chicago Customer

7 The table representation of an entity set In the table, columns are called attributes, rows are called tuples, observations, or records. Each row is an entity, and the table is an entity set. Customer SSNName Street City Brown2404 MaileHonolulu Yang809 Dole St.Honolulu Gregson211 Main St.Chicago

8Relation Definition: A relation is a named, two-dimensional table of dataDefinition: A relation is a named, two-dimensional table of data Table consists of rows (records) and columns (attribute or field)Table consists of rows (records) and columns (attribute or field) Requirements for a table to qualify as a relation:Requirements for a table to qualify as a relation: –It must have a unique name –Every attribute value must be atomic (not multivalued, not composite) –Every row must be unique (can’t have two rows with exactly the same values for all their fields) –Attributes (columns) in tables must have unique names –The order of the columns must be irrelevant –The order of the rows must be irrelevant

9 Keys It is important that any entity in an entity set be uniquely identifiable. Practically, we use the values of certain attributes to uniquely identify an entity. Keys can be simple (a single field) or composite (more than one field)

10 Customer-name Customer-street customer SSN Customer-city In this particular case, the value of the combination of any attribute(s) with SSN can uniquely identify a particular customer.

11 Keys Meanwhile, it is also obvious that some of these combinations may have redundant attributes. Therefore, in theory, we systematically classify these combinations of attributes using three types of Keys: superkey, candidate key, and primary key.

12 Keys (1) Superkey: is a set of attributes whose value can uniquely identify an entity in the entity set. A superkey contains one or more attributes. Example: The combination of “SSN” and “Name” is a superkey of the following entity set customer.

13 Because: The value of attributes “SSN” and “Name”, such as and Susan, can uniquely identify that particular customer in customer entity set, which is the pool of all customers. Customer-name Customer-street customer SSN Customer-city

14 Notationally, we write, Superkey: (SSN, name) Other superkeys for the entity set customer: Superkey: (SSN) Superkey: (SSN, Street) Superkey: (SSN, City) Superkey: (SSN, Name, Street) Superkey: (SSN, Name, City) Superkey: (SSN, Street, City) Superkey: (SSN, Name, Street, City)

15 Superkey is the broadest definition of unique identifiers of an entity in an entity set. We are unsurprisingly very interested in the most economical combination(s) of attributes that can uniquely identify any particular entity. Therefore, we introduce Candidate Key next.

16 (2) Candidate key: is a set of one or more attributes whose value can uniquely identify an entity in the entity set, and any attribute in the candidate key cannot be omitted without destroying the uniqueness property of the candidate key. (It is minimal superkey). Example: (SSN, Name) is NOT a candidate key, because taking out “name” still leaves “SSN” which can uniquely identify an entity. “SSN” is a candidate key of customer. Candidate key could have more than one attributes.

17 Also, while most entity sets have only one candidate key, some entity sets could have more than one candidate key. Example: Both “SSN” and “License #” are candidate keys of Driver entity set. In building a database in a database software, the software will only allow to use one candidate key to be the unique identifier of an entity for an entity set.

18 (3) Primary Key: is the candidate key that is chosen by the database designer as the unique identifier of an entity. The database designer chooses only one candidate key as the primary key in building the system. Example: “SSN” and “License #” are both candidate keys of Driver entity set. The database designer can choose either one as the primary key.

Foreign Key ·A foreign key is an attribute or attribute combination of one relation R2 whose values are required to match those of the primary key of relation R1 where R1 and R2 are not necessarily distinct. Note that a foreign key and the corresponding primary key should be defined on the same domain(s). Emp# e1 e2 e3 ename red blue brown Dept d1 d2 d3 Worksfordept d1 d2 Dname Pay Tax Art Employee Dept Foreign key

20 Primary Key Foreign Key (implements 1:N relationship between customer and order) Combined, these are a composite primary key (uniquely identifies the order line)…individually they are foreign keys (implement M:N relationship between order and product) Figure 5-3 Schema for four relations (Pine Valley Furniture Company)

Domain For each attribute, a set of permitted values, is called a the domain 21

Relational Data Structure EMPLOYEE Emp# Name Emp Sex Mgr Emp# E1 JonesMaleE65 E6 SmithMaleE28 E28Jones Female- Relation Attribute Heading Body Female Male Gender Domain

The Domain Emp# E1 E2 E3 Name Red Brown Black Mgr# - E1 E1, E2, E3,E4 Red, Brown Black, Blue Attributes Domains Employee Person Name Emp#

25 Overall, superkey is the broadest unique identifier; candidate key is a subset of superkey; and primary key is a subset of candidate key. In practice, we would first look for superkeys. Then we look for candidate keys based on experience and common sense. If there is only one candidate key, it naturally will be designated as the primary key. If we find more than one candidate key, then we can designate any one of them as primary key.

Integrity Constraints It ensures that changes made to the database by authorized users do not result in a loss of data consistency. It guards against accidental damage to the database 26

Domain Constraints They define valid values for attributes They are the most elementary form of integrity constraint. They test values inserted in the database, and test queries to ensure that the comparisons make sense.

28 Integrity Constraints –NOT NULL: specification prohibits the insertion of a null value for the attribute. Any data base modification that would cause a null to be inserted in an attribute declared to be not null generates an error diagnostic –E.g. balance numeric(12,2) not null

29 Integrity Constraints –Unique Constraints: specification says that attributes A1,A2… Aj, form a candidate key; –no two tuples in the relation can be equal on all the primary key attributes.

30 Integrity Constraints –The Check Clause:ensures that attribute values satisfy specified conditions. –E.g. –Create table student (name char(15) not null, Stud_id char(10), Degree_level char(15), Primary key(stud_id),check (degree_level in(‘Bachelors’, ‘Masters’))) The check clause ensures that the degree_level must be one of ‘Bachelors’ or’Masters’

Referential Integrity Ensures that a value that appears in one relation for a given set of attributes also appears for a certain set of attribute in another relation. –If an account exists in the database with branch name “Perryridge”, then the branch “Perryridge” must actually exist in the database. Primary keys of respective relations Foreign key branch (branch-name, branch-city, asset ) Perryridge Brooklyn 500,000 account ( account-no, branch-name, balance ) A-123 Perryridge 5000 A set of attributes X in R is a foreign key if it is not a primary key of R but it is a primary key of some relation S.

Assertions An assertion is a predicate expressing a condition that we wish the database to always satisfy. Domain constraints and referential integrity constraints are special forms of assertions. But there are many constraints we cannot express by using only these special forms. EX1: Every loan has atleast one customer who maintains an account with a minimum balance of Rs

Creating an Assertion When an assertion is created, the system will test it for validity. If the assertion is valid, then any future modification to the database is allowed only if it does not cause the assertion to be violated. But assertions can create a considerable amount of overhead, especially if complex assertions have been made.